Skip to content

Commit

Permalink
support snow blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 committed Oct 8, 2023
1 parent 9a73a8b commit 3ac644a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3ac644a

Please sign in to comment.