diff --git a/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java b/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java index 643d0aaa..5cd812e9 100644 --- a/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java +++ b/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java @@ -65,7 +65,8 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { return map; }); - public static final int MAX_SOLIDS = 1_000; + public static final int MAX_SOLIDS = 1000; + public static final int MAX_FLUID_CAPACITY = 4000; private final AbstractCrucibleBlockEntity.ItemHandler item = new AbstractCrucibleBlockEntity.ItemHandler(); private final AbstractCrucibleBlockEntity.FluidHandler tank = new AbstractCrucibleBlockEntity.FluidHandler(); @@ -292,7 +293,7 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { private static class FluidHandler extends FluidHelper { public FluidHandler() { - super(4_000); + super(MAX_FLUID_CAPACITY); } @Override @@ -329,32 +330,34 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { public void tick(Level level, BlockPos pos, BlockState state, AbstractCrucibleBlockEntity crucible) { // Update twice per tick if (!level.isClientSide) { + var tank = crucible.tank; + if ((level.getGameTime() % 10L) == 0L) { short delta = (short) Math.min(crucible.solids, crucible.getMeltingRate()); // Skip if no heat if (delta <= 0) return; - if (crucible.tank.getSpace() >= delta) { + if (tank.getSpace() >= delta) { // Remove solids crucible.solids -= delta; // Add lava - if (crucible.tank.isEmpty()) { + if (tank.isEmpty()) { if (crucible.fluid != null) { - crucible.tank.setFluid(new FluidStack(crucible.fluid, delta)); + tank.setFluid(new FluidStack(crucible.fluid, delta)); updateLight(level, pos, crucible.fluid); } } else { - crucible.tank.getFluid().grow(delta); + tank.getFluid().grow(delta); } // Sync to client crucible.markUpdated(); } } - if (crucible instanceof WaterCrucibleBlockEntity && level.isRainingAt(pos.above())) { - BarrelBlockEntity.fillRainWater(crucible, crucible.tank); + if (tank.getFluidAmount() < MAX_FLUID_CAPACITY && crucible instanceof WaterCrucibleBlockEntity && level.isRainingAt(pos.above())) { + BarrelBlockEntity.fillRainWater(crucible, tank); } } } diff --git a/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java b/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java index 8d3c9399..3ae6b2a6 100644 --- a/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java +++ b/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java @@ -55,7 +55,6 @@ import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.ItemHandlerHelper; import net.neoforged.neoforge.items.ItemStackHandler; import org.jetbrains.annotations.Nullable; -import thedarkcolour.exdeorum.block.AbstractCrucibleBlock; import thedarkcolour.exdeorum.block.BarrelBlock; import thedarkcolour.exdeorum.blockentity.helper.FluidHelper; import thedarkcolour.exdeorum.client.CompostColors; @@ -65,10 +64,10 @@ import thedarkcolour.exdeorum.recipe.RecipeUtil; import thedarkcolour.exdeorum.recipe.barrel.BarrelFluidMixingRecipe; import thedarkcolour.exdeorum.recipe.barrel.FluidTransformationRecipe; import thedarkcolour.exdeorum.registry.EBlockEntities; -import thedarkcolour.exdeorum.registry.EFluids; public class BarrelBlockEntity extends EBlockEntity { private static final int MOSS_SPREAD_RANGE = 2; + private static final int MAX_CAPACITY = 1000; private final BarrelBlockEntity.ItemHandler item = new BarrelBlockEntity.ItemHandler(); private final BarrelBlockEntity.FluidHandler tank = new BarrelBlockEntity.FluidHandler(); @@ -154,7 +153,7 @@ public class BarrelBlockEntity extends EBlockEntity { } public boolean isBrewing() { - return this.tank.getFluidAmount() == 1000 && this.progress != 0.0f && !isBurning(); + return this.tank.getFluidAmount() == MAX_CAPACITY && this.progress != 0.0f && !isBurning(); } public boolean isBurning() { @@ -163,7 +162,7 @@ public class BarrelBlockEntity extends EBlockEntity { // Composting is in progress if at 1000. When finished, compost is set back to 0 public boolean isComposting() { - return this.compost == 1000; + return this.compost == MAX_CAPACITY; } // Returns true if there are no solid ingredients (can a fluid be inserted?) @@ -173,7 +172,7 @@ public class BarrelBlockEntity extends EBlockEntity { @SuppressWarnings("deprecation") public boolean hasFullWater() { - return this.tank.getFluidAmount() == 1000 && this.tank.getFluid().getFluid().is(FluidTags.WATER); + return this.tank.getFluidAmount() == MAX_CAPACITY && this.tank.getFluid().getFluid().is(FluidTags.WATER); } // Burning temp of wood according to google is 300 C or ~575 kelvin @@ -398,7 +397,7 @@ public class BarrelBlockEntity extends EBlockEntity { private void addCompost(ItemStack playerItem, int volume) { int oldCompost = this.compost; - this.compost = (short) Math.min(1000, this.compost + volume); + this.compost = (short) Math.min(MAX_CAPACITY, this.compost + volume); if (this.compost != 0) { if (!CompostColors.isLoaded()) { @@ -455,10 +454,10 @@ public class BarrelBlockEntity extends EBlockEntity { public void updateFluidTransform() { if (!this.level.isClientSide) { - var belowState = this.level.getBlockState(this.worldPosition.below()); - if (this.tank.getFluidAmount() != 1000) { + if (this.tank.getFluidAmount() != MAX_CAPACITY) { this.currentTransformRecipe = null; } else { + var belowState = this.level.getBlockState(this.worldPosition.below()); this.currentTransformRecipe = RecipeUtil.getFluidTransformationRecipe(this.tank.getFluid().getFluid(), belowState); if (this.currentTransformRecipe != null) { @@ -481,21 +480,20 @@ public class BarrelBlockEntity extends EBlockEntity { @Override public void tick(Level level, BlockPos pos, BlockState state, BarrelBlockEntity barrel) { if (!level.isClientSide) { + var tank = barrel.tank; // Turn compost to dirt if (barrel.isComposting()) { barrel.doCompost(); - } else if (isHotFluid(barrel.tank.getFluid().getFluid().getFluidType()) && state.ignitedByLava()) { + } else if (isHotFluid(tank.getFluid().getFluid().getFluidType()) && state.ignitedByLava()) { if ((barrel.progress += getProgressStep()) >= 1.0f) { - if (barrel.tank.getFluidAmount() == 1000) { - var fluid = barrel.tank.getFluid().getFluid(); + if (tank.getFluidAmount() == MAX_CAPACITY) { + var fluid = tank.getFluid().getFluid(); level.setBlockAndUpdate(pos, fluid.getFluidType().getBlockForFluidState(level, pos, fluid.defaultFluidState())); } else { level.setBlockAndUpdate(pos, Blocks.FIRE.defaultBlockState()); } } barrel.markUpdated(); - } else if (level.isRainingAt(pos.above()) && barrel.item.getStackInSlot(0).isEmpty() && barrel.compost == 0) { - fillRainWater(barrel, barrel.tank); } else if (barrel.currentTransformRecipe != null) { var recipe = barrel.currentTransformRecipe; var catalysts = 0; @@ -530,13 +528,20 @@ public class BarrelBlockEntity extends EBlockEntity { // Reset progress barrel.progress = 0.0f; level.playSound(null, pos, SoundEvents.BREWING_STAND_BREW, SoundSource.BLOCKS, 1.0f, 0.6f); - barrel.tank.setFluid(FluidStack.EMPTY); - barrel.tank.fill(new FluidStack(recipe.resultFluid(), 1000), IFluidHandler.FluidAction.EXECUTE); + tank.setFluid(FluidStack.EMPTY); + tank.fill(new FluidStack(recipe.resultFluid(), 1000), IFluidHandler.FluidAction.EXECUTE); } barrel.markUpdated(); } + } else if (tank.getFluidAmount() < MAX_CAPACITY && level.isRainingAt(pos.above()) && barrel.item.getStackInSlot(0).isEmpty() && barrel.compost == 0) { + fillRainWater(barrel, tank); + + // avoid checking fluid transform until full + if (tank.getFluidAmount() == MAX_CAPACITY) { + barrel.updateFluidTransform(); + } } else if (barrel.hasFullWater()) { - if (barrel.tank.getFluid().getFluid().getFluidType() == NeoForgeMod.WATER_TYPE.value()) { + if (tank.getFluid().getFluid().getFluidType() == NeoForgeMod.WATER_TYPE.value()) { var rand = level.random; // Leak water to create moss (only wooden barrels do this) if (state.ignitedByLava() && rand.nextInt(500) == 0) { @@ -561,7 +566,7 @@ public class BarrelBlockEntity extends EBlockEntity { if (tank.isEmpty()) { tank.setFluid(new FluidStack(Fluids.WATER, 1)); block.markUpdated(); - } else if (tank.getFluid().getFluid() == Fluids.WATER && tank.getFluidAmount() < tank.getCapacity()) { + } else if (tank.getFluid().getFluid() == Fluids.WATER) { tank.getFluid().grow(1); block.markUpdated(); } @@ -648,7 +653,7 @@ public class BarrelBlockEntity extends EBlockEntity { private Fluid lastFluid; public FluidHandler() { - super(1000); + super(MAX_CAPACITY); } @Override