diff --git a/README.md b/README.md index fd96346..4fa773a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# Fabric Example Mod +# Jump Vader - A Fabric Server-Side Elevator Mod -## Setup +## What is it +I'ts a mod that lets you place "Jump Vader" blocks similar to the Quark mod's elevators. +You simply place one above the other at any vertical distance, and jump/crouch on top of the +block to go in between the different heights. -For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using. - -## License - -This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. +## Crafting +![Crafting Recipe](https://raw.githubusercontent.com/VenomCodeDev/JumpVaderMod/1.19/assets/JumpVaderCraftingRecipe.png) \ No newline at end of file diff --git a/assets/JumpVaderCraftingRecipe.png b/assets/JumpVaderCraftingRecipe.png new file mode 100644 index 0000000..9944fd7 Binary files /dev/null and b/assets/JumpVaderCraftingRecipe.png differ diff --git a/build.gradle b/build.gradle index 6d30805..d9e4bae 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id 'fabric-loom' version '1.0-SNAPSHOT' id 'maven-publish' + id 'com.github.johnrengelman.shadow' version '7.0.0' } sourceCompatibility = JavaVersion.VERSION_17 @@ -16,6 +17,9 @@ repositories { // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. + + mavenCentral() + maven { url 'https://maven.nucleoid.xyz' } } dependencies { @@ -27,10 +31,15 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - // Uncomment the following line to enable the deprecated Fabric API modules. + // Uncomment the following line to enable the deprecated Fabric API modules. // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. - // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" + modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" + + shadow(implementation('org.spongepowered:configurate-hocon:4.1.2')) + + modImplementation include("eu.pb4:polymer:${project.polymer_version}") + modImplementation include("fr.catcore:server-translations-api:${project.server_translation_api_version}") } processResources { @@ -57,6 +66,18 @@ jar { from("LICENSE") { rename { "${it}_${project.archivesBaseName}"} } + archiveClassifier.set("dev") +} + +shadowJar { + configurations = [project.configurations.shadow] + archiveClassifier.set("dev") + relocate "net.objecthunter", "de.siphalor.spiceoffabric.shadow.net.objecthunter" +} + +remapJar { + dependsOn(shadowJar) + inputFile = tasks.shadowJar.archiveFile } // configure the maven publication diff --git a/gradle.properties b/gradle.properties index 93161f4..9a4793d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,15 +2,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties - # check these on https://fabricmc.net/develop - minecraft_version=1.19.2 - yarn_mappings=1.19.2+build.8 - loader_version=0.14.9 +# check these on https://fabricmc.net/develop +minecraft_version=1.19.2 +yarn_mappings=1.19.2+build.20 +loader_version=0.14.9 # Mod Properties - mod_version = 1.0.0 - maven_group = com.example - archives_base_name = fabric-example-mod +mod_version = 1.0.0 +maven_group = dev.venomcode +archives_base_name = jump-vader # Dependencies - fabric_version=0.60.0+1.19.2 +fabric_version=0.62.0+1.19.2 +polymer_version=0.2.16+1.19.2 +server_translation_api_version=1.4.17+1.19.2 diff --git a/src/main/java/dev/venomcode/jumpvader/JumpVaderConfig.java b/src/main/java/dev/venomcode/jumpvader/JumpVaderConfig.java new file mode 100644 index 0000000..7cc7682 --- /dev/null +++ b/src/main/java/dev/venomcode/jumpvader/JumpVaderConfig.java @@ -0,0 +1,82 @@ +package dev.venomcode.jumpvader; + +import org.spongepowered.configurate.CommentedConfigurationNode; +import org.spongepowered.configurate.ConfigurateException; +import org.spongepowered.configurate.hocon.HoconConfigurationLoader; +import org.spongepowered.configurate.serialize.SerializationException; + +import java.io.IOException; +import java.nio.file.Path; + +public class JumpVaderConfig +{ + + public boolean getEnabled() + { + return rootNode.node(ENABLED_TAG).getBoolean(true); + } + + public int getMaxVerticalBlocks() + { + return rootNode.node(MAX_VERTICAL_BLOCKS_TAG).getInt(128); + } + + public void setupConfig() throws SerializationException + { + + rootNode.node(ENABLED_TAG).comment(ENABLED_TAG_COMMENT).set(getEnabled()); + rootNode.node(MAX_VERTICAL_BLOCKS_TAG).comment(MAX_VERTICAL_BLOCKS_TAG_COMMENT).set(getMaxVerticalBlocks()); + + save(); + } + + // NODE LOCATION TAGS & COMMENTS + private static final String ENABLED_TAG = "enabled"; + private static final String ENABLED_TAG_COMMENT = "Toggles this entire mod on and off."; + private static final String MAX_VERTICAL_BLOCKS_TAG = "max_blocks_vertical"; + private static final String MAX_VERTICAL_BLOCKS_TAG_COMMENT = "The maximum amount of vertical blocks to travel when using the jump vader block."; + + + public JumpVaderConfig() + { + loader = HoconConfigurationLoader.builder() + .path(Path.of("./config/" + JumpVaderMod.MODID + ".conf")) + .build(); + try + { + rootNode = loader.load(); + setupConfig(); + } + catch (IOException ex) + { + JumpVaderMod.LOGGER.info("Error occurred loading config:" + ex.getMessage()); + if(ex.getCause() != null) + { + ex.getCause().printStackTrace(); + } + rootNode = null; + } + } + + private boolean save() + { + try + { + loader.save(rootNode); + return true; + } + catch (final ConfigurateException ex) + { + JumpVaderMod.LOGGER.info("Unable to save config for '" + JumpVaderMod.MODID + "'! Error: " + ex.getMessage()); + } + return false; + } + + private CommentedConfigurationNode getRootNode() + { + return rootNode; + } + + private final HoconConfigurationLoader loader; + private CommentedConfigurationNode rootNode; +} diff --git a/src/main/java/dev/venomcode/jumpvader/JumpVaderMod.java b/src/main/java/dev/venomcode/jumpvader/JumpVaderMod.java new file mode 100644 index 0000000..53dab65 --- /dev/null +++ b/src/main/java/dev/venomcode/jumpvader/JumpVaderMod.java @@ -0,0 +1,38 @@ +package dev.venomcode.jumpvader; + +import dev.venomcode.jumpvader.blocks.JumpVaderBlock; +import eu.pb4.polymer.api.item.PolymerBlockItem; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.item.v1.FabricItemSettings; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.Blocks; +import net.minecraft.block.Material; +import net.minecraft.item.Items; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JumpVaderMod implements ModInitializer { + // This logger is used to write text to the console and the log file. + // It is considered best practice to use your mod id as the logger's name. + // That way, it's clear which mod wrote info, warnings, and errors. + public static final String MODID = "jumpvader"; + public static final Logger LOGGER = LoggerFactory.getLogger(MODID); + private static JumpVaderConfig config; + + @Override + public void onInitialize() + { + config = new JumpVaderConfig(); + + Registry.register( Registry.BLOCK, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), JUMP_VADER_BLOCK); + + Registry.register( Registry.ITEM, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), new PolymerBlockItem( JUMP_VADER_BLOCK, new FabricItemSettings(), Items.ORANGE_STAINED_GLASS ) ); + } + public static JumpVaderConfig getConfig() + { + return config; + } + public static final JumpVaderBlock JUMP_VADER_BLOCK = new JumpVaderBlock(FabricBlockSettings.of(Material.GLASS), Blocks.ORANGE_STAINED_GLASS); +} diff --git a/src/main/java/dev/venomcode/jumpvader/blocks/JumpVaderBlock.java b/src/main/java/dev/venomcode/jumpvader/blocks/JumpVaderBlock.java new file mode 100644 index 0000000..2b1c3a9 --- /dev/null +++ b/src/main/java/dev/venomcode/jumpvader/blocks/JumpVaderBlock.java @@ -0,0 +1,96 @@ +package dev.venomcode.jumpvader.blocks; + +import dev.venomcode.jumpvader.JumpVaderMod; +import dev.venomcode.jumpvader.ifaces.IJumpVaderListener; +import eu.pb4.polymer.api.block.SimplePolymerBlock; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.Material; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; + +public class JumpVaderBlock extends SimplePolymerBlock implements IJumpVaderListener +{ + + public JumpVaderBlock(Settings settings, Block virtualBlock) + { + super(settings, virtualBlock); + } + + @Override + public boolean onJump(BlockPos pos , ServerPlayerEntity player ) + { + pos = pos.up(); + ServerWorld w = player.getWorld(); + int count = 0; + + while(count < JumpVaderMod.getConfig().getMaxVerticalBlocks() && pos.getY() < 318) + { + Block blk = w.getBlockState( pos ).getBlock(); + + if(blk instanceof JumpVaderBlock) + { + final BlockPos tpPos = pos.up(); + + if(w.getBlockState( tpPos ).getBlock().equals( Blocks.AIR ) && w.getBlockState( tpPos.up() ).getBlock().equals( Blocks.AIR )) + { + player.networkHandler.requestTeleport( tpPos.getX() + 0.5f, tpPos.getY(), tpPos.getZ() + 0.5f, player.getHeadYaw(), 0f ); + + w.playSound( null, tpPos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 0.5f, 1.5f ); + w.spawnParticles( ParticleTypes.END_ROD, tpPos.getX() + 0.5f, tpPos.getY(), tpPos.getZ() + 0.5f, 10, 0, 0, 0, 0.25f ); + + return true; + } + } + pos = pos.up(); + count++; + } + return false; + } + + @Override + public void onCrouch( BlockPos pos , ServerPlayerEntity player ) + { + pos = pos.down(); + ServerWorld w = player.getWorld(); + int count = 0; + + while(count < JumpVaderMod.getConfig().getMaxVerticalBlocks() && pos.getY() >= -64) + { + Block blk = w.getBlockState( pos ).getBlock(); + + if(blk instanceof JumpVaderBlock) + { + final BlockPos tpPos = pos.up(); + + if(w.getBlockState( tpPos ).getBlock().equals( Blocks.AIR ) && w.getBlockState( tpPos.up() ).getBlock().equals( Blocks.AIR )) + { + player.networkHandler.requestTeleport( tpPos.getX() + 0.5f, tpPos.getY(), tpPos.getZ() + 0.5f, player.getHeadYaw(), 0f ); + + w.playSound( null, tpPos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 0.5f, 1.5f ); + w.spawnParticles( ParticleTypes.END_ROD, tpPos.getX() + 0.5f, tpPos.getY(), tpPos.getZ() + 0.5f, 10, 0, 0, 0, 0.25f ); + + return; + } + } + pos = pos.down(); + count++; + } + + } + + @Override + public Block getPolymerBlock(BlockState state) + { + return Blocks.ORANGE_STAINED_GLASS; + } + + private static final Identifier _identifier = new Identifier( JumpVaderMod.MODID, "jumpvader_block" ); +} \ No newline at end of file diff --git a/src/main/java/dev/venomcode/jumpvader/ifaces/IJumpVaderListener.java b/src/main/java/dev/venomcode/jumpvader/ifaces/IJumpVaderListener.java new file mode 100644 index 0000000..439fa01 --- /dev/null +++ b/src/main/java/dev/venomcode/jumpvader/ifaces/IJumpVaderListener.java @@ -0,0 +1,10 @@ +package dev.venomcode.jumpvader.ifaces; + +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.BlockPos; + +public interface IJumpVaderListener +{ + boolean onJump(BlockPos pos, ServerPlayerEntity player ); + void onCrouch( BlockPos pos, ServerPlayerEntity player ); +} diff --git a/src/main/java/dev/venomcode/jumpvader/mixin/ServerPlayerMixin.java b/src/main/java/dev/venomcode/jumpvader/mixin/ServerPlayerMixin.java new file mode 100644 index 0000000..760c5c7 --- /dev/null +++ b/src/main/java/dev/venomcode/jumpvader/mixin/ServerPlayerMixin.java @@ -0,0 +1,53 @@ +package dev.venomcode.jumpvader.mixin; + +import com.mojang.authlib.GameProfile; +import dev.venomcode.jumpvader.ifaces.IJumpVaderListener; +import net.minecraft.block.Block; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.encryption.PlayerPublicKey; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin( ServerPlayerEntity.class ) +public abstract class ServerPlayerMixin extends PlayerEntity +{ + @Override + public void jump( ) + { + BlockPos p = this.getBlockPos().down(); + Block blk = this.world.getBlockState( p ).getBlock(); + + if(blk instanceof IJumpVaderListener bActioner) + { + if(bActioner.onJump( p, (ServerPlayerEntity ) (Object)this )) + { + return; + } + } + + super.jump( ); + } + + @Override + public void setSneaking( boolean sneaking ) + { + super.setSneaking( sneaking ); + if(sneaking) + { + BlockPos p = this.getBlockPos().down(); + Block blk = this.world.getBlockState( p ).getBlock(); + + if(blk instanceof IJumpVaderListener bActioner) + { + bActioner.onCrouch( p, (ServerPlayerEntity ) (Object)this ); + } + } + } + + public ServerPlayerMixin(World world , BlockPos pos , float yaw , GameProfile profile, PlayerPublicKey pubKey) + { + super(world, pos, yaw, profile, pubKey); + } +} diff --git a/src/main/java/net/fabricmc/example/ExampleMod.java b/src/main/java/net/fabricmc/example/ExampleMod.java deleted file mode 100644 index a964189..0000000 --- a/src/main/java/net/fabricmc/example/ExampleMod.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.fabricmc.example; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExampleMod implements ModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - public static final Logger LOGGER = LoggerFactory.getLogger("modid"); - - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - LOGGER.info("Hello Fabric world!"); - } -} diff --git a/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java b/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java deleted file mode 100644 index 356cb38..0000000 --- a/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.fabricmc.example.mixin; - -import net.fabricmc.example.ExampleMod; -import net.minecraft.client.gui.screen.TitleScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(TitleScreen.class) -public class ExampleMixin { - @Inject(at = @At("HEAD"), method = "init()V") - private void init(CallbackInfo info) { - ExampleMod.LOGGER.info("This line is printed by an example mod mixin!"); - } -} diff --git a/src/main/resources/assets/modid/icon.png b/src/main/resources/assets/jumpvader/icon.png similarity index 100% rename from src/main/resources/assets/modid/icon.png rename to src/main/resources/assets/jumpvader/icon.png diff --git a/src/main/resources/data/jumpvader/lang/en_us.json b/src/main/resources/data/jumpvader/lang/en_us.json new file mode 100644 index 0000000..1cbbde4 --- /dev/null +++ b/src/main/resources/data/jumpvader/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "block.jumpvader.jumpvader_block": "Jump Vader" +} \ No newline at end of file diff --git a/src/main/resources/data/jumpvader/loot_tables/blocks/jumpvader_block.json b/src/main/resources/data/jumpvader/loot_tables/blocks/jumpvader_block.json new file mode 100644 index 0000000..5b8a626 --- /dev/null +++ b/src/main/resources/data/jumpvader/loot_tables/blocks/jumpvader_block.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "jumpvader:jumpvader_block" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/jumpvader/recipes/jump_vader.json b/src/main/resources/data/jumpvader/recipes/jump_vader.json new file mode 100644 index 0000000..f245849 --- /dev/null +++ b/src/main/resources/data/jumpvader/recipes/jump_vader.json @@ -0,0 +1,23 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "#A#", + "AEA", + "#A#" + ], + "key": { + "#": { + "item": "minecraft:glass" + }, + "A": { + "item": "minecraft:amethyst_shard" + }, + "E": { + "item": "minecraft:ender_pearl" + } + }, + "result": { + "item": "jumpvader:jumpvader_block", + "count": 2 + } +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3428658..21a5fce 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,29 +1,29 @@ { "schemaVersion": 1, - "id": "modid", + "id": "jumpvader", "version": "${version}", - "name": "Example Mod", - "description": "This is an example description! Tell everyone what your mod is about!", + "name": "Jump Vader", + "description": "Ender Vaders ServerSide Only", "authors": [ - "Me!" + "VenomCodeDev" ], "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" + "homepage": "https://github.com/VenomCodeDev/JumpVaderMod", + "sources": "https://github.com/VenomCodeDev/JumpVaderMod" }, "license": "CC0-1.0", - "icon": "assets/modid/icon.png", + "icon": "assets/jumpvader/icon.png", "environment": "*", "entrypoints": { "main": [ - "net.fabricmc.example.ExampleMod" + "dev.venomcode.jumpvader.JumpVaderMod" ] }, "mixins": [ - "modid.mixins.json" + "jumpvader.mixins.json" ], "depends": { diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/jumpvader.mixins.json similarity index 70% rename from src/main/resources/modid.mixins.json rename to src/main/resources/jumpvader.mixins.json index 7c42cb4..5d70c49 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/jumpvader.mixins.json @@ -1,12 +1,12 @@ { "required": true, "minVersion": "0.8", - "package": "net.fabricmc.example.mixin", + "package": "dev.venomcode.jumpvader.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "ServerPlayerMixin" ], "client": [ - "ExampleMixin" ], "injectors": { "defaultRequire": 1