diff --git a/build.gradle b/build.gradle index db607fa..0226a71 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { id 'fabric-loom' version '1.2-SNAPSHOT' id 'maven-publish' - id 'com.github.johnrengelman.shadow' version '7.0.0' } version = project.mod_version @@ -20,7 +19,7 @@ repositories { maven { url 'https://maven.nucleoid.xyz' } maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } - maven { url 'https://jitpack.io' } + maven { url "https://api.modrinth.com/maven" } } dependencies { @@ -35,12 +34,14 @@ dependencies { // 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}" + + + include(modImplementation("maven.modrinth:server-api:${project.serverapi_version}")) + + include(modImplementation('me.lucko:fabric-permissions-api:0.2-SNAPSHOT')) include(modImplementation("eu.pb4:polymer-core:${project.polymer_version}")) include(modImplementation("xyz.nucleoid:server-translations-api:${project.server_translations_api_version}")) - - shadow(implementation('org.spongepowered:configurate-hocon:4.1.2')) } processResources { @@ -70,15 +71,6 @@ jar { rename { "${it}_${project.archivesBaseName}"} } } -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 publishing { diff --git a/gradle.properties b/gradle.properties index ef0f1a0..b2e154b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,11 +9,12 @@ yarn_mappings=1.20.1+build.2 loader_version=0.14.21 # Mod Properties -mod_version = 1.0.2+1.20.1 -maven_group = dev.venomcode +mod_version = 1.0.3+1.20.1 +maven_group = dev.venomcode.jumpvader archives_base_name = jumpvader # Dependencies fabric_version=0.83.1+1.20.1 +serverapi_version=1.0.6a+1.20.1 polymer_version=0.5.2+1.20.1 server_translations_api_version=2.0.0+1.20 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..249e583 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..59bc51a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..a69d9cb 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..53a6b23 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/dev/venomcode/jumpvader/JumpVaderConfig.java b/src/main/java/dev/venomcode/jumpvader/JumpVaderConfig.java index 5fe7fc0..09e9db8 100644 --- a/src/main/java/dev/venomcode/jumpvader/JumpVaderConfig.java +++ b/src/main/java/dev/venomcode/jumpvader/JumpVaderConfig.java @@ -3,86 +3,41 @@ package dev.venomcode.jumpvader; import org.spongepowered.configurate.CommentedConfigurationNode; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.hocon.HoconConfigurationLoader; +import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Comment; +import org.spongepowered.configurate.objectmapping.meta.Setting; import org.spongepowered.configurate.serialize.SerializationException; import java.io.IOException; import java.nio.file.Path; +@ConfigSerializable public class JumpVaderConfig { public boolean getEnabled() { - return rootNode.node(ENABLED_TAG).getBoolean(true); + return enabled; } public int getMaxVerticalBlocks() { - return rootNode.node(MAX_VERTICAL_BLOCKS_TAG).getInt(128); + return maxVerticleBlocks; } public String getAlternativeBlock() { - return rootNode.node(USE_ALTERNATIVE_BLOCK_TAG).getString("default"); + return placeholderBlockRaw; } - 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()); - rootNode.node(USE_ALTERNATIVE_BLOCK_TAG).comment(USE_ALTERNATIVE_BLOCK_TAG_COMMENT).set(getAlternativeBlock()); + @Setting("mod enabled") + @Comment("Toggles the entire mod on/off. Doesnt delete blocks/items if set to off!") + private boolean enabled = true; - save(); - } + @Setting("max vertical blocks") + @Comment("The maximum amount of blocks a player can move vertically using the jump vader") + private int maxVerticleBlocks = 128; - // 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."; - private static final String USE_ALTERNATIVE_BLOCK_TAG = "use_alternative_block"; - private static final String USE_ALTERNATIVE_BLOCK_TAG_COMMENT = "Block to use for clients. Allowed Values: default, stained_glass, white_wool"; - - - 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; + @Setting("display block") + @Comment("Sets the 'fake' block to display as a placeholder for the jump vader block.") + private String placeholderBlockRaw = "minecraft:orange_wool"; } diff --git a/src/main/java/dev/venomcode/jumpvader/JumpVaderMod.java b/src/main/java/dev/venomcode/jumpvader/JumpVaderMod.java index 892bd1c..14a19b5 100644 --- a/src/main/java/dev/venomcode/jumpvader/JumpVaderMod.java +++ b/src/main/java/dev/venomcode/jumpvader/JumpVaderMod.java @@ -1,17 +1,27 @@ package dev.venomcode.jumpvader; import dev.venomcode.jumpvader.blocks.JumpVaderBlock; +import dev.venomcode.serverapi.api.ServerAPI; +import dev.venomcode.serverapi.api.event.SAPIPlayerEvents; import eu.pb4.polymer.core.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.item.Item; import net.minecraft.item.Items; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.spongepowered.configurate.CommentedConfigurationNode; +import org.spongepowered.configurate.ConfigurateException; +import org.spongepowered.configurate.hocon.HoconConfigurationLoader; + +import java.nio.file.Path; public class JumpVaderMod implements ModInitializer { // This logger is used to write text to the console and the log file. @@ -19,20 +29,76 @@ public class JumpVaderMod implements ModInitializer { // 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(); + JumpVaderConfig config = getConfig(); + saveConfig(); + + Identifier jumpVaderProxyIdent = new Identifier(config.getAlternativeBlock()); + Item jumpVaderProxyItem = Registries.ITEM.get(jumpVaderProxyIdent); + + JUMP_VADER_BLOCK = new JumpVaderBlock(FabricBlockSettings.copyOf(Blocks.BAMBOO_PLANKS), Registries.BLOCK.get(jumpVaderProxyIdent)); Registry.register(Registries.BLOCK, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), JUMP_VADER_BLOCK); - Registry.register( Registries.ITEM, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), new PolymerBlockItem( JUMP_VADER_BLOCK, new FabricItemSettings(), Items.ORANGE_STAINED_GLASS ) ); + Registry.register( Registries.ITEM, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), new PolymerBlockItem( JUMP_VADER_BLOCK, new FabricItemSettings(), jumpVaderProxyItem ) ); + + SAPIPlayerEvents.JUMP.register((player -> { + if(!config.getEnabled()) + return true; + BlockPos testPos = player.getBlockPos().down(); + if(player.getWorld().getBlockState(testPos).getBlock() instanceof JumpVaderBlock jumpVaderBlock) + { + return !jumpVaderBlock.onJump(testPos, player); + } + return true; + })); + + SAPIPlayerEvents.SNEAK.register((player -> { + if(!config.getEnabled()) + return true; + + BlockPos testPos = player.getBlockPos().down(); + if(player.getWorld().getBlockState(testPos).getBlock() instanceof JumpVaderBlock jumpVaderBlock) { + jumpVaderBlock.onCrouch(testPos, player); + } + + return true; + })); } - public static JumpVaderConfig getConfig() - { - return config; + public static JumpVaderBlock JUMP_VADER_BLOCK; + + public static JumpVaderConfig getConfig() { + if(_configCached != null) + return _configCached; + + try { + CommentedConfigurationNode node = configLoader.load(); + + _configCached = node.get(JumpVaderConfig.class); + } + catch (ConfigurateException ex) { + LOGGER.error(ServerAPI.Logger.Error("[ERROR]Failed to load jump_vader config.")); + } + + return _configCached; } - public static final JumpVaderBlock JUMP_VADER_BLOCK = new JumpVaderBlock(FabricBlockSettings.copyOf(Blocks.BAMBOO_PLANKS), Blocks.ORANGE_STAINED_GLASS); + + public static void saveConfig() { + CommentedConfigurationNode node = CommentedConfigurationNode.root(); + try { + node.set(JumpVaderConfig.class, _configCached); + configLoader.save(node); + } + catch (ConfigurateException ex) { + LOGGER.error(ServerAPI.Logger.Error("[ERROR]Failed to save jump_vader config.")); + } + } + + private static final HoconConfigurationLoader configLoader = HoconConfigurationLoader.builder() + .path(Path.of(ServerAPI.CONFIG_PATH + "jump_vader.conf")) + .build(); + private static JumpVaderConfig _configCached = null; } diff --git a/src/main/java/dev/venomcode/jumpvader/blocks/JumpVaderBlock.java b/src/main/java/dev/venomcode/jumpvader/blocks/JumpVaderBlock.java index 5b0d35c..ec7df08 100644 --- a/src/main/java/dev/venomcode/jumpvader/blocks/JumpVaderBlock.java +++ b/src/main/java/dev/venomcode/jumpvader/blocks/JumpVaderBlock.java @@ -90,15 +90,5 @@ public class JumpVaderBlock extends SimplePolymerBlock implements IJumpVaderList } - @Override - public Block getPolymerBlock(BlockState state) - { - return switch (JumpVaderMod.getConfig().getAlternativeBlock()) { - case "tinted_glass" -> Blocks.TINTED_GLASS; - case "white_wool" -> Blocks.WHITE_WOOL; - default -> 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/mixin/ServerPlayerMixin.java b/src/main/java/dev/venomcode/jumpvader/mixin/ServerPlayerMixin.java deleted file mode 100644 index 760c5c7..0000000 --- a/src/main/java/dev/venomcode/jumpvader/mixin/ServerPlayerMixin.java +++ /dev/null @@ -1,53 +0,0 @@ -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/resources/jumpvader.mixins.json b/src/main/resources/jumpvader.mixins.json index 5d70c49..a72547c 100644 --- a/src/main/resources/jumpvader.mixins.json +++ b/src/main/resources/jumpvader.mixins.json @@ -4,7 +4,6 @@ "package": "dev.venomcode.jumpvader.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ServerPlayerMixin" ], "client": [ ],