Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make steam venting decrement snow layers #2092

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 26 additions & 10 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,24 +705,40 @@ public static MapColor getMapColor(int rgb) {
return color;
}

public static boolean isBlockSnowLayer(@Nonnull IBlockState blockState) {
return blockState.getBlock() == Blocks.SNOW_LAYER && blockState.getValue(BlockSnow.LAYERS) == 1;
/**
* @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)) {
world.destroyBlock(pos, false);
if (playSound) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f);
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));
}
return true;
success = true;
}
return false;

if (success && playSound) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f);
}

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