From 3ac644ab2af8d35d0502f65e4885ad56ab28c553 Mon Sep 17 00:00:00 2001 From: TechLord22 <37029404+techlord22@users.noreply.github.com> Date: Sun, 8 Oct 2023 18:08:12 -0400 Subject: [PATCH] support snow blocks --- .../api/capability/impl/RecipeLogicSteam.java | 2 +- .../java/gregtech/api/util/GTUtility.java | 32 ++++++++++++------- .../MetaTileEntityPrimitiveBlastFurnace.java | 6 ++-- .../MetaTileEntityMufflerHatch.java | 4 +-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java index 32738279f6f..fec0e6cb6ca 100644 --- a/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java +++ b/src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java @@ -130,7 +130,7 @@ public void tryDoVenting() { IBlockState blockOnPos = metaTileEntity.getWorld().getBlockState(ventingBlockPos); if (blockOnPos.getCollisionBoundingBox(metaTileEntity.getWorld(), ventingBlockPos) == Block.NULL_AABB) { performVentingAnimation(ventingBlockPos, machinePos); - } else if (GTUtility.tryBreakSnowLayer(metaTileEntity.getWorld(), ventingBlockPos, blockOnPos, false)) { + } else if (GTUtility.tryBreakSnow(metaTileEntity.getWorld(), ventingBlockPos, blockOnPos, false)) { performVentingAnimation(ventingBlockPos, machinePos); } else if (!ventingStuck) { setVentingStuck(true); diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 7c278fa2494..cb9a26e030e 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -703,30 +703,40 @@ public static MapColor getMapColor(int rgb) { return color; } - public static boolean isBlockSnowLayer(@Nonnull IBlockState blockState) { - return blockState.getBlock() == Blocks.SNOW_LAYER; + /** + * @param blockState the blockstate to check + * @return if the block is a snow layer or snow block + */ + public static boolean isBlockSnow(@Nonnull IBlockState blockState) { + return blockState.getBlock() == Blocks.SNOW_LAYER || blockState.getBlock() == Blocks.SNOW; } /** * Attempt to break a (single) snow layer at the given BlockPos. + * Will also turn snow blocks into snow layers at height 7. * - * @return true if the passed IBlockState was a snow layer + * @return true if the passed IBlockState was valid snow block */ - public static boolean tryBreakSnowLayer(World world, BlockPos pos, @Nonnull IBlockState blockState, boolean playSound) { - if (isBlockSnowLayer(blockState)) { - int layers = blockState.getValue(BlockSnow.LAYERS); + public static boolean tryBreakSnow(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, boolean playSound) { + boolean success = false; + if (state.getBlock() == Blocks.SNOW) { + world.setBlockState(pos, Blocks.SNOW_LAYER.getDefaultState().withProperty(BlockSnow.LAYERS, 7)); + success = true; + } else if (state.getBlock() == Blocks.SNOW_LAYER) { + int layers = state.getValue(BlockSnow.LAYERS); if (layers == 1) { world.destroyBlock(pos, false); } else { world.setBlockState(pos, Blocks.SNOW_LAYER.getDefaultState().withProperty(BlockSnow.LAYERS, layers - 1)); } + success = true; + } - if (playSound) { - world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f); - } - return true; + if (success && playSound) { + world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f); } - return false; + + return success; } /** diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPrimitiveBlastFurnace.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPrimitiveBlastFurnace.java index f0c87c31aac..2e257ba8c9f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPrimitiveBlastFurnace.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPrimitiveBlastFurnace.java @@ -45,7 +45,7 @@ public class MetaTileEntityPrimitiveBlastFurnace extends RecipeMapPrimitiveMultiblockController { - private static final TraceabilityPredicate IS_SNOW_LAYER = new TraceabilityPredicate(bws -> GTUtility.isBlockSnowLayer(bws.getBlockState())); + private static final TraceabilityPredicate SNOW_PREDICATE = new TraceabilityPredicate(bws -> GTUtility.isBlockSnow(bws.getBlockState())); public MetaTileEntityPrimitiveBlastFurnace(ResourceLocation metaTileEntityId) { super(metaTileEntityId, RecipeMaps.PRIMITIVE_BLAST_FURNACE_RECIPES); @@ -64,7 +64,7 @@ protected BlockPattern createStructurePattern() { .aisle("XXX", "XYX", "XXX", "XXX") .where('X', states(MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.PRIMITIVE_BRICKS))) .where('#', air()) - .where('&', air().or(IS_SNOW_LAYER)) // this won't stay in the structure, and will be broken while running + .where('&', air().or(SNOW_PREDICATE)) // this won't stay in the structure, and will be broken while running .where('Y', selfPredicate()) .build(); } @@ -155,7 +155,7 @@ private void damageEntitiesAndBreakSnow() { if (getOffsetTimer() % 10 == 0) { IBlockState state = getWorld().getBlockState(middlePos); - GTUtility.tryBreakSnowLayer(getWorld(), middlePos, state, true); + GTUtility.tryBreakSnow(getWorld(), middlePos, state, true); } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java index f1204541681..2d7b2a90963 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java @@ -100,12 +100,12 @@ private boolean checkFrontFaceFree() { // break a snow layer if it exists, and if this machine is running if (controller != null && controller.isActive()) { - if (GTUtility.tryBreakSnowLayer(getWorld(), frontPos, blockState, true)) { + if (GTUtility.tryBreakSnow(getWorld(), frontPos, blockState, true)) { return true; } return blockState.getBlock().isAir(blockState, getWorld(), frontPos); } - return blockState.getBlock().isAir(blockState, getWorld(), frontPos) || GTUtility.isBlockSnowLayer(blockState); + return blockState.getBlock().isAir(blockState, getWorld(), frontPos) || GTUtility.isBlockSnow(blockState); } @SideOnly(Side.CLIENT)