From 815422d9b9ed6e31aacb5f320118f3578cd7a1af Mon Sep 17 00:00:00 2001 From: AmyMialee <10999535+AmyMialee@users.noreply.github.com> Date: Sun, 5 Oct 2025 04:23:02 +0100 Subject: [PATCH] 1.21.9 partial port mostly needs the recipe stuff to be finished and adding things to an itemgroup, as the lib is currently not updated --- LICENSE => LICENSE.md | 0 build.gradle | 16 +- gradle.properties | 13 +- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 185 ------------- gradlew.bat | 89 ------ src/main/java/safro/oxidized/Oxidized.java | 21 +- .../java/safro/oxidized/OxidizedClient.java | 25 +- .../oxidized/block/CopperButtonBlock.java | 4 +- .../safro/oxidized/block/CopperKilnBlock.java | 36 +-- .../safro/oxidized/block/CopperPanBlock.java | 72 +++-- .../safro/oxidized/block/CopperRailBlock.java | 258 +++++++----------- .../safro/oxidized/block/CopperTrapBlock.java | 68 +++-- .../block/entity/CopperKilnBlockEntity.java | 12 +- .../block/screen/CopperKilnScreen.java | 11 +- .../block/screen/CopperKilnScreenHandler.java | 3 +- .../safro/oxidized/config/OxidizedConfig.java | 22 +- .../oxidized/entity/CopperGolemEntity.java | 167 ------------ .../entity/CopperGolemEntityModel.java | 67 ----- .../entity/CopperGolemEntityRenderer.java | 29 -- .../entity/goal/MoveToLightningRodGoal.java | 26 -- .../oxidized/entity/goal/UseButtonGoal.java | 130 --------- .../safro/oxidized/item/BarometerItem.java | 29 +- .../safro/oxidized/item/CopperPulsarItem.java | 64 ++--- .../safro/oxidized/item/RoseGoldMaterial.java | 42 --- .../mixin/LightningRodBlockMixin.java | 79 ------ .../oxidized/mixin/LivingEntityMixin.java | 14 +- .../mixin/MinecartEntityAccessor.java | 3 +- .../oxidized/mixin/MinecartRailMixin.java | 23 +- .../oxidized/recipe/CopperKilnRecipe.java | 31 ++- .../oxidized/recipe/CopperKilnRecipeBook.java | 21 -- .../oxidized/registry/BlockRegistry.java | 52 ++-- .../oxidized/registry/EntityRegistry.java | 23 -- .../safro/oxidized/registry/ItemRegistry.java | 70 +++-- .../oxidized/rei/KilnSmeltingDisplay.java | 18 +- .../safro/oxidized/rei/OxidizedREIPlugin.java | 9 +- .../safro/oxidized/util/MinecartHandler.java | 12 +- .../safro/oxidized/util/TrapDamageSource.java | 11 - .../resources/assets/oxidized/lang/en_us.json | 2 + .../tags/item/rose_gold_tool_materials.json | 6 + 40 files changed, 402 insertions(+), 1363 deletions(-) rename LICENSE => LICENSE.md (100%) delete mode 100755 gradlew delete mode 100644 gradlew.bat delete mode 100644 src/main/java/safro/oxidized/entity/CopperGolemEntity.java delete mode 100644 src/main/java/safro/oxidized/entity/CopperGolemEntityModel.java delete mode 100644 src/main/java/safro/oxidized/entity/CopperGolemEntityRenderer.java delete mode 100644 src/main/java/safro/oxidized/entity/goal/MoveToLightningRodGoal.java delete mode 100644 src/main/java/safro/oxidized/entity/goal/UseButtonGoal.java delete mode 100644 src/main/java/safro/oxidized/item/RoseGoldMaterial.java delete mode 100644 src/main/java/safro/oxidized/mixin/LightningRodBlockMixin.java delete mode 100644 src/main/java/safro/oxidized/recipe/CopperKilnRecipeBook.java delete mode 100644 src/main/java/safro/oxidized/registry/EntityRegistry.java delete mode 100644 src/main/java/safro/oxidized/util/TrapDamageSource.java create mode 100644 src/main/resources/data/oxidized/tags/item/rose_gold_tool_materials.json diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/build.gradle b/build.gradle index d1b7fce..00d4ba7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.7-SNAPSHOT' + id 'fabric-loom' version '1.11-SNAPSHOT' id 'maven-publish' } @@ -48,7 +48,7 @@ dependencies { } // SafLib - modImplementation include("maven.modrinth:saflib:${project.lib_version}") +// modImplementation include("maven.modrinth:saflib:${project.lib_version}") } processResources { @@ -60,32 +60,26 @@ processResources { } tasks.withType(JavaCompile).configureEach { - it.options.release = 21 } java { sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 - withSourcesJar() } jar { - from("LICENSE") { + from("LICENSE.md") { rename { "${it}_${project.archivesBaseName}"} } } - publishing { publications { mavenJava(MavenPublication) { from components.java } } - - repositories { - - } -} + repositories {} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 2064a20..0f2021f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,13 @@ org.gradle.jvmargs=-Xmx1G -minecraft_version=1.21.1 -yarn_mappings=1.21.1+build.3 -loader_version=0.16.9 +minecraft_version=1.21.9 +yarn_mappings=1.21.9+build.1 +loader_version=0.17.2 -fabric_version=0.107.0+1.21.1 -rei_version=16.0.788 -modmenu_version=11.0.3 -lib_version=1.1.1 +fabric_version=0.134.0+1.21.9 +rei_version=20.0.811 +modmenu_version=16.0.0-rc.1 # Mod Properties mod_version = 1.8.4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0d18421..3ae1e2f 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-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 4f906e0..0000000 --- a/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="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 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/src/main/java/safro/oxidized/Oxidized.java b/src/main/java/safro/oxidized/Oxidized.java index c1812cc..11e8b58 100644 --- a/src/main/java/safro/oxidized/Oxidized.java +++ b/src/main/java/safro/oxidized/Oxidized.java @@ -3,34 +3,29 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; import net.minecraft.registry.RegistryKey; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; import safro.oxidized.config.OxidizedConfig; import safro.oxidized.registry.BlockRegistry; -import safro.oxidized.registry.EntityRegistry; import safro.oxidized.registry.ItemRegistry; -import safro.oxidized.util.TrapDamageSource; -import safro.saflib.SafLib; import java.io.File; -import java.util.ArrayList; public class Oxidized implements ModInitializer { - public static RegistryKey ITEMGROUP = SafLib.createGroup("oxidized"); - public static final Logger LOGGER = LogManager.getLogger("oxidized"); + public static String MOD_ID = "oxidized"; + public static RegistryKey ITEMGROUP = SafLib.createGroup(MOD_ID); public static OxidizedConfig CONFIG; @Override public void onInitialize() { CONFIG = OxidizedConfig.loadConfig(new File(FabricLoader.getInstance().getConfigDir() + "/oxidized_config.json")); - - TrapDamageSource.init(); BlockRegistry.init(); ItemRegistry.init(); - EntityRegistry.init(); - SafLib.registerAll(ITEMGROUP, BlockRegistry.COPPER_KILN); } + + public static @NotNull Identifier id(String path) { + return Identifier.of(MOD_ID, path); + } } diff --git a/src/main/java/safro/oxidized/OxidizedClient.java b/src/main/java/safro/oxidized/OxidizedClient.java index 5ae7587..0182eee 100644 --- a/src/main/java/safro/oxidized/OxidizedClient.java +++ b/src/main/java/safro/oxidized/OxidizedClient.java @@ -1,34 +1,17 @@ package safro.oxidized; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; -import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry; -import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.BlockRenderLayerMap; import net.minecraft.client.gui.screen.ingame.HandledScreens; +import net.minecraft.client.render.BlockRenderLayer; import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.util.Identifier; import safro.oxidized.block.screen.CopperKilnScreen; -import safro.oxidized.entity.CopperGolemEntityModel; -import safro.oxidized.entity.CopperGolemEntityRenderer; import safro.oxidized.registry.BlockRegistry; -import safro.oxidized.registry.EntityRegistry; public class OxidizedClient implements ClientModInitializer { - public static final EntityModelLayer COPPER_GOLEM_LAYER = new EntityModelLayer(Identifier.of("oxidized", "copper_golem_layer"), "copper_golem_layer"); - @Override public void onInitializeClient() { - if (Oxidized.CONFIG.enable_copper_golem) { - EntityModelLayerRegistry.registerModelLayer(COPPER_GOLEM_LAYER, CopperGolemEntityModel::getTexturedModelData); - EntityRendererRegistry.register(EntityRegistry.COPPER_GOLEM, CopperGolemEntityRenderer::new); - } - - BlockRenderLayerMap.INSTANCE.putBlock(BlockRegistry.COPPER_RAIL, RenderLayer.getCutout()); - BlockRenderLayerMap.INSTANCE.putBlock(BlockRegistry.COPPER_KILN, RenderLayer.getCutout()); - BlockRenderLayerMap.INSTANCE.putBlock(BlockRegistry.COPPER_LANTERN, RenderLayer.getCutout()); - BlockRenderLayerMap.INSTANCE.putBlock(BlockRegistry.COPPER_TRAP, RenderLayer.getCutout()); - + BlockRenderLayerMap.putBlocks(BlockRenderLayer.CUTOUT, BlockRegistry.COPPER_RAIL, BlockRegistry.COPPER_KILN, BlockRegistry.COPPER_TRAP); HandledScreens.register(BlockRegistry.COPPER_KILN_SCREEN_HANDLER, CopperKilnScreen::new); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/CopperButtonBlock.java b/src/main/java/safro/oxidized/block/CopperButtonBlock.java index a38c9bc..354c169 100644 --- a/src/main/java/safro/oxidized/block/CopperButtonBlock.java +++ b/src/main/java/safro/oxidized/block/CopperButtonBlock.java @@ -2,11 +2,9 @@ import net.minecraft.block.BlockSetType; import net.minecraft.block.ButtonBlock; -import net.minecraft.sound.SoundEvents; public class CopperButtonBlock extends ButtonBlock { - public CopperButtonBlock(Settings settings) { super(BlockSetType.IRON, 20, settings); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/CopperKilnBlock.java b/src/main/java/safro/oxidized/block/CopperKilnBlock.java index 865d2c8..df427d2 100644 --- a/src/main/java/safro/oxidized/block/CopperKilnBlock.java +++ b/src/main/java/safro/oxidized/block/CopperKilnBlock.java @@ -8,13 +8,13 @@ import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.particle.ParticleTypes; -import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.stat.Stats; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import safro.oxidized.block.entity.CopperKilnBlockEntity; import safro.oxidized.registry.BlockRegistry; @@ -36,33 +36,25 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return new CopperKilnBlockEntity(pos, state); } - @Nullable @Override - public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { + public @Nullable BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { return validateTicker(world, type, BlockRegistry.COPPER_KILN_BLOCK_ENTITY); } @Override - public void openScreen(World world, BlockPos pos, PlayerEntity player) { - BlockEntity blockEntity = world.getBlockEntity(pos); - if (blockEntity instanceof CopperKilnBlockEntity) { - player.openHandledScreen((NamedScreenHandlerFactory)blockEntity); - player.incrementStat(Stats.INTERACT_WITH_FURNACE); - } - + public void openScreen(@NotNull World world, BlockPos pos, PlayerEntity player) { + if (!(world.getBlockEntity(pos) instanceof CopperKilnBlockEntity kiln)) return; + player.openHandledScreen(kiln); + player.incrementStat(Stats.INTERACT_WITH_FURNACE); } @Override - public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { - if (state.get(LIT)) { - double d = (double)pos.getX() + 0.5D; - double e = pos.getY(); - double f = (double)pos.getZ() + 0.5D; - if (random.nextDouble() < 0.1D) { - world.playSound(d, e, f, SoundEvents.BLOCK_SMOKER_SMOKE, SoundCategory.BLOCKS, 1.0F, 1.0F, false); - } - - world.addParticle(ParticleTypes.SMOKE, d, e + 1.1D, f, 0.0D, 0.0D, 0.0D); - } + public void randomDisplayTick(@NotNull BlockState state, World world, BlockPos pos, Random random) { + if (!state.get(LIT)) return; + var x = pos.getX() + 0.5d; + var y = pos.getY(); + var z = pos.getZ() + 0.5d; + if (random.nextDouble() < 0.1D) world.playSoundClient(x, y, z, SoundEvents.BLOCK_SMOKER_SMOKE, SoundCategory.BLOCKS, 1.0F, 1.0F, false); + world.addParticleClient(ParticleTypes.SMOKE, x, y + 1.1D, z, 0.0D, 0.0D, 0.0D); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/CopperPanBlock.java b/src/main/java/safro/oxidized/block/CopperPanBlock.java index eeb34dc..c66ee63 100644 --- a/src/main/java/safro/oxidized/block/CopperPanBlock.java +++ b/src/main/java/safro/oxidized/block/CopperPanBlock.java @@ -23,12 +23,15 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; +import net.minecraft.world.tick.ScheduledTickView; +import org.jetbrains.annotations.NotNull; import safro.oxidized.Oxidized; public class CopperPanBlock extends Block implements Waterloggable { - public static final IntProperty PANNED; - public static final BooleanProperty WATERLOGGED; - private static final VoxelShape SHAPE = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 5.0D, 16.0D); + public static final IntProperty PANNED = Properties.HATCH; + public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; + private static final VoxelShape SHAPE = createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 5.0D, 16.0D); public CopperPanBlock(Settings settings) { super(settings); @@ -36,25 +39,24 @@ public CopperPanBlock(Settings settings) { } @Override - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - int i = state.get(PANNED); - float range = 0.55F; - if (state.getFluidState().isIn(FluidTags.WATER) && isSpecialBlockBelow(world, pos)) { - if (i < 2) { - world.setBlockState(pos, state.with(PANNED, i + 1), 2); - } else { - if (Oxidized.CONFIG.enable_copper_pan_sound) world.playSound(null, pos, SoundEvents.ENTITY_FISHING_BOBBER_SPLASH, SoundCategory.BLOCKS, 0.4F, 0.9F + random.nextFloat() * 0.2F); - double d = (double)(world.random.nextFloat() * range) + (1-range)/2; - double e = 0.66000000238418579D; - double g = (double)(world.random.nextFloat() * range) + (1-range)/2; - ItemEntity itemEntity = new ItemEntity(world, (double)pos.getX() + d, (double)pos.getY() + e, (double)pos.getZ() + g, new ItemStack(getPannedItem(random))); - itemEntity.setToDefaultPickupDelay(); - world.spawnEntity(itemEntity); - } + public void randomTick(@NotNull BlockState state, ServerWorld world, BlockPos pos, Random random) { + int panned = state.get(PANNED); + var range = 0.55F; + if (!state.getFluidState().isIn(FluidTags.WATER) || !isSpecialBlockBelow(world, pos)) return; + if (panned < 2) { + world.setBlockState(pos, state.with(PANNED, panned + 1), 2); + } else { + if (Oxidized.CONFIG.enable_copper_pan_sound) world.playSound(null, pos, SoundEvents.ENTITY_FISHING_BOBBER_SPLASH, SoundCategory.BLOCKS, 0.4F, 0.9F + random.nextFloat() * 0.2F); + var d = (double)(world.random.nextFloat() * range) + (1-range)/2; + var e = 0.66000000238418579D; + var g = (double)(world.random.nextFloat() * range) + (1-range)/2; + var itemEntity = new ItemEntity(world, (double)pos.getX() + d, (double)pos.getY() + e, (double)pos.getZ() + g, new ItemStack(getPannedItem(random))); + itemEntity.setToDefaultPickupDelay(); + world.spawnEntity(itemEntity); } } - public Item getPannedItem(Random random) { + public Item getPannedItem(@NotNull Random random) { if (random.nextFloat() <= Oxidized.CONFIG.iron_nugget_chance) { return Items.IRON_NUGGET; } else if (random.nextFloat() <= Oxidized.CONFIG.gold_nugget_chance) { @@ -65,36 +67,34 @@ public Item getPannedItem(Random random) { return Items.EMERALD; } else if (random.nextFloat() <= Oxidized.CONFIG.gravel_chance) { return Items.GRAVEL; - } - else + } else { return Items.CLAY_BALL; + } } - public static boolean isSpecialBlockBelow(BlockView world, BlockPos pos) { + public static boolean isSpecialBlockBelow(BlockView world, @NotNull BlockPos pos) { return isBlock(world, pos.down()); } - public static boolean isBlock(BlockView world, BlockPos pos) { + public static boolean isBlock(@NotNull BlockView world, BlockPos pos) { return world.getBlockState(pos).isIn(BlockTags.SAND) || world.getBlockState(pos).isOf(Blocks.GRAVEL); } @Override - public FluidState getFluidState(BlockState state) { + public FluidState getFluidState(@NotNull BlockState state) { return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); } @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos()); + public BlockState getPlacementState(@NotNull ItemPlacementContext ctx) { + var fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos()); return this.getDefaultState().with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER); } @Override - public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { - if (state.get(WATERLOGGED)) { - world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); - } - return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + protected BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, Random random) { + if (world instanceof ServerWorld serverWorld && state.get(WATERLOGGED)) serverWorld.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + return super.getStateForNeighborUpdate(state, world, tickView, pos, direction, neighborPos, neighborState, random); } @Override @@ -108,15 +108,9 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po } @Override - public void appendProperties(StateManager.Builder builder) { + public void appendProperties(StateManager.@NotNull Builder builder) { builder.add(PANNED); builder.add(WATERLOGGED); super.appendProperties(builder); } - - static { - PANNED = Properties.HATCH; - WATERLOGGED = Properties.WATERLOGGED; - } - -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/CopperRailBlock.java b/src/main/java/safro/oxidized/block/CopperRailBlock.java index f3e16e9..ab98719 100644 --- a/src/main/java/safro/oxidized/block/CopperRailBlock.java +++ b/src/main/java/safro/oxidized/block/CopperRailBlock.java @@ -1,9 +1,13 @@ package safro.oxidized.block; import com.mojang.serialization.MapCodec; -import net.minecraft.block.*; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.AbstractRailBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.block.enums.RailShape; import net.minecraft.entity.vehicle.AbstractMinecartEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.EnumProperty; @@ -12,37 +16,33 @@ import net.minecraft.util.BlockMirror; import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.jetbrains.annotations.NotNull; import safro.oxidized.Oxidized; import safro.oxidized.mixin.MinecartEntityAccessor; import safro.oxidized.util.MinecartHandler; public class CopperRailBlock extends AbstractRailBlock { public static final MapCodec CODEC = createCodec(CopperRailBlock::new); - public static final EnumProperty SHAPE; - public static final BooleanProperty POWERED; + public static final EnumProperty SHAPE = Properties.STRAIGHT_RAIL_SHAPE; + public static final BooleanProperty POWERED = Properties.POWERED; public CopperRailBlock(AbstractBlock.Settings settings) { super(true, settings); this.setDefaultState(this.stateManager.getDefaultState().with(SHAPE, RailShape.NORTH_SOUTH).with(POWERED, false).with(WATERLOGGED, false)); } - public void onMoveOnRail(BlockPos pos, BlockState state, AbstractMinecartEntity minecart, CallbackInfo info) { - + public void onMoveOnRail(ServerWorld world, BlockPos pos, @NotNull BlockState state, AbstractMinecartEntity minecart) { if (!state.get(POWERED)) { - double slowDownScaler = 0.25D; + var slowDownScaler = 0.25D; minecart.setVelocity(minecart.getVelocity().multiply(slowDownScaler, 1.0D, slowDownScaler)); return; } - - RailShape railShape = state.get(getShapeProperty()); - Vec3d velocity = minecart.getVelocity(); - double speed = Math.sqrt(velocity.x * velocity.x + velocity.z * velocity.z); - + var railShape = state.get(this.getShapeProperty()); + var velocity = minecart.getVelocity(); + var speed = Math.sqrt(velocity.x * velocity.x + velocity.z * velocity.z); if (speed > 0.01D) { - minecart.setVelocity(velocity.normalize().multiply(((MinecartEntityAccessor) minecart).invokeGetMaxOffRailSpeed() * 10D)); + minecart.setVelocity(velocity.normalize().multiply(((MinecartEntityAccessor) minecart).invokeGetMaxOffRailSpeed(world) * 10D)); } else { MinecartHandler.handleBlockHit(pos, minecart, railShape); } @@ -52,11 +52,11 @@ public boolean isPoweredByOtherRails(World world, BlockPos pos, BlockState state if (distance >= Oxidized.CONFIG.copper_rail_range) { return false; } else { - int i = pos.getX(); - int j = pos.getY(); - int k = pos.getZ(); - boolean bl2 = true; - RailShape railShape = state.get(SHAPE); + var i = pos.getX(); + var j = pos.getY(); + var k = pos.getZ(); + var bl2 = true; + var railShape = state.get(SHAPE); switch(railShape) { case NORTH_SOUTH: if (bl) { @@ -80,7 +80,6 @@ public boolean isPoweredByOtherRails(World world, BlockPos pos, BlockState state ++j; bl2 = false; } - railShape = RailShape.EAST_WEST; break; case ASCENDING_WEST: @@ -91,7 +90,6 @@ public boolean isPoweredByOtherRails(World world, BlockPos pos, BlockState state } else { ++i; } - railShape = RailShape.EAST_WEST; break; case ASCENDING_NORTH: @@ -102,7 +100,6 @@ public boolean isPoweredByOtherRails(World world, BlockPos pos, BlockState state ++j; bl2 = false; } - railShape = RailShape.NORTH_SOUTH; break; case ASCENDING_SOUTH: @@ -113,10 +110,8 @@ public boolean isPoweredByOtherRails(World world, BlockPos pos, BlockState state } else { --k; } - railShape = RailShape.NORTH_SOUTH; } - if (this.isPoweredByOtherRails(world, new BlockPos(i, j, k), bl, distance, railShape)) { return true; } else { @@ -125,22 +120,14 @@ public boolean isPoweredByOtherRails(World world, BlockPos pos, BlockState state } } - public boolean isPoweredByOtherRails(World world, BlockPos pos, boolean bl, int distance, RailShape shape) { - BlockState blockState = world.getBlockState(pos); - if (!blockState.isOf(this)) { - return false; - } else { - RailShape railShape = blockState.get(SHAPE); - if (shape == RailShape.EAST_WEST && (railShape == RailShape.NORTH_SOUTH || railShape == RailShape.ASCENDING_NORTH || railShape == RailShape.ASCENDING_SOUTH)) { - return false; - } else if (shape == RailShape.NORTH_SOUTH && (railShape == RailShape.EAST_WEST || railShape == RailShape.ASCENDING_EAST || railShape == RailShape.ASCENDING_WEST)) { - return false; - } else if (blockState.get(POWERED)) { - return world.isReceivingRedstonePower(pos) ? true : this.isPoweredByOtherRails(world, pos, blockState, bl, distance + 1); - } else { - return false; - } - } + public boolean isPoweredByOtherRails(@NotNull World world, BlockPos pos, boolean bl, int distance, RailShape shape) { + var blockState = world.getBlockState(pos); + if (!blockState.isOf(this)) return false; + var railShape = blockState.get(SHAPE); + if (shape == RailShape.EAST_WEST && (railShape == RailShape.NORTH_SOUTH || railShape == RailShape.ASCENDING_NORTH || railShape == RailShape.ASCENDING_SOUTH)) return false; + if (shape == RailShape.NORTH_SOUTH && (railShape == RailShape.EAST_WEST || railShape == RailShape.ASCENDING_EAST || railShape == RailShape.ASCENDING_WEST)) return false; + if (blockState.get(POWERED)) return world.isReceivingRedstonePower(pos) || this.isPoweredByOtherRails(world, pos, blockState, bl, distance + 1); + return false; } @Override @@ -148,145 +135,94 @@ protected MapCodec getCodec() { return CODEC; } - public void updateBlockState(BlockState state, World world, BlockPos pos, Block neighbor) { + @Override + public void updateBlockState(@NotNull BlockState state, @NotNull World world, BlockPos pos, Block neighbor) { boolean bl = state.get(POWERED); - boolean bl2 = world.isReceivingRedstonePower(pos) || this.isPoweredByOtherRails(world, pos, state, true, 0) || this.isPoweredByOtherRails(world, pos, state, false, 0); - if (bl2 != bl) { - world.setBlockState(pos, state.with(POWERED, bl2), Block.NOTIFY_ALL); - world.updateNeighborsAlways(pos.down(), this); - if (state.get(SHAPE).isAscending()) { - world.updateNeighborsAlways(pos.up(), this); - } - } - + var bl2 = world.isReceivingRedstonePower(pos) || this.isPoweredByOtherRails(world, pos, state, true, 0) || this.isPoweredByOtherRails(world, pos, state, false, 0); + if (bl2 == bl) return; + world.setBlockState(pos, state.with(POWERED, bl2), NOTIFY_ALL); + world.updateNeighbors(pos.down(), this); + if (state.get(SHAPE).isAscending()) world.updateNeighbors(pos.up(), this); } + @Override public Property getShapeProperty() { return SHAPE; } - public BlockState rotate(BlockState state, BlockRotation rotation) { + @Override + public BlockState rotate(BlockState state, @NotNull BlockRotation rotation) { switch(rotation) { case CLOCKWISE_180: - switch(state.get(SHAPE)) { - case ASCENDING_EAST: - return state.with(SHAPE, RailShape.ASCENDING_WEST); - case ASCENDING_WEST: - return state.with(SHAPE, RailShape.ASCENDING_EAST); - case ASCENDING_NORTH: - return state.with(SHAPE, RailShape.ASCENDING_SOUTH); - case ASCENDING_SOUTH: - return state.with(SHAPE, RailShape.ASCENDING_NORTH); - case SOUTH_EAST: - return state.with(SHAPE, RailShape.NORTH_WEST); - case SOUTH_WEST: - return state.with(SHAPE, RailShape.NORTH_EAST); - case NORTH_WEST: - return state.with(SHAPE, RailShape.SOUTH_EAST); - case NORTH_EAST: - return state.with(SHAPE, RailShape.SOUTH_WEST); + switch (state.get(SHAPE)) { + case ASCENDING_EAST -> state.with(SHAPE, RailShape.ASCENDING_WEST); + case ASCENDING_WEST -> state.with(SHAPE, RailShape.ASCENDING_EAST); + case ASCENDING_NORTH -> state.with(SHAPE, RailShape.ASCENDING_SOUTH); + case ASCENDING_SOUTH -> state.with(SHAPE, RailShape.ASCENDING_NORTH); + case SOUTH_EAST -> state.with(SHAPE, RailShape.NORTH_WEST); + case SOUTH_WEST -> state.with(SHAPE, RailShape.NORTH_EAST); + case NORTH_WEST -> state.with(SHAPE, RailShape.SOUTH_EAST); + case NORTH_EAST -> state.with(SHAPE, RailShape.SOUTH_WEST); } case COUNTERCLOCKWISE_90: - switch(state.get(SHAPE)) { - case NORTH_SOUTH: - return state.with(SHAPE, RailShape.EAST_WEST); - case EAST_WEST: - return state.with(SHAPE, RailShape.NORTH_SOUTH); - case ASCENDING_EAST: - return state.with(SHAPE, RailShape.ASCENDING_NORTH); - case ASCENDING_WEST: - return state.with(SHAPE, RailShape.ASCENDING_SOUTH); - case ASCENDING_NORTH: - return state.with(SHAPE, RailShape.ASCENDING_WEST); - case ASCENDING_SOUTH: - return state.with(SHAPE, RailShape.ASCENDING_EAST); - case SOUTH_EAST: - return state.with(SHAPE, RailShape.NORTH_EAST); - case SOUTH_WEST: - return state.with(SHAPE, RailShape.SOUTH_EAST); - case NORTH_WEST: - return state.with(SHAPE, RailShape.SOUTH_WEST); - case NORTH_EAST: - return state.with(SHAPE, RailShape.NORTH_WEST); - } + return switch (state.get(SHAPE)) { + case NORTH_SOUTH -> state.with(SHAPE, RailShape.EAST_WEST); + case EAST_WEST -> state.with(SHAPE, RailShape.NORTH_SOUTH); + case ASCENDING_EAST -> state.with(SHAPE, RailShape.ASCENDING_NORTH); + case ASCENDING_WEST -> state.with(SHAPE, RailShape.ASCENDING_SOUTH); + case ASCENDING_NORTH -> state.with(SHAPE, RailShape.ASCENDING_WEST); + case ASCENDING_SOUTH -> state.with(SHAPE, RailShape.ASCENDING_EAST); + case SOUTH_EAST -> state.with(SHAPE, RailShape.NORTH_EAST); + case SOUTH_WEST -> state.with(SHAPE, RailShape.SOUTH_EAST); + case NORTH_WEST -> state.with(SHAPE, RailShape.SOUTH_WEST); + case NORTH_EAST -> state.with(SHAPE, RailShape.NORTH_WEST); + }; case CLOCKWISE_90: - switch(state.get(SHAPE)) { - case NORTH_SOUTH: - return state.with(SHAPE, RailShape.EAST_WEST); - case EAST_WEST: - return state.with(SHAPE, RailShape.NORTH_SOUTH); - case ASCENDING_EAST: - return state.with(SHAPE, RailShape.ASCENDING_SOUTH); - case ASCENDING_WEST: - return state.with(SHAPE, RailShape.ASCENDING_NORTH); - case ASCENDING_NORTH: - return state.with(SHAPE, RailShape.ASCENDING_EAST); - case ASCENDING_SOUTH: - return state.with(SHAPE, RailShape.ASCENDING_WEST); - case SOUTH_EAST: - return state.with(SHAPE, RailShape.SOUTH_WEST); - case SOUTH_WEST: - return state.with(SHAPE, RailShape.NORTH_WEST); - case NORTH_WEST: - return state.with(SHAPE, RailShape.NORTH_EAST); - case NORTH_EAST: - return state.with(SHAPE, RailShape.SOUTH_EAST); - } + return switch (state.get(SHAPE)) { + case NORTH_SOUTH -> state.with(SHAPE, RailShape.EAST_WEST); + case EAST_WEST -> state.with(SHAPE, RailShape.NORTH_SOUTH); + case ASCENDING_EAST -> state.with(SHAPE, RailShape.ASCENDING_SOUTH); + case ASCENDING_WEST -> state.with(SHAPE, RailShape.ASCENDING_NORTH); + case ASCENDING_NORTH -> state.with(SHAPE, RailShape.ASCENDING_EAST); + case ASCENDING_SOUTH -> state.with(SHAPE, RailShape.ASCENDING_WEST); + case SOUTH_EAST -> state.with(SHAPE, RailShape.SOUTH_WEST); + case SOUTH_WEST -> state.with(SHAPE, RailShape.NORTH_WEST); + case NORTH_WEST -> state.with(SHAPE, RailShape.NORTH_EAST); + case NORTH_EAST -> state.with(SHAPE, RailShape.SOUTH_EAST); + }; default: return state; } } - public BlockState mirror(BlockState state, BlockMirror mirror) { - RailShape railShape = state.get(SHAPE); - switch(mirror) { - case LEFT_RIGHT: - switch(railShape) { - case ASCENDING_NORTH: - return state.with(SHAPE, RailShape.ASCENDING_SOUTH); - case ASCENDING_SOUTH: - return state.with(SHAPE, RailShape.ASCENDING_NORTH); - case SOUTH_EAST: - return state.with(SHAPE, RailShape.NORTH_EAST); - case SOUTH_WEST: - return state.with(SHAPE, RailShape.NORTH_WEST); - case NORTH_WEST: - return state.with(SHAPE, RailShape.SOUTH_WEST); - case NORTH_EAST: - return state.with(SHAPE, RailShape.SOUTH_EAST); - default: - return super.mirror(state, mirror); - } - case FRONT_BACK: - switch(railShape) { - case ASCENDING_EAST: - return state.with(SHAPE, RailShape.ASCENDING_WEST); - case ASCENDING_WEST: - return state.with(SHAPE, RailShape.ASCENDING_EAST); - case ASCENDING_NORTH: - case ASCENDING_SOUTH: - default: - break; - case SOUTH_EAST: - return state.with(SHAPE, RailShape.SOUTH_WEST); - case SOUTH_WEST: - return state.with(SHAPE, RailShape.SOUTH_EAST); - case NORTH_WEST: - return state.with(SHAPE, RailShape.NORTH_EAST); - case NORTH_EAST: - return state.with(SHAPE, RailShape.NORTH_WEST); - } - } - - return super.mirror(state, mirror); + @Override + public BlockState mirror(@NotNull BlockState state, @NotNull BlockMirror mirror) { + var railShape = state.get(SHAPE); + return switch (mirror) { + case LEFT_RIGHT -> switch (railShape) { + case ASCENDING_NORTH -> state.with(SHAPE, RailShape.ASCENDING_SOUTH); + case ASCENDING_SOUTH -> state.with(SHAPE, RailShape.ASCENDING_NORTH); + case SOUTH_EAST -> state.with(SHAPE, RailShape.NORTH_EAST); + case SOUTH_WEST -> state.with(SHAPE, RailShape.NORTH_WEST); + case NORTH_WEST -> state.with(SHAPE, RailShape.SOUTH_WEST); + case NORTH_EAST -> state.with(SHAPE, RailShape.SOUTH_EAST); + default -> super.mirror(state, mirror); + }; + case FRONT_BACK -> switch (railShape) { + case ASCENDING_EAST -> state.with(SHAPE, RailShape.ASCENDING_WEST); + case ASCENDING_WEST -> state.with(SHAPE, RailShape.ASCENDING_EAST); + case SOUTH_EAST -> state.with(SHAPE, RailShape.SOUTH_WEST); + case SOUTH_WEST -> state.with(SHAPE, RailShape.SOUTH_EAST); + case NORTH_WEST -> state.with(SHAPE, RailShape.NORTH_EAST); + case NORTH_EAST -> state.with(SHAPE, RailShape.NORTH_WEST); + default -> super.mirror(state, mirror); + }; + default -> super.mirror(state, mirror); + }; } - public void appendProperties(StateManager.Builder builder) { + @Override + public void appendProperties(StateManager.@NotNull Builder builder) { builder.add(SHAPE, POWERED, WATERLOGGED); } - - static { - SHAPE = Properties.STRAIGHT_RAIL_SHAPE; - POWERED = Properties.POWERED; - } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/CopperTrapBlock.java b/src/main/java/safro/oxidized/block/CopperTrapBlock.java index 7a9e60c..b7cb4d2 100644 --- a/src/main/java/safro/oxidized/block/CopperTrapBlock.java +++ b/src/main/java/safro/oxidized/block/CopperTrapBlock.java @@ -4,29 +4,35 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCollisionHandler; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemPlacementContext; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import net.minecraft.world.World; +import net.minecraft.world.block.WireOrientation; import net.minecraft.world.event.GameEvent; -import safro.oxidized.util.TrapDamageSource; -import safro.saflib.util.DamageSourceUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import safro.oxidized.Oxidized; public class CopperTrapBlock extends Block { - public static final BooleanProperty CLOSED; - protected static final VoxelShape SHAPE; + public static final RegistryKey TRAP = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Oxidized.id("trap")); + public static final BooleanProperty CLOSED = BooleanProperty.of("closed"); + protected static final VoxelShape SHAPE = createCuboidShape(2, 0, 1, 14, 2, 15); public CopperTrapBlock(Settings settings) { super(settings); @@ -34,8 +40,8 @@ public CopperTrapBlock(Settings settings) { } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { - if (!world.isClient) { + public ActionResult onUse(BlockState state, @NotNull World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + if (!world.isClient()) { if (state.get(CLOSED)) { world.setBlockState(pos, state.with(CLOSED, false), 3); } else { @@ -48,23 +54,18 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt } @Override - public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { - if (entity instanceof LivingEntity && !entity.canAvoidTraps()) { - if (!state.get(CLOSED)) { - if (!world.isClient && (entity.lastRenderX != entity.getX() || entity.lastRenderZ != entity.getZ())) { - double d = Math.abs(entity.getX() - entity.lastRenderX); - double e = Math.abs(entity.getZ() - entity.lastRenderZ); - if (d >= 0.003000000026077032D || e >= 0.003000000026077032D) { - entity.damage(DamageSourceUtil.create(world, TrapDamageSource.TRAP), 5.0F); - } - this.schedule(state, world, pos); - } - } - } + protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, EntityCollisionHandler handler) { + if (!(entity instanceof LivingEntity) || entity.canAvoidTraps()) return; + if (state.get(CLOSED)) return; + if (world.isClient() || (entity.lastRenderX == entity.getX() && entity.lastRenderZ == entity.getZ())) return; + var d = Math.abs(entity.getX() - entity.lastRenderX); + var e = Math.abs(entity.getZ() - entity.lastRenderZ); + if (d >= 0.003000000026077032D || e >= 0.003000000026077032D) entity.damage((ServerWorld) world, world.getDamageSources().create(TRAP), 5.0F); + this.schedule(state, world, pos); } @Override - protected void appendProperties(StateManager.Builder builder) { + protected void appendProperties(StateManager.@NotNull Builder builder) { builder.add(CLOSED); super.appendProperties(builder); } @@ -74,38 +75,31 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po return SHAPE; } - public void schedule(BlockState state, World world, BlockPos pos) { + public void schedule(@NotNull BlockState state, @NotNull World world, BlockPos pos) { world.setBlockState(pos, state.with(CLOSED, true), 3); world.scheduleBlockTick(pos, this, 60); - world.updateNeighborsAlways(pos, this); + world.updateNeighbors(pos, this); } @Override - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + public void scheduledTick(@NotNull BlockState state, ServerWorld world, BlockPos pos, Random random) { if (state.get(CLOSED)) { world.setBlockState(pos, state.with(CLOSED, false)); - world.updateNeighborsAlways(pos, this); + world.updateNeighbors(pos, this); } } @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { + public BlockState getPlacementState(@NotNull ItemPlacementContext ctx) { return this.getDefaultState().with(CLOSED, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())); } @Override - public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { - if (!world.isClient) { - world.setBlockState(pos, state.with(CLOSED, world.isReceivingRedstonePower(pos))); - } + protected void neighborUpdate(BlockState state, @NotNull World world, BlockPos pos, Block sourceBlock, @Nullable WireOrientation wireOrientation, boolean notify) { + if (!world.isClient()) world.setBlockState(pos, state.with(CLOSED, world.isReceivingRedstonePower(pos))); } - public static boolean isClosed(BlockState state) { + public static boolean isClosed(@NotNull BlockState state) { return state.get(CLOSED); } - - static { - CLOSED = BooleanProperty.of("closed"); - SHAPE = Block.createCuboidShape(2, 0, 1, 14, 2, 15); - } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/entity/CopperKilnBlockEntity.java b/src/main/java/safro/oxidized/block/entity/CopperKilnBlockEntity.java index b2d4871..83e0886 100644 --- a/src/main/java/safro/oxidized/block/entity/CopperKilnBlockEntity.java +++ b/src/main/java/safro/oxidized/block/entity/CopperKilnBlockEntity.java @@ -1,8 +1,10 @@ package safro.oxidized.block.entity; +import net.minecraft.block.AbstractBlock; import net.minecraft.block.BlockState; import net.minecraft.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.FuelRegistry; import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.text.Text; @@ -11,20 +13,22 @@ import safro.oxidized.registry.BlockRegistry; public class CopperKilnBlockEntity extends AbstractFurnaceBlockEntity { - public CopperKilnBlockEntity(BlockPos pos, BlockState state) { super(BlockRegistry.COPPER_KILN_BLOCK_ENTITY, pos, state, BlockRegistry.COPPER_KILN_RECIPE_TYPE); } + @Override protected Text getContainerName() { return Text.translatable("container.oxidized.copper_kiln"); } - protected int getFuelTime(ItemStack fuel) { - return super.getFuelTime(fuel) / 2; + @Override + protected int getFuelTime(FuelRegistry fuelRegistry, ItemStack stack) { + return super.getFuelTime(fuelRegistry, stack) / 2; } + @Override protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) { return new CopperKilnScreenHandler(syncId, playerInventory, this, this.propertyDelegate); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/screen/CopperKilnScreen.java b/src/main/java/safro/oxidized/block/screen/CopperKilnScreen.java index 78ae4f4..e265a4c 100644 --- a/src/main/java/safro/oxidized/block/screen/CopperKilnScreen.java +++ b/src/main/java/safro/oxidized/block/screen/CopperKilnScreen.java @@ -1,18 +1,21 @@ package safro.oxidized.block.screen; - import net.minecraft.client.gui.screen.ingame.AbstractFurnaceScreen; +import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import safro.oxidized.recipe.CopperKilnRecipeBook; + +import java.util.List; public class CopperKilnScreen extends AbstractFurnaceScreen { private static final Identifier LIT_PROGRESS_TEXTURE = Identifier.ofVanilla("container/furnace/lit_progress"); private static final Identifier BURN_PROGRESS_TEXTURE = Identifier.ofVanilla("container/furnace/burn_progress"); private static final Identifier TEXTURE = Identifier.ofVanilla("textures/gui/container/furnace.png"); + private static final Text TOGGLE_KILNABLE_TEXT = Text.translatable("gui.recipebook.toggleRecipes.kilnable"); + private static final List TABS = List.of(); // TODO: Tabs public CopperKilnScreen(CopperKilnScreenHandler handler, PlayerInventory inventory, Text title) { - super(handler, new CopperKilnRecipeBook(), inventory, title, TEXTURE, LIT_PROGRESS_TEXTURE, BURN_PROGRESS_TEXTURE); + super(handler, inventory, title, TOGGLE_KILNABLE_TEXT, TEXTURE, LIT_PROGRESS_TEXTURE, BURN_PROGRESS_TEXTURE, TABS); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/block/screen/CopperKilnScreenHandler.java b/src/main/java/safro/oxidized/block/screen/CopperKilnScreenHandler.java index 9387ca3..9b1b45d 100644 --- a/src/main/java/safro/oxidized/block/screen/CopperKilnScreenHandler.java +++ b/src/main/java/safro/oxidized/block/screen/CopperKilnScreenHandler.java @@ -8,7 +8,6 @@ import safro.oxidized.registry.BlockRegistry; public class CopperKilnScreenHandler extends AbstractFurnaceScreenHandler { - public CopperKilnScreenHandler(int syncId, PlayerInventory playerInventory) { super(BlockRegistry.COPPER_KILN_SCREEN_HANDLER, BlockRegistry.COPPER_KILN_RECIPE_TYPE, RecipeBookCategory.FURNACE, syncId, playerInventory); } @@ -16,4 +15,4 @@ public CopperKilnScreenHandler(int syncId, PlayerInventory playerInventory) { public CopperKilnScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, PropertyDelegate propertyDelegate) { super(BlockRegistry.COPPER_KILN_SCREEN_HANDLER, BlockRegistry.COPPER_KILN_RECIPE_TYPE, RecipeBookCategory.FURNACE, syncId, playerInventory, inventory, propertyDelegate); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/config/OxidizedConfig.java b/src/main/java/safro/oxidized/config/OxidizedConfig.java index a6b0b73..e918c75 100644 --- a/src/main/java/safro/oxidized/config/OxidizedConfig.java +++ b/src/main/java/safro/oxidized/config/OxidizedConfig.java @@ -2,6 +2,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.nio.charset.StandardCharsets; @@ -21,20 +22,12 @@ public class OxidizedConfig { public float emerald_chance = 0.02F; public boolean enable_copper_pan_sound = true; - public int copper_golem_button_chance = 30; - public boolean enable_copper_golem = true; - public boolean enable_rose_gold_tools = true; - public static OxidizedConfig loadConfig(File file) { + public static @NotNull OxidizedConfig loadConfig(@NotNull File file) { OxidizedConfig config; - if (file.exists() && file.isFile()) { - try ( - FileInputStream fileInputStream = new FileInputStream(file); - InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); - ) { + try (var fileInputStream = new FileInputStream(file); var inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8); var bufferedReader = new BufferedReader(inputStreamReader)) { config = GSON.fromJson(bufferedReader, OxidizedConfig.class); } catch (IOException e) { throw new RuntimeException("Failed to load config", e); @@ -42,20 +35,15 @@ public static OxidizedConfig loadConfig(File file) { } else { config = new OxidizedConfig(); } - config.saveConfig(file); - return config; } public void saveConfig(File config) { - try ( - FileOutputStream stream = new FileOutputStream(config); - Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8); - ) { + try (var stream = new FileOutputStream(config); Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) { GSON.toJson(this, writer); } catch (IOException e) { throw new RuntimeException("Failed to load config", e); } } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/entity/CopperGolemEntity.java b/src/main/java/safro/oxidized/entity/CopperGolemEntity.java deleted file mode 100644 index 4a93d30..0000000 --- a/src/main/java/safro/oxidized/entity/CopperGolemEntity.java +++ /dev/null @@ -1,167 +0,0 @@ -package safro.oxidized.entity; - -import net.minecraft.block.Oxidizable; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LightningEntity; -import net.minecraft.entity.ai.goal.LookAroundGoal; -import net.minecraft.entity.ai.goal.LookAtEntityGoal; -import net.minecraft.entity.ai.goal.WanderAroundGoal; -import net.minecraft.entity.attribute.DefaultAttributeContainer; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.data.DataTracker; -import net.minecraft.entity.data.TrackedData; -import net.minecraft.entity.data.TrackedDataHandlerRegistry; -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.entity.passive.GolemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.AxeItem; -import net.minecraft.item.ItemStack; -import net.minecraft.particle.ParticleTypes; -import net.minecraft.particle.ParticleUtil; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.math.intprovider.UniformIntProvider; -import net.minecraft.world.World; -import safro.oxidized.entity.goal.MoveToLightningRodGoal; -import safro.oxidized.entity.goal.UseButtonGoal; - -public class CopperGolemEntity extends GolemEntity { - private static final TrackedData IS_PRESSING_BUTTONS; - private Oxidizable.OxidationLevel oxidizationLevel; - private int tickOxidization = 0; - - public CopperGolemEntity(EntityType entityType, World world) { - super(entityType, world); - } - - @Override - protected void initGoals() { - this.goalSelector.add(1, new MoveToLightningRodGoal(this, 0.6D)); - this.goalSelector.add(2, new UseButtonGoal(this, 0.8D)); - this.goalSelector.add(3, new WanderAroundGoal(this, 0.4)); - this.goalSelector.add(4, new LookAtEntityGoal(this, PlayerEntity.class, 6.0F)); - this.goalSelector.add(5, new LookAroundGoal(this)); - } - - public static DefaultAttributeContainer.Builder createCopperGolemAttributes() { - return MobEntity.createMobAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 15.0D).add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.27D).add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 0.75D); - } - - public void setPressingButtons(boolean pressing) { - this.dataTracker.set(IS_PRESSING_BUTTONS, pressing); - } - - public boolean isPressingButtons() { - return this.dataTracker.get(IS_PRESSING_BUTTONS); - } - - public Oxidizable.OxidationLevel getOxidizationLevel() { - return oxidizationLevel; - } - - public boolean isStatue() { - return oxidizationLevel.equals(Oxidizable.OxidationLevel.OXIDIZED); - } - - @Override - public void tick() { - super.tick(); - this.oxidizationTick(); - if (this.oxidizationLevel != Oxidizable.OxidationLevel.OXIDIZED) { - ++tickOxidization; - } - this.setAiDisabled(this.isStatue()); - } - - protected void oxidizationTick() { - if (tickOxidization == 1200000) { - this.oxidizationLevel = Oxidizable.OxidationLevel.OXIDIZED; - } else if (tickOxidization == 800000) { - this.oxidizationLevel = Oxidizable.OxidationLevel.WEATHERED; - } else if (tickOxidization == 400000) { - this.oxidizationLevel = Oxidizable.OxidationLevel.EXPOSED; - } else if (this.tickOxidization < 400000) { - this.oxidizationLevel = Oxidizable.OxidationLevel.UNAFFECTED; - } - } - - @Override - protected void initDataTracker(DataTracker.Builder builder) { - super.initDataTracker(builder); - builder.add(IS_PRESSING_BUTTONS, false); - } - - @Override - protected ActionResult interactMob(PlayerEntity player, Hand hand) { - World world = player.getWorld(); - ItemStack stack = player.getStackInHand(hand); - if (stack.getItem() instanceof AxeItem && this.oxidizationLevel != Oxidizable.OxidationLevel.UNAFFECTED) { - this.degradeLevel(); - world.playSound(player, player.getBlockPos(), SoundEvents.ITEM_AXE_SCRAPE, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.syncWorldEvent(player, 3005, player.getBlockPos(), 0); - stack.damage(1, player, hand == Hand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND); - return ActionResult.SUCCESS; - } - return ActionResult.PASS; - } - - public void degradeLevel() { - if (this.oxidizationLevel == Oxidizable.OxidationLevel.OXIDIZED) { - this.oxidizationLevel = Oxidizable.OxidationLevel.WEATHERED; - } else if (this.oxidizationLevel == Oxidizable.OxidationLevel.WEATHERED) { - this.oxidizationLevel = Oxidizable.OxidationLevel.EXPOSED; - } else if (this.oxidizationLevel == Oxidizable.OxidationLevel.EXPOSED) { - this.oxidizationLevel = Oxidizable.OxidationLevel.UNAFFECTED; - } - } - - @Override - public void onStruckByLightning(ServerWorld world, LightningEntity lightning) { - super.onStruckByLightning(world, lightning); - this.tickOxidization = 0; - this.oxidizationLevel = Oxidizable.OxidationLevel.UNAFFECTED; - ParticleUtil.spawnParticle(this.getMovementDirection().getAxis(), world, this.getBlockPos(), 0.125D, ParticleTypes.ELECTRIC_SPARK, UniformIntProvider.create(1, 2)); - } - - @Override - public boolean damage(DamageSource source, float amount) { - boolean bl = super.damage(source, amount); - if (source.getAttacker() instanceof LightningEntity) { - return false; - } else - return bl; - } - - @Override - protected void pushAway(Entity entity) { - if (entity instanceof PlayerEntity) { - super.pushAway(entity); - } - } - - @Override - protected int getNextAirUnderwater(int air) { - return air; - } - - @Override - protected SoundEvent getHurtSound(DamageSource source) { - return SoundEvents.ENTITY_IRON_GOLEM_HURT; - } - - @Override - protected SoundEvent getDeathSound() { - return SoundEvents.ENTITY_IRON_GOLEM_DEATH; - } - - static { - IS_PRESSING_BUTTONS = DataTracker.registerData(CopperGolemEntity.class, TrackedDataHandlerRegistry.BOOLEAN); - } -} diff --git a/src/main/java/safro/oxidized/entity/CopperGolemEntityModel.java b/src/main/java/safro/oxidized/entity/CopperGolemEntityModel.java deleted file mode 100644 index ff9646c..0000000 --- a/src/main/java/safro/oxidized/entity/CopperGolemEntityModel.java +++ /dev/null @@ -1,67 +0,0 @@ -package safro.oxidized.entity; - -import net.minecraft.client.model.*; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.model.CrossbowPosing; -import net.minecraft.client.render.entity.model.EntityModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.MathHelper; - -public class CopperGolemEntityModel extends EntityModel { - private final ModelPart right_leg; - private final ModelPart left_leg; - private final ModelPart body; - private final ModelPart head; - private final ModelPart left_arm; - private final ModelPart right_arm; - - public CopperGolemEntityModel(ModelPart root) { - this.right_leg = root.getChild("right_leg"); - this.left_leg = root.getChild("left_leg"); - this.body = root.getChild("body"); - this.left_arm = root.getChild("left_arm"); - this.right_arm = root.getChild("right_arm"); - this.head = root.getChild("head"); - } - - public static TexturedModelData getTexturedModelData() { - ModelData modelData = new ModelData(); - ModelPartData modelPartData = modelData.getRoot(); - modelPartData.addChild("right_leg", ModelPartBuilder.create().uv(16,0).cuboid(-2.2F, -2.0F, -1.0F, 2.0F, 2.0F, 2.0F), ModelTransform.pivot(0.0F,24.0F,0.0F)); - modelPartData.addChild("left_leg", ModelPartBuilder.create().uv(8,15).cuboid(0.2F, -2.0F, -1.0F, 2.0F, 2.0F, 2.0F), ModelTransform.pivot(0.0F,24.0F,0.0F)); - modelPartData.addChild("body", ModelPartBuilder.create().uv(0,8).cuboid(-3.0F, -6.0F, -1.5F, 6.0F, 4.0F, 3.0F), ModelTransform.pivot(0.0F,24.0F,0.0F)); - modelPartData.addChild("left_arm", ModelPartBuilder.create().uv(16,15).cuboid(3.0F, -6.0F, -0.5F, 1.0F, 5.0F, 1.0F), ModelTransform.pivot(0.0F,24.0F,0.0F)); - modelPartData.addChild("right_arm", ModelPartBuilder.create().uv(18,8).cuboid(-4.0F, -6.0F, -0.5F, 1.0F, 5.0F, 1.0F), ModelTransform.pivot(0.0F,24.0F,0.0F)); - modelPartData.addChild("head", ModelPartBuilder.create().uv(0,0).cuboid(-3.0F, -10.0F, -2.0F, 6.0F, 4.0F, 4.0F).uv(0,0).cuboid(-0.5F, -7.6F, -3.0F, 1.0F, 2.0F, 1.0F).uv(6,15).cuboid(-0.5F, -11.0F, -0.5F, 1.0F, 1.0F, 1.0F).uv(0,15).cuboid(-1.0F, -13.0F, -1.0F, 2.0F, 2.0F, 2.0F), ModelTransform.pivot(0.0F,24.0F,0.0F)); - return TexturedModelData.of(modelData,32,32); - } - - @Override - public void setAngles(CopperGolemEntity entity, float f, float g, float h, float i, float j){ - this.right_leg.pitch = -1.5F * MathHelper.wrap(f, 13.0F) * g; - this.left_leg.pitch = 1.5F * MathHelper.wrap(f, 13.0F) * g; - this.right_leg.yaw = 0.0F; - this.left_leg.yaw = 0.0F; - if (entity.isPressingButtons()) { - this.right_arm.pivotZ = -0.5F; - this.left_arm.pivotZ = -0.5F; - this.right_arm.pitch = 6.1F; - this.left_arm.pitch = 6.1F; - } else { - this.right_arm.pivotZ = 0F; - this.left_arm.pivotZ = 0F; - this.right_arm.pitch = 0F; - this.left_arm.pitch = 0F; - } - } - - @Override - public void render(MatrixStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, int color) { - left_leg.render(matrixStack, buffer, packedLight, packedOverlay); - right_leg.render(matrixStack, buffer, packedLight, packedOverlay); - body.render(matrixStack, buffer, packedLight, packedOverlay); - left_arm.render(matrixStack, buffer, packedLight, packedOverlay); - right_arm.render(matrixStack, buffer, packedLight, packedOverlay); - head.render(matrixStack, buffer, packedLight, packedOverlay); - } -} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/entity/CopperGolemEntityRenderer.java b/src/main/java/safro/oxidized/entity/CopperGolemEntityRenderer.java deleted file mode 100644 index daedbe4..0000000 --- a/src/main/java/safro/oxidized/entity/CopperGolemEntityRenderer.java +++ /dev/null @@ -1,29 +0,0 @@ -package safro.oxidized.entity; - -import net.minecraft.block.Oxidizable; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.MobEntityRenderer; -import net.minecraft.util.Identifier; -import safro.oxidized.OxidizedClient; - -public class CopperGolemEntityRenderer extends MobEntityRenderer { - private static final Identifier UNAFFECTED = Identifier.of("oxidized", "textures/entity/copper_golem.png"); - private static final Identifier EXPOSED = Identifier.of("oxidized", "textures/entity/exposed_copper_golem.png"); - private static final Identifier WEATHERED = Identifier.of("oxidized", "textures/entity/weathered_copper_golem.png"); - private static final Identifier OXIDIZED = Identifier.of("oxidized", "textures/entity/oxidized_copper_golem.png"); - - public CopperGolemEntityRenderer(EntityRendererFactory.Context context) { - super(context, new CopperGolemEntityModel(context.getPart(OxidizedClient.COPPER_GOLEM_LAYER)), 0.2F); - } - - public Identifier getTexture(CopperGolemEntity entity) { - if (entity.getOxidizationLevel() == Oxidizable.OxidationLevel.EXPOSED) { - return EXPOSED; - } else if (entity.getOxidizationLevel() == Oxidizable.OxidationLevel.WEATHERED) { - return WEATHERED; - } else if (entity.getOxidizationLevel() == Oxidizable.OxidationLevel.OXIDIZED) { - return OXIDIZED; - } else - return UNAFFECTED; - } -} diff --git a/src/main/java/safro/oxidized/entity/goal/MoveToLightningRodGoal.java b/src/main/java/safro/oxidized/entity/goal/MoveToLightningRodGoal.java deleted file mode 100644 index fd6a1b0..0000000 --- a/src/main/java/safro/oxidized/entity/goal/MoveToLightningRodGoal.java +++ /dev/null @@ -1,26 +0,0 @@ -package safro.oxidized.entity.goal; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.entity.ai.goal.MoveToTargetPosGoal; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.WorldView; -import safro.oxidized.entity.CopperGolemEntity; - -public class MoveToLightningRodGoal extends MoveToTargetPosGoal { - private final CopperGolemEntity golem; - - public MoveToLightningRodGoal(CopperGolemEntity entity, double speed) { - super(entity, speed, 10); - this.golem = entity; - } - - public boolean canStart() { - return this.golem.getWorld().isThundering() && super.canStart(); - } - - protected boolean isTargetPos(WorldView world, BlockPos pos) { - BlockState state = world.getBlockState(pos); - return state.isOf(Blocks.LIGHTNING_ROD); - } -} diff --git a/src/main/java/safro/oxidized/entity/goal/UseButtonGoal.java b/src/main/java/safro/oxidized/entity/goal/UseButtonGoal.java deleted file mode 100644 index 96ec0e7..0000000 --- a/src/main/java/safro/oxidized/entity/goal/UseButtonGoal.java +++ /dev/null @@ -1,130 +0,0 @@ -package safro.oxidized.entity.goal; - -import net.minecraft.block.BlockState; -import net.minecraft.block.ButtonBlock; -import net.minecraft.entity.ai.goal.MoveToTargetPosGoal; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.WorldView; -import net.minecraft.world.event.GameEvent; -import safro.oxidized.Oxidized; -import safro.oxidized.block.CopperButtonBlock; -import safro.oxidized.entity.CopperGolemEntity; -import safro.oxidized.registry.BlockRegistry; - -public class UseButtonGoal extends MoveToTargetPosGoal { - private final CopperGolemEntity golem; - private BlockState button; - private BlockPos buttonPos; - - public UseButtonGoal(CopperGolemEntity entity, double speed) { - super(entity, speed, 8); - this.golem = entity; - } - - @Override - public boolean canStart() { - return super.canStart(); - } - - @Override - public void start() { - super.start(); - } - - @Override - public void stop() { - super.stop(); - this.golem.setPressingButtons(false); - this.button = null; - this.buttonPos = null; - } - - public void tick() { - if (this.hasReached()) { - // if (this.hasButton(targetPos) && button != null && buttonPos != null) { - this.golem.setPressingButtons(true); - if (MathHelper.nextInt(golem.getRandom(), 1, Oxidized.CONFIG.copper_golem_button_chance) == 2) { - BlockState state = this.golem.getWorld().getBlockState(this.targetPos); - if (!state.get(ButtonBlock.POWERED)) { - ((CopperButtonBlock)state.getBlock()).powerOn(state, this.golem.getWorld(), this.targetPos, null); - } - } - // } - } - super.tick(); - } - - @Override - protected boolean isTargetPos(WorldView world, BlockPos pos) { - BlockState state = world.getBlockState(pos); - return state.isOf(BlockRegistry.COPPER_BUTTON); - } - - @Override - protected BlockPos getTargetPos() { - return this.targetPos; - } - - private BlockPos getStandablePos(BlockPos pos) { - World world = this.golem.getWorld(); - if (isStandable(world, pos.west())) { - return pos.west(); - } else if (isStandable(world, pos.north())) { - return pos.north(); - } else if (isStandable(world, pos.south())) { - return pos.south(); - } else if (isStandable(world, pos.up())) { - return pos.up(); - } else if (isStandable(world, pos.down())) { - return pos.down(); - } else { - return pos.east(); - } - } - - private boolean isStandable(World world, BlockPos pos) { - return world.isAir(pos) && world.getBlockState(pos.down()).hasSolidTopSurface(world, pos, this.golem); - } - - private boolean hasButton(BlockPos pos) { - if (this.golem.getWorld().getBlockState(pos).isOf(BlockRegistry.COPPER_BUTTON)) { - button = this.golem.getWorld().getBlockState(pos); - buttonPos = pos; - return true; - } else if (this.golem.getWorld().getBlockState(pos.down()).isOf(BlockRegistry.COPPER_BUTTON)) { - button = this.golem.getWorld().getBlockState(pos.down()); - buttonPos = pos.down(); - return true; - } else if (this.golem.getWorld().getBlockState(pos.up()).isOf(BlockRegistry.COPPER_BUTTON)) { - button = this.golem.getWorld().getBlockState(pos.up()); - buttonPos = pos.up(); - return true; - } else if (this.golem.getWorld().getBlockState(pos.east()).isOf(BlockRegistry.COPPER_BUTTON)) { - button = this.golem.getWorld().getBlockState(pos.east()); - buttonPos = pos.east(); - return true; - } else if (this.golem.getWorld().getBlockState(pos.west()).isOf(BlockRegistry.COPPER_BUTTON)) { - button = this.golem.getWorld().getBlockState(pos.west()); - buttonPos = pos.west(); - return true; - } else if (this.golem.getWorld().getBlockState(pos.north()).isOf(BlockRegistry.COPPER_BUTTON)) { - button = this.golem.getWorld().getBlockState(pos.north()); - buttonPos = pos.north(); - return true; - } else if (this.golem.getWorld().getBlockState(pos.south()).isOf(BlockRegistry.COPPER_BUTTON)) { - button = this.golem.getWorld().getBlockState(pos.south()); - buttonPos = pos.south(); - return true; - } else - button = null; - buttonPos = null; - return false; - } - - @Override - public double getDesiredDistanceToTarget() { - return 0.75D; - } -} diff --git a/src/main/java/safro/oxidized/item/BarometerItem.java b/src/main/java/safro/oxidized/item/BarometerItem.java index 3ac821d..c367464 100644 --- a/src/main/java/safro/oxidized/item/BarometerItem.java +++ b/src/main/java/safro/oxidized/item/BarometerItem.java @@ -2,48 +2,41 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; import net.minecraft.world.level.ServerWorldProperties; +import org.jetbrains.annotations.NotNull; import safro.oxidized.mixin.ServerWorldAccessor; public class BarometerItem extends Item { - public BarometerItem(Settings settings) { super(settings); } @Override - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { - ItemStack stack = user.getStackInHand(hand); - if (!world.isClient) { - ServerWorld serverWorld = (ServerWorld) world; - ServerWorldProperties properties = ((ServerWorldAccessor) serverWorld).getWorldProperties(); - Biome biome = serverWorld.getBiome(user.getBlockPos()).value(); - + public ActionResult use(@NotNull World world, PlayerEntity user, Hand hand) { + if (world instanceof ServerWorld serverWorld) { + var properties = ((ServerWorldAccessor) serverWorld).getWorldProperties(); + var biome = serverWorld.getBiome(user.getBlockPos()).value(); if (serverWorld.isThundering()) { user.sendMessage(getTime(properties, false, false), true); } else if (serverWorld.isRaining()) { - user.sendMessage(getTime(properties, true, biome.isCold(user.getBlockPos())), true); + user.sendMessage(getTime(properties, true, biome.isCold(user.getBlockPos(), world.getSeaLevel())), true); } else { user.sendMessage(Text.translatable("text.oxidized.clearweather", properties.getClearWeatherTime() / 20).formatted(Formatting.GOLD), true); } } - return TypedActionResult.success(stack, world.isClient()); + return ActionResult.SUCCESS; } private static Text getTime(ServerWorldProperties properties, boolean rain, boolean snow) { - int time = (rain ? properties.getRainTime() : properties.getThunderTime()) / 20; - String key = rain ? "text.oxidized.rain" : "text.oxidized.thunderstorm"; - if (snow) { - key = "text.oxidized.snow"; - } + var time = (rain ? properties.getRainTime() : properties.getThunderTime()) / 20; + var key = rain ? "text.oxidized.rain" : "text.oxidized.thunderstorm"; + if (snow) key = "text.oxidized.snow"; return Text.translatable(key, time).formatted(Formatting.GOLD); } } diff --git a/src/main/java/safro/oxidized/item/CopperPulsarItem.java b/src/main/java/safro/oxidized/item/CopperPulsarItem.java index f98607c..c8b6d67 100644 --- a/src/main/java/safro/oxidized/item/CopperPulsarItem.java +++ b/src/main/java/safro/oxidized/item/CopperPulsarItem.java @@ -3,6 +3,7 @@ import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.NbtComponent; import net.minecraft.entity.Entity; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.ExperienceOrbEntity; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.player.PlayerEntity; @@ -11,69 +12,50 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; -import net.minecraft.util.math.Box; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import safro.oxidized.Oxidized; +import safro.oxidized.registry.ItemRegistry; import java.util.List; public class CopperPulsarItem extends Item { - - static final String POWERED = "Powered"; - public CopperPulsarItem(Settings settings) { super(settings); } @Override - public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { - if(!world.isClient() && isActive(stack)) { - ServerPlayerEntity player = (ServerPlayerEntity) entity; - Box box = player.getBoundingBox().expand(Oxidized.CONFIG.pulsar_reach); - - List entityItems = player.getWorld().getEntitiesByClass(ItemEntity.class, box, EntityPredicates.VALID_ENTITY); - for (ItemEntity item : entityItems) { - item.onPlayerCollision(player); - } - - List entityXP = player.getWorld().getEntitiesByClass(ExperienceOrbEntity.class, box, EntityPredicates.VALID_ENTITY); - for (ExperienceOrbEntity xp : entityXP) { - xp.onPlayerCollision(player); - } - } + public void inventoryTick(ItemStack stack, @NotNull ServerWorld world, Entity entity, @Nullable EquipmentSlot slot) { + if (world.isClient() || !this.isActive(stack)) return; + var player = (ServerPlayerEntity) entity; + var box = player.getBoundingBox().expand(Oxidized.CONFIG.pulsar_reach); + var entityItems = player.getEntityWorld().getEntitiesByClass(ItemEntity.class, box, EntityPredicates.VALID_ENTITY); + for (var item : entityItems) item.onPlayerCollision(player); + var entityXP = player.getEntityWorld().getEntitiesByClass(ExperienceOrbEntity.class, box, EntityPredicates.VALID_ENTITY); + for (var xp : entityXP) xp.onPlayerCollision(player); } @Override - public TypedActionResult use(World world, PlayerEntity player, Hand hand) { - ItemStack pulsar = player.getStackInHand(hand); - - if (!world.isClient() && !player.isSneaking()) { + public ActionResult use(@NotNull World world, @NotNull PlayerEntity user, Hand hand) { + var pulsar = user.getStackInHand(hand); + if (!world.isClient() && !user.isSneaking()) { this.toggle(pulsar); - String status = this.isActive(pulsar) ? "Active" : "Inactive"; - player.sendMessage(Text.of("§6Pulsar is now: " + status), false); + var status = this.isActive(pulsar) ? "Active" : "Inactive"; + user.sendMessage(Text.of("§6Pulsar is now: " + status), false); } - return TypedActionResult.success(pulsar, world.isClient()); + return ActionResult.SUCCESS; } - public boolean isActive(ItemStack stack) { - NbtComponent data = stack.get(DataComponentTypes.CUSTOM_DATA); - if (data != null) { - NbtCompound tag = data.copyNbt(); - if (tag.contains("Powered")) { - return tag.getBoolean("Powered"); - } - } - return true; + public boolean isActive(@NotNull ItemStack stack) { + return Boolean.TRUE.equals(stack.get(ItemRegistry.POWERED)); } - public void toggle(ItemStack stack) { - boolean active = isActive(stack); - NbtCompound tag = new NbtCompound(); - tag.putBoolean("Powered", !active); - NbtComponent.set(DataComponentTypes.CUSTOM_DATA, stack, tag); + public void toggle(@NotNull ItemStack stack) { + stack.set(ItemRegistry.POWERED, !this.isActive(stack)); } } diff --git a/src/main/java/safro/oxidized/item/RoseGoldMaterial.java b/src/main/java/safro/oxidized/item/RoseGoldMaterial.java deleted file mode 100644 index cb1cccc..0000000 --- a/src/main/java/safro/oxidized/item/RoseGoldMaterial.java +++ /dev/null @@ -1,42 +0,0 @@ -package safro.oxidized.item; - -import net.minecraft.block.Block; -import net.minecraft.item.Items; -import net.minecraft.item.ToolMaterial; -import net.minecraft.recipe.Ingredient; -import net.minecraft.registry.tag.BlockTags; -import net.minecraft.registry.tag.TagKey; - -public class RoseGoldMaterial implements ToolMaterial { - public static final RoseGoldMaterial ROSE_GOLD = new RoseGoldMaterial(); - - @Override - public int getDurability() { - return 250; - } - - @Override - public float getMiningSpeedMultiplier() { - return 12.0F; - } - - @Override - public float getAttackDamage() { - return 0.0F; - } - - @Override - public TagKey getInverseTag() { - return BlockTags.INCORRECT_FOR_GOLD_TOOL; - } - - @Override - public int getEnchantability() { - return 22; - } - - @Override - public Ingredient getRepairIngredient() { - return Ingredient.ofItems(Items.COPPER_INGOT); - } -} diff --git a/src/main/java/safro/oxidized/mixin/LightningRodBlockMixin.java b/src/main/java/safro/oxidized/mixin/LightningRodBlockMixin.java deleted file mode 100644 index 05b88a2..0000000 --- a/src/main/java/safro/oxidized/mixin/LightningRodBlockMixin.java +++ /dev/null @@ -1,79 +0,0 @@ -package safro.oxidized.mixin; - -import net.minecraft.advancement.criterion.Criteria; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.LightningRodBlock; -import net.minecraft.block.pattern.BlockPattern; -import net.minecraft.block.pattern.BlockPatternBuilder; -import net.minecraft.block.pattern.CachedBlockPosition; -import net.minecraft.predicate.block.BlockStatePredicate; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import safro.oxidized.Oxidized; -import safro.oxidized.entity.CopperGolemEntity; -import safro.oxidized.registry.EntityRegistry; - -import java.util.Iterator; - -@Mixin(LightningRodBlock.class) -public class LightningRodBlockMixin { - @Unique - @Nullable - private BlockPattern copperGolemPattern = null; - - @Inject(method = "onBlockAdded", at = @At("TAIL")) - private void checkForGolem(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify, CallbackInfo ci) { - if (!oldState.isOf(state.getBlock())) { - if (Oxidized.CONFIG.enable_copper_golem) this.trySpawnCopperGolem(world, pos); - } - } - - @Unique - private void trySpawnCopperGolem(World world, BlockPos pos) { - BlockPattern.Result result = this.getCopperGolemPattern().searchAround(world, pos); - int i; - Iterator var6; - ServerPlayerEntity serverPlayerEntity; - int j; - if (result != null) { - for (i = 0; i < this.getCopperGolemPattern().getHeight(); ++i) { - CachedBlockPosition cachedBlockPosition = result.translate(0, i, 0); - world.setBlockState(cachedBlockPosition.getBlockPos(), Blocks.AIR.getDefaultState(), 2); - world.syncWorldEvent(2001, cachedBlockPosition.getBlockPos(), Block.getRawIdFromState(cachedBlockPosition.getBlockState())); - } - - CopperGolemEntity golem = EntityRegistry.COPPER_GOLEM.create(world); - BlockPos blockPos = result.translate(0, 2, 0).getBlockPos(); - golem.refreshPositionAndAngles((double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.05D, (double) blockPos.getZ() + 0.5D, 0.0F, 0.0F); - world.spawnEntity(golem); - var6 = world.getNonSpectatingEntities(ServerPlayerEntity.class, golem.getBoundingBox().expand(5.0D)).iterator(); - - while (var6.hasNext()) { - serverPlayerEntity = (ServerPlayerEntity) var6.next(); - Criteria.SUMMONED_ENTITY.trigger(serverPlayerEntity, golem); - } - - for (j = 0; j < this.getCopperGolemPattern().getHeight(); ++j) { - CachedBlockPosition cachedBlockPosition2 = result.translate(0, j, 0); - world.updateNeighbors(cachedBlockPosition2.getBlockPos(), Blocks.AIR); - } - } - } - - @Unique - private BlockPattern getCopperGolemPattern() { - if (this.copperGolemPattern == null) { - this.copperGolemPattern = BlockPatternBuilder.start().aisle("^", "$", "#").where('^', CachedBlockPosition.matchesBlockState(BlockStatePredicate.forBlock(Blocks.LIGHTNING_ROD))).where('$', CachedBlockPosition.matchesBlockState(BlockStatePredicate.forBlock(Blocks.CARVED_PUMPKIN))).where('#', CachedBlockPosition.matchesBlockState(BlockStatePredicate.forBlock(Blocks.COPPER_BLOCK).or(BlockStatePredicate.forBlock(Blocks.CUT_COPPER)))).build(); - } - return this.copperGolemPattern; - } -} diff --git a/src/main/java/safro/oxidized/mixin/LivingEntityMixin.java b/src/main/java/safro/oxidized/mixin/LivingEntityMixin.java index c777aeb..ffebf8b 100644 --- a/src/main/java/safro/oxidized/mixin/LivingEntityMixin.java +++ b/src/main/java/safro/oxidized/mixin/LivingEntityMixin.java @@ -13,12 +13,10 @@ public class LivingEntityMixin { @Inject(method = "tick", at = @At("HEAD")) private void trapEntity(CallbackInfo ci) { - LivingEntity entity = (LivingEntity) (Object) this; - if (entity.getBlockStateAtPos().isOf(BlockRegistry.COPPER_TRAP)) { - if (CopperTrapBlock.isClosed(entity.getBlockStateAtPos())) { - Vec3d v = entity.getPos(); - entity.teleport(v.getX(), v.getY(), v.getZ(), false); - } - } + var entity = (LivingEntity) (Object) this; + if (!entity.getBlockStateAtPos().isOf(BlockRegistry.COPPER_TRAP)) return; + if (!CopperTrapBlock.isClosed(entity.getBlockStateAtPos())) return; + var v = entity.getEntityPos(); + entity.teleport(v.getX(), v.getY(), v.getZ(), false); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/mixin/MinecartEntityAccessor.java b/src/main/java/safro/oxidized/mixin/MinecartEntityAccessor.java index 5a71f3b..e6a1544 100644 --- a/src/main/java/safro/oxidized/mixin/MinecartEntityAccessor.java +++ b/src/main/java/safro/oxidized/mixin/MinecartEntityAccessor.java @@ -1,6 +1,7 @@ package safro.oxidized.mixin; import net.minecraft.entity.vehicle.AbstractMinecartEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @@ -11,6 +12,6 @@ public interface MinecartEntityAccessor { boolean invokeWillHitBlockAt(BlockPos pos); @Invoker("getMaxSpeed") - double invokeGetMaxOffRailSpeed(); + double invokeGetMaxOffRailSpeed(ServerWorld world); } diff --git a/src/main/java/safro/oxidized/mixin/MinecartRailMixin.java b/src/main/java/safro/oxidized/mixin/MinecartRailMixin.java index 943ab2e..60eef36 100644 --- a/src/main/java/safro/oxidized/mixin/MinecartRailMixin.java +++ b/src/main/java/safro/oxidized/mixin/MinecartRailMixin.java @@ -3,8 +3,13 @@ import net.minecraft.block.AbstractRailBlock; import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; import net.minecraft.entity.vehicle.AbstractMinecartEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -12,14 +17,14 @@ import safro.oxidized.block.CopperRailBlock; @Mixin(AbstractMinecartEntity.class) -public abstract class MinecartRailMixin { +public abstract class MinecartRailMixin extends Entity { + public MinecartRailMixin(EntityType type, World world) { + super(type, world); + } - @SuppressWarnings("ConstantConditions") - @Inject(at = @At("HEAD"), method = "moveOnRail", cancellable = true) - protected void moveOnRail(BlockPos pos, BlockState state, CallbackInfo info) { - AbstractRailBlock railBlock = (AbstractRailBlock) state.getBlock(); - if (railBlock instanceof CopperRailBlock) { - ((CopperRailBlock) railBlock).onMoveOnRail(pos, state, (AbstractMinecartEntity) (Object) this, info); - } + @Inject(method = "moveOnRail", at = @At("HEAD"), cancellable = true) + protected void moveOnRail(ServerWorld world, CallbackInfo ci) { + var state = this.getEntityWorld().getBlockState(this.getBlockPos()); + if (state.getBlock() instanceof CopperRailBlock rail) rail.onMoveOnRail(world, this.getBlockPos(), state, (AbstractMinecartEntity) (Object) this); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/recipe/CopperKilnRecipe.java b/src/main/java/safro/oxidized/recipe/CopperKilnRecipe.java index c6c1f2c..b5cdf5c 100644 --- a/src/main/java/safro/oxidized/recipe/CopperKilnRecipe.java +++ b/src/main/java/safro/oxidized/recipe/CopperKilnRecipe.java @@ -1,25 +1,38 @@ package safro.oxidized.recipe; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.recipe.AbstractCookingRecipe; -import net.minecraft.recipe.Ingredient; -import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.item.Items; +import net.minecraft.recipe.*; import net.minecraft.recipe.book.CookingRecipeCategory; +import net.minecraft.recipe.book.RecipeBookCategories; +import net.minecraft.recipe.book.RecipeBookCategory; import net.minecraft.util.Identifier; import safro.oxidized.registry.BlockRegistry; +import safro.oxidized.registry.ItemRegistry; public class CopperKilnRecipe extends AbstractCookingRecipe { - public CopperKilnRecipe(String group, CookingRecipeCategory category, Ingredient input, ItemStack output, float experience, int cookTime) { - super(BlockRegistry.COPPER_KILN_RECIPE_TYPE, group, category, input, output, experience, cookTime); + super(group, category, input, output, experience, cookTime); + } + + @Override + protected Item getCookerItem() { + return BlockRegistry.COPPER_KILN.asItem(); } - public ItemStack createIcon() { - return new ItemStack(BlockRegistry.COPPER_KILN); + @Override + public RecipeType getType() { + return BlockRegistry.COPPER_KILN_RECIPE_TYPE; } @Override - public RecipeSerializer getSerializer() { + public RecipeSerializer getSerializer() { return BlockRegistry.COPPER_KILN_RECIPE_SERIALIZER; } -} + + @Override + public RecipeBookCategory getRecipeBookCategory() { //TODO : custom category + return RecipeBookCategories.CRAFTING_BUILDING_BLOCKS; + } +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/recipe/CopperKilnRecipeBook.java b/src/main/java/safro/oxidized/recipe/CopperKilnRecipeBook.java deleted file mode 100644 index dfdb8f6..0000000 --- a/src/main/java/safro/oxidized/recipe/CopperKilnRecipeBook.java +++ /dev/null @@ -1,21 +0,0 @@ -package safro.oxidized.recipe; - -import net.minecraft.block.entity.AbstractFurnaceBlockEntity; -import net.minecraft.client.gui.screen.recipebook.AbstractFurnaceRecipeBookScreen; -import net.minecraft.item.Item; -import net.minecraft.text.Text; - -import java.util.Set; - -public class CopperKilnRecipeBook extends AbstractFurnaceRecipeBookScreen { - private static final Text LABEL = Text.translatable("gui.recipebook.toggleRecipes.kiln"); - - protected Text getToggleCraftableButtonText() { - return LABEL; - } - - @Override - protected Set getAllowedFuels() { - return AbstractFurnaceBlockEntity.createFuelTimeMap().keySet(); - } -} diff --git a/src/main/java/safro/oxidized/registry/BlockRegistry.java b/src/main/java/safro/oxidized/registry/BlockRegistry.java index 24d6a8b..b361c53 100644 --- a/src/main/java/safro/oxidized/registry/BlockRegistry.java +++ b/src/main/java/safro/oxidized/registry/BlockRegistry.java @@ -1,54 +1,54 @@ package safro.oxidized.registry; +import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry; import net.minecraft.block.*; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.piston.PistonBehavior; -import net.minecraft.recipe.CookingRecipeSerializer; +import net.minecraft.recipe.AbstractCookingRecipe; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeType; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; import net.minecraft.resource.featuretoggle.FeatureFlags; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.state.property.Properties; import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import safro.oxidized.Oxidized; import safro.oxidized.block.*; import safro.oxidized.block.entity.CopperKilnBlockEntity; import safro.oxidized.block.screen.CopperKilnScreenHandler; import safro.oxidized.recipe.CopperKilnRecipe; -import safro.saflib.registry.BaseBlockItemRegistry; -import java.util.function.ToIntFunction; +import java.util.function.Function; -public class BlockRegistry extends BaseBlockItemRegistry { - static { MODID = "oxidized"; } +public class BlockRegistry { + public static final Block COPPER_RAIL = register(Oxidized.id("copper_rail"), CopperRailBlock::new, AbstractBlock.Settings.create().mapColor(MapColor.CLEAR).nonOpaque().pistonBehavior(PistonBehavior.DESTROY).noCollision().strength(0.7F).sounds(BlockSoundGroup.METAL)); + public static final Block VERTICAL_CUT_COPPER = register(Oxidized.id("vertical_cut_copper"), (settings) -> new OxidizableBlock(Oxidizable.OxidationLevel.UNAFFECTED, settings), AbstractBlock.Settings.create().mapColor(MapColor.ORANGE).sounds(BlockSoundGroup.COPPER).requiresTool().strength(3.0F, 6.0F)); + public static final Block VERTICAL_EXPOSED_CUT_COPPER = register(Oxidized.id("vertical_exposed_cut_copper"), (settings) -> new OxidizableBlock(Oxidizable.OxidationLevel.EXPOSED, settings), AbstractBlock.Settings.copy(VERTICAL_CUT_COPPER)); + public static final Block VERTICAL_WEATHERED_CUT_COPPER = register(Oxidized.id("vertical_weathered_cut_copper"), (settings) -> new OxidizableBlock(Oxidizable.OxidationLevel.WEATHERED, settings), AbstractBlock.Settings.copy(VERTICAL_CUT_COPPER)); + public static final Block VERTICAL_OXIDIZED_CUT_COPPER = register(Oxidized.id("vertical_oxidized_cut_copper"), (settings) -> new OxidizableBlock(Oxidizable.OxidationLevel.OXIDIZED, settings), AbstractBlock.Settings.copy(VERTICAL_CUT_COPPER)); + public static final Block WAXED_VERTICAL_CUT_COPPER = register(Oxidized.id("waxed_vertical_cut_copper"), Block::new, AbstractBlock.Settings.copy(VERTICAL_CUT_COPPER)); + public static final Block WAXED_VERTICAL_EXPOSED_CUT_COPPER = register(Oxidized.id("waxed_vertical_exposed_cut_copper"), Block::new, AbstractBlock.Settings.copy(VERTICAL_CUT_COPPER)); + public static final Block WAXED_VERTICAL_WEATHERED_CUT_COPPER = register(Oxidized.id("waxed_vertical_weathered_cut_copper"), Block::new, AbstractBlock.Settings.copy(VERTICAL_CUT_COPPER)); + public static final Block WAXED_VERTICAL_OXIDIZED_CUT_COPPER = register(Oxidized.id("waxed_vertical_oxidized_cut_copper"), Block::new, AbstractBlock.Settings.copy(VERTICAL_CUT_COPPER)); + public static final Block COPPER_PAN = register(Oxidized.id("copper_pan"), CopperPanBlock::new, blockWithStrength(3.0F, 6.0F).ticksRandomly()); + public static final Block COPPER_BUTTON = register(Oxidized.id("copper_button"), CopperButtonBlock::new, AbstractBlock.Settings.create().mapColor(MapColor.CLEAR).nonOpaque().pistonBehavior(PistonBehavior.DESTROY).noCollision().strength(0.5F).sounds(BlockSoundGroup.COPPER)); - public static final Block COPPER_RAIL = register("copper_rail", new CopperRailBlock(AbstractBlock.Settings.create().mapColor(MapColor.CLEAR).nonOpaque().pistonBehavior(PistonBehavior.DESTROY).noCollision().strength(0.7F).sounds(BlockSoundGroup.METAL))); - public static final Block VERTICAL_CUT_COPPER = register("vertical_cut_copper", new OxidizableBlock(Oxidizable.OxidationLevel.UNAFFECTED, AbstractBlock.Settings.create().mapColor(MapColor.ORANGE).sounds(BlockSoundGroup.COPPER).requiresTool().strength(3.0F, 6.0F))); - public static final Block VERTICAL_EXPOSED_CUT_COPPER = register("vertical_exposed_cut_copper", new OxidizableBlock(Oxidizable.OxidationLevel.EXPOSED, AbstractBlock.Settings.copy(BlockRegistry.VERTICAL_CUT_COPPER))); - public static final Block VERTICAL_WEATHERED_CUT_COPPER = register("vertical_weathered_cut_copper", new OxidizableBlock(Oxidizable.OxidationLevel.WEATHERED, AbstractBlock.Settings.copy(BlockRegistry.VERTICAL_CUT_COPPER))); - public static final Block VERTICAL_OXIDIZED_CUT_COPPER = register("vertical_oxidized_cut_copper", new OxidizableBlock(Oxidizable.OxidationLevel.OXIDIZED, AbstractBlock.Settings.copy(BlockRegistry.VERTICAL_CUT_COPPER))); - public static final Block WAXED_VERTICAL_CUT_COPPER = register("waxed_vertical_cut_copper", new Block(AbstractBlock.Settings.copy(BlockRegistry.VERTICAL_CUT_COPPER))); - public static final Block WAXED_VERTICAL_EXPOSED_CUT_COPPER = register("waxed_vertical_exposed_cut_copper", new Block(AbstractBlock.Settings.copy(BlockRegistry.VERTICAL_CUT_COPPER))); - public static final Block WAXED_VERTICAL_WEATHERED_CUT_COPPER = register("waxed_vertical_weathered_cut_copper", new Block(AbstractBlock.Settings.copy(BlockRegistry.VERTICAL_CUT_COPPER))); - public static final Block WAXED_VERTICAL_OXIDIZED_CUT_COPPER = register("waxed_vertical_oxidized_cut_copper", new Block(AbstractBlock.Settings.copy(BlockRegistry.VERTICAL_CUT_COPPER))); - public static final LanternBlock COPPER_LANTERN = register("copper_lantern", new LanternBlock(AbstractBlock.Settings.create().mapColor(MapColor.IRON_GRAY).requiresTool().strength(3.5F).sounds(BlockSoundGroup.LANTERN).luminance((state) -> 15).nonOpaque())); - public static final Block COPPER_PAN = register("copper_pan", new CopperPanBlock(blockWithStrength(3.0F, 6.0F).ticksRandomly())); - public static final Block COPPER_BUTTON = register("copper_button", new CopperButtonBlock(AbstractBlock.Settings.create().mapColor(MapColor.CLEAR).nonOpaque().pistonBehavior(PistonBehavior.DESTROY).noCollision().strength(0.5F).sounds(BlockSoundGroup.COPPER))); - - public static final Block COPPER_KILN = register("copper_kiln", new CopperKilnBlock(blockWithStrength(3.5F, 6.0F).luminance(createLightLevelBlockstate(13)).nonOpaque())); - public static BlockEntityType COPPER_KILN_BLOCK_ENTITY = register("copper_kiln", CopperKilnBlockEntity::new, COPPER_KILN); + public static final Block COPPER_KILN = register(Oxidized.id("copper_kiln"), CopperKilnBlock::new, blockWithStrength(3.5F, 6.0F).luminance((state) -> state.get(Properties.LIT) ? 13 : 0).nonOpaque()); + public static BlockEntityType COPPER_KILN_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, Oxidized.id("copper_kiln"), FabricBlockEntityTypeBuilder.create(CopperKilnBlockEntity::new, COPPER_KILN).build()); public static final ScreenHandlerType COPPER_KILN_SCREEN_HANDLER = Registry.register(Registries.SCREEN_HANDLER, Identifier.of("oxidized", "copper_kiln_screen_handler"), new ScreenHandlerType<>(CopperKilnScreenHandler::new, FeatureFlags.VANILLA_FEATURES)); public static final RecipeType COPPER_KILN_RECIPE_TYPE = Registry.register(Registries.RECIPE_TYPE, Identifier.of("oxidized", "kiln_smelting"), new RecipeType<>() { public String toString() { return "oxidized:kiln_smelting"; } }); - public static final RecipeSerializer COPPER_KILN_RECIPE_SERIALIZER = Registry.register(Registries.RECIPE_SERIALIZER, Identifier.of("oxidized", "kiln_smelting"), new CookingRecipeSerializer<>(CopperKilnRecipe::new, 100)); + public static final RecipeSerializer COPPER_KILN_RECIPE_SERIALIZER = Registry.register(Registries.RECIPE_SERIALIZER, Identifier.of("oxidized", "kiln_smelting"), new AbstractCookingRecipe.Serializer<>(CopperKilnRecipe::new, 100)); - public static final Block COPPER_TRAP = register("copper_trap", new CopperTrapBlock(blockWithStrength(2.0F, 3.0F).noCollision())); + public static final Block COPPER_TRAP = register(Oxidized.id("copper_trap"), CopperTrapBlock::new, blockWithStrength(2.0F, 3.0F).noCollision()); public static void init() { OxidizableBlocksRegistry.registerOxidizableBlockPair(VERTICAL_CUT_COPPER, VERTICAL_EXPOSED_CUT_COPPER); @@ -65,7 +65,9 @@ private static AbstractBlock.Settings blockWithStrength(float hardness, float re return AbstractBlock.Settings.create().mapColor(MapColor.ORANGE).strength(hardness, resistance).requiresTool().sounds(BlockSoundGroup.COPPER); } - private static ToIntFunction createLightLevelBlockstate(int litLevel) { - return (state) -> (Boolean)state.get(Properties.LIT) ? litLevel : 0; + public static Block register(Identifier id, @NotNull Function factory, AbstractBlock.@NotNull Settings settings) { + var key = RegistryKey.of(Registries.BLOCK.getKey(), id); + var block = factory.apply(settings.registryKey(key)); + return Registry.register(Registries.BLOCK, key, block); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/registry/EntityRegistry.java b/src/main/java/safro/oxidized/registry/EntityRegistry.java deleted file mode 100644 index e20da33..0000000 --- a/src/main/java/safro/oxidized/registry/EntityRegistry.java +++ /dev/null @@ -1,23 +0,0 @@ -package safro.oxidized.registry; - -import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; -import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnGroup; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.util.Identifier; -import safro.oxidized.entity.CopperGolemEntity; - -public class EntityRegistry { - public static final EntityType COPPER_GOLEM = EntityType.Builder.create(CopperGolemEntity::new, SpawnGroup.MISC) - .dimensions(0.5F, 0.9F).makeFireImmune().maxTrackingRange(10).build(); - - public static void init() { - Registry.register(Registries.ENTITY_TYPE, Identifier.of("oxidized", "copper_golem"), COPPER_GOLEM); - - // Attributes - FabricDefaultAttributeRegistry.register(COPPER_GOLEM, CopperGolemEntity.createCopperGolemAttributes()); - } -} diff --git a/src/main/java/safro/oxidized/registry/ItemRegistry.java b/src/main/java/safro/oxidized/registry/ItemRegistry.java index b88fa99..f391dd2 100644 --- a/src/main/java/safro/oxidized/registry/ItemRegistry.java +++ b/src/main/java/safro/oxidized/registry/ItemRegistry.java @@ -1,48 +1,66 @@ package safro.oxidized.registry; +import com.mojang.serialization.Codec; +import net.minecraft.component.ComponentType; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.EquippableComponent; import net.minecraft.item.*; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.BlockTags; +import net.minecraft.registry.tag.TagKey; import net.minecraft.text.Text; +import net.minecraft.util.DyeColor; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; import safro.oxidized.Oxidized; import safro.oxidized.item.BarometerItem; import safro.oxidized.item.CopperPulsarItem; -import safro.oxidized.item.RoseGoldMaterial; -import safro.saflib.registry.BaseBlockItemRegistry; import java.util.List; +import java.util.function.Function; +import java.util.function.UnaryOperator; -public class ItemRegistry extends BaseBlockItemRegistry { - static { MODID = "oxidized"; } +public class ItemRegistry { + public static final TagKey ROSE_GOLD_TOOL_MATERIALS = TagKey.of(RegistryKeys.ITEM, Oxidized.id("wooden_tool_materials")); + public static final ToolMaterial ROSE_GOLD = new ToolMaterial(BlockTags.INCORRECT_FOR_GOLD_TOOL, 250, 12f, 0f, 22, ROSE_GOLD_TOOL_MATERIALS); + public static final ComponentType POWERED = registerComponent(Oxidized.id("powered"), builder -> builder.codec(Codec.BOOL).packetCodec(PacketCodecs.BOOLEAN)); public static void init() { - if (Oxidized.CONFIG.enable_copper_pulsar) { - register("copper_pulsar", new CopperPulsarItem(settings())); - } - - register("copper_barometer", new BarometerItem(settings().maxCount(1))); - register("copper_nugget", new Item(settings())); - + if (Oxidized.CONFIG.enable_copper_pulsar) registerItem(Oxidized.id("copper_pulsar"), CopperPulsarItem::new, new Item.Settings().maxCount(1)); + registerItem(Oxidized.id("copper_barometer"), BarometerItem::new, new Item.Settings().maxCount(1)); if (Oxidized.CONFIG.enable_rose_gold_tools) { - register("rose_gold_upgrade_template", createRoseGoldTemplate()); - register("rose_gold_axe", new AxeItem(RoseGoldMaterial.ROSE_GOLD, settings().attributeModifiers(AxeItem.createAttributeModifiers(RoseGoldMaterial.ROSE_GOLD, 6.0F, -3.0F)))); - register("rose_gold_hoe", new HoeItem(RoseGoldMaterial.ROSE_GOLD, settings().attributeModifiers(HoeItem.createAttributeModifiers(RoseGoldMaterial.ROSE_GOLD, 0, -3.0F)))); - register("rose_gold_pickaxe", new PickaxeItem(RoseGoldMaterial.ROSE_GOLD, settings().attributeModifiers(PickaxeItem.createAttributeModifiers(RoseGoldMaterial.ROSE_GOLD, 1, -2.8F)))); - register("rose_gold_shovel", new ShovelItem(RoseGoldMaterial.ROSE_GOLD, settings().attributeModifiers(ShovelItem.createAttributeModifiers(RoseGoldMaterial.ROSE_GOLD, 1.5F, -3.0F)))); - register("rose_gold_sword", new SwordItem(RoseGoldMaterial.ROSE_GOLD, settings().attributeModifiers(SwordItem.createAttributeModifiers(RoseGoldMaterial.ROSE_GOLD, 4, -2.4F)))); - } - - if (Oxidized.CONFIG.enable_copper_golem) { - register("copper_golem_spawn_egg", new SpawnEggItem(EntityRegistry.COPPER_GOLEM, 0x8A4129, 0xC15B36, settings())); + registerItem(Oxidized.id("rose_gold_upgrade_template"), ItemRegistry::createRoseGoldTemplate, new Item.Settings()); + registerItem(Oxidized.id("rose_gold_axe"), (settings) -> new AxeItem(ROSE_GOLD, 6f, -3f, settings), new Item.Settings()); + registerItem(Oxidized.id("rose_gold_hoe"), (settings) -> new HoeItem(ROSE_GOLD, 0, -3f, settings), new Item.Settings()); + registerItem(Oxidized.id("rose_gold_pickaxe"), (settings) -> new Item(settings.pickaxe(ROSE_GOLD, 1, -2.8f)), new Item.Settings()); + registerItem(Oxidized.id("rose_gold_shovel"), (settings) -> new ShovelItem(ROSE_GOLD, 1.5f, -3.0f, settings), new Item.Settings().maxCount(1)); + registerItem(Oxidized.id("rose_gold_sword"), (settings) -> new Item(settings.sword(ROSE_GOLD, 4, -2.4f)), new Item.Settings().maxCount(1)); } } - private static SmithingTemplateItem createRoseGoldTemplate() { - return new SmithingTemplateItem(Text.translatable("text.oxidized.rose_gold_template_applies").formatted(Formatting.BLUE), + private static @NotNull SmithingTemplateItem createRoseGoldTemplate(Item.Settings settings) { + return new SmithingTemplateItem( + Text.translatable("text.oxidized.rose_gold_template_applies").formatted(Formatting.BLUE), Text.translatable("text.oxidized.rose_gold_template_ingredient").formatted(Formatting.BLUE), - Text.translatable("text.oxidized.rose_gold_template").formatted(Formatting.GRAY), Text.translatable("text.oxidized.rose_gold_template.base_desc"), Text.translatable("text.oxidized.rose_gold_template.ing_desc"), - List.of(Identifier.of("item/empty_slot_ingot")), List.of(Identifier.of("item/empty_slot_hoe"), Identifier.of("item/empty_slot_axe"), Identifier.of("item/empty_slot_sword"), Identifier.of("item/empty_slot_shovel"), Identifier.of("item/empty_slot_pickaxe"))); + List.of(Identifier.of("item/empty_slot_ingot")), List.of(Identifier.of("item/empty_slot_hoe"), Identifier.of("item/empty_slot_axe"), Identifier.of("item/empty_slot_sword"), Identifier.of("item/empty_slot_shovel"), Identifier.of("item/empty_slot_pickaxe")), + settings); + } + + public static Item registerItem(Identifier id, @NotNull Function factory, Item.@NotNull Settings settings) { + var key = RegistryKey.of(RegistryKeys.ITEM, id); + var item = factory.apply(settings.registryKey(key)); + if (item instanceof BlockItem blockItem) blockItem.appendBlocks(Item.BLOCK_ITEMS, item); + return Registry.register(Registries.ITEM, key, item); + } + + private static ComponentType registerComponent(Identifier id, @NotNull UnaryOperator> builderOperator) { + return Registry.register(Registries.DATA_COMPONENT_TYPE, id, builderOperator.apply(ComponentType.builder()).build()); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/rei/KilnSmeltingDisplay.java b/src/main/java/safro/oxidized/rei/KilnSmeltingDisplay.java index d698b2a..4adda79 100644 --- a/src/main/java/safro/oxidized/rei/KilnSmeltingDisplay.java +++ b/src/main/java/safro/oxidized/rei/KilnSmeltingDisplay.java @@ -1,25 +1,35 @@ package safro.oxidized.rei; import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.display.DisplaySerializer; import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.plugin.common.displays.cooking.DefaultCookingDisplay; -import net.minecraft.nbt.NbtCompound; import net.minecraft.recipe.RecipeEntry; +import net.minecraft.util.Identifier; import safro.oxidized.recipe.CopperKilnRecipe; import java.util.List; +import java.util.Optional; public class KilnSmeltingDisplay extends DefaultCookingDisplay { + public static DisplaySerializer SERIALIZER = serializer(KilnSmeltingDisplay::new); + public KilnSmeltingDisplay(RecipeEntry recipe) { super(recipe); } - public KilnSmeltingDisplay(List input, List output, NbtCompound tag) { - super(input, output, tag); + public KilnSmeltingDisplay(List input, List output, Optional id, float xp, double cookTime) { + super(input, output, id, xp, cookTime); } @Override public CategoryIdentifier getCategoryIdentifier() { return OxidizedREIPlugin.KILN_SMELTING; } -} + + @Override + public DisplaySerializer getSerializer() { + return SERIALIZER; + } +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/rei/OxidizedREIPlugin.java b/src/main/java/safro/oxidized/rei/OxidizedREIPlugin.java index 8578aa0..593924a 100644 --- a/src/main/java/safro/oxidized/rei/OxidizedREIPlugin.java +++ b/src/main/java/safro/oxidized/rei/OxidizedREIPlugin.java @@ -12,6 +12,7 @@ import me.shedaniel.rei.plugin.client.categories.cooking.DefaultCookingCategory; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; import safro.oxidized.block.screen.CopperKilnScreen; import safro.oxidized.recipe.CopperKilnRecipe; import safro.oxidized.registry.BlockRegistry; @@ -20,19 +21,19 @@ public class OxidizedREIPlugin implements REIClientPlugin { public static final CategoryIdentifier KILN_SMELTING = CategoryIdentifier.of("oxidized", "plugins/kiln_smelting"); @Override - public void registerCategories(CategoryRegistry registry) { + public void registerCategories(@NotNull CategoryRegistry registry) { registry.add(new DefaultCookingCategory(KILN_SMELTING, EntryStacks.of(BlockRegistry.COPPER_KILN), "category.oxidized.kiln_smelting")); registry.addWorkstations(KILN_SMELTING, EntryStacks.of(BlockRegistry.COPPER_KILN)); registry.addWorkstations(CategoryIdentifier.of(Identifier.of("minecraft", "plugins/fuel")), EntryStack.of(VanillaEntryTypes.ITEM, new ItemStack(BlockRegistry.COPPER_KILN))); } @Override - public void registerDisplays(DisplayRegistry registry) { + public void registerDisplays(@NotNull DisplayRegistry registry) { registry.registerRecipeFiller(CopperKilnRecipe.class, BlockRegistry.COPPER_KILN_RECIPE_TYPE, KilnSmeltingDisplay::new); } @Override - public void registerScreens(ScreenRegistry registry) { + public void registerScreens(@NotNull ScreenRegistry registry) { registry.registerContainerClickArea(new Rectangle(78, 32, 28, 23), CopperKilnScreen.class, KILN_SMELTING); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/util/MinecartHandler.java b/src/main/java/safro/oxidized/util/MinecartHandler.java index a4d149f..5015120 100644 --- a/src/main/java/safro/oxidized/util/MinecartHandler.java +++ b/src/main/java/safro/oxidized/util/MinecartHandler.java @@ -2,15 +2,14 @@ import net.minecraft.block.enums.RailShape; import net.minecraft.entity.vehicle.AbstractMinecartEntity; -import net.minecraft.entity.vehicle.MinecartEntity; import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.NotNull; import safro.oxidized.mixin.MinecartEntityAccessor; public class MinecartHandler { - - public static void handleBlockHit(BlockPos pos, AbstractMinecartEntity minecart, RailShape railShape) { - double x = minecart.getVelocity().x; - double z = minecart.getVelocity().z; + public static void handleBlockHit(BlockPos pos, @NotNull AbstractMinecartEntity minecart, RailShape railShape) { + var x = minecart.getVelocity().x; + var z = minecart.getVelocity().z; if (railShape == RailShape.EAST_WEST) { if (((MinecartEntityAccessor) minecart).invokeWillHitBlockAt(pos.west())) { x = 0.02D; @@ -24,7 +23,6 @@ public static void handleBlockHit(BlockPos pos, AbstractMinecartEntity minecart, z = -0.02D; } } - minecart.setVelocity(x, minecart.getVelocity().y, z); } -} +} \ No newline at end of file diff --git a/src/main/java/safro/oxidized/util/TrapDamageSource.java b/src/main/java/safro/oxidized/util/TrapDamageSource.java deleted file mode 100644 index 79b2292..0000000 --- a/src/main/java/safro/oxidized/util/TrapDamageSource.java +++ /dev/null @@ -1,11 +0,0 @@ -package safro.oxidized.util; - -import net.minecraft.entity.damage.DamageType; -import net.minecraft.registry.RegistryKey; -import safro.saflib.util.DamageSourceUtil; - -public class TrapDamageSource { - public static final RegistryKey TRAP = DamageSourceUtil.register("oxidized", "trap"); - - public static void init() {} -} diff --git a/src/main/resources/assets/oxidized/lang/en_us.json b/src/main/resources/assets/oxidized/lang/en_us.json index acc2608..0b4da03 100644 --- a/src/main/resources/assets/oxidized/lang/en_us.json +++ b/src/main/resources/assets/oxidized/lang/en_us.json @@ -1,4 +1,6 @@ { + "gui.recipebook.toggleRecipes.kilnable": "Kilnable", + "item.oxidized.copper_pulsar": "Copper Pulsar", "item.oxidized.rose_gold_axe": "Rose Gold Axe", "item.oxidized.rose_gold_pickaxe": "Rose Gold Pickaxe", diff --git a/src/main/resources/data/oxidized/tags/item/rose_gold_tool_materials.json b/src/main/resources/data/oxidized/tags/item/rose_gold_tool_materials.json new file mode 100644 index 0000000..4b0daa0 --- /dev/null +++ b/src/main/resources/data/oxidized/tags/item/rose_gold_tool_materials.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "minecraft:copper_ingot" + ] +} \ No newline at end of file