diff --git a/src/main/java/thedarkcolour/exdeorum/block/AbstractCrucibleBlock.java b/src/main/java/thedarkcolour/exdeorum/block/AbstractCrucibleBlock.java index f0247e76..3cdf38cd 100644 --- a/src/main/java/thedarkcolour/exdeorum/block/AbstractCrucibleBlock.java +++ b/src/main/java/thedarkcolour/exdeorum/block/AbstractCrucibleBlock.java @@ -45,11 +45,10 @@ public abstract class AbstractCrucibleBlock extends EBlock { @Override public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) { - // todo look at auxiliary light manager - //if (level.getBlockEntity(pos) instanceof AbstractCrucibleBlockEntity crucible) { - // return crucible.getTank().getFluid().getFluid().getFluidType().getLightLevel(); - //} - //return pos == BlockPos.ZERO ? 1 : 0; + var lightManager = level.getAuxLightManager(pos); + if (lightManager != null) { + return lightManager.getLightAt(pos); + } return 0; } diff --git a/src/main/java/thedarkcolour/exdeorum/block/BarrelBlock.java b/src/main/java/thedarkcolour/exdeorum/block/BarrelBlock.java index 90d59021..cda9b841 100644 --- a/src/main/java/thedarkcolour/exdeorum/block/BarrelBlock.java +++ b/src/main/java/thedarkcolour/exdeorum/block/BarrelBlock.java @@ -87,4 +87,13 @@ public class BarrelBlock extends EBlock { } } } + + @Override + public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) { + var lightManager = level.getAuxLightManager(pos); + if (lightManager != null) { + return lightManager.getLightAt(pos); + } + return 0; + } } diff --git a/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java b/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java index 94fe5a40..643d0aaa 100644 --- a/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java +++ b/src/main/java/thedarkcolour/exdeorum/blockentity/AbstractCrucibleBlockEntity.java @@ -75,7 +75,6 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { @Nullable private Fluid fluid = null; private short solids; - private boolean needsLightUpdate; public AbstractCrucibleBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -104,7 +103,18 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { this.lastMelted = BuiltInRegistries.BLOCK.get(new ResourceLocation(nbt.getString("LastMelted"))); this.fluid = BuiltInRegistries.FLUID.get(new ResourceLocation(nbt.getString("Fluid"))); this.solids = nbt.getShort("Solids"); - this.needsLightUpdate = true; + + updateLight(this.level, this.worldPosition, this.fluid); + } + + public static void updateLight(@Nullable Level level, BlockPos pos, Fluid fluid) { + if (level != null) { + var lightManager = level.getAuxLightManager(pos); + + if (lightManager != null) { + lightManager.setLightAt(pos, fluid.getFluidType().getLightLevel()); + } + } } @Override @@ -127,6 +137,9 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { var lastMelted = buffer.readById(BuiltInRegistries.BLOCK); this.lastMelted = lastMelted == Blocks.AIR ? null : lastMelted; this.solids = buffer.readShort(); + + // needed on client + updateLight(this.level, this.worldPosition, this.tank.getFluid().getFluid()); } @Override @@ -135,6 +148,8 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { this.tank.setFluid(from.tank.getFluid().copy()); this.lastMelted = from.lastMelted; this.solids = from.solids; + // needed on client + updateLight(this.level, this.worldPosition, this.tank.getFluid().getFluid()); } } @@ -187,7 +202,7 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { if (contained.isEmpty()) { this.fluid = result.getFluid(); - this.needsLightUpdate = true; + updateLight(this.level, this.worldPosition, this.fluid); } var melts = MELT_OVERRIDES.get(); @@ -312,10 +327,6 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { public static class Ticker implements BlockEntityTicker { @Override public void tick(Level level, BlockPos pos, BlockState state, AbstractCrucibleBlockEntity crucible) { - if (crucible.needsLightUpdate) { - level.getLightEngine().checkBlock(crucible.worldPosition); - crucible.needsLightUpdate = false; - } // Update twice per tick if (!level.isClientSide) { if ((level.getGameTime() % 10L) == 0L) { @@ -332,7 +343,7 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity { if (crucible.tank.isEmpty()) { if (crucible.fluid != null) { crucible.tank.setFluid(new FluidStack(crucible.fluid, delta)); - crucible.needsLightUpdate = true; + updateLight(level, pos, crucible.fluid); } } else { crucible.tank.getFluid().grow(delta); diff --git a/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java b/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java index 1abc0c33..9a1749e6 100644 --- a/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java +++ b/src/main/java/thedarkcolour/exdeorum/blockentity/BarrelBlockEntity.java @@ -42,6 +42,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FlowingFluid; +import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.common.NeoForgeMod; @@ -54,6 +55,7 @@ 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; @@ -112,6 +114,8 @@ public class BarrelBlockEntity extends EBlockEntity { this.r = nbt.getShort("r"); this.g = nbt.getShort("g"); this.b = nbt.getShort("b"); + + AbstractCrucibleBlockEntity.updateLight(this.level, this.worldPosition, this.tank.getFluid().getFluid()); } @Override @@ -639,6 +643,9 @@ public class BarrelBlockEntity extends EBlockEntity { // Inner class private class FluidHandler extends FluidHelper { + @Nullable + private Fluid lastFluid; + public FluidHandler() { super(1000); } @@ -655,6 +662,11 @@ public class BarrelBlockEntity extends EBlockEntity { BarrelBlockEntity.this.markUpdated(); } BarrelBlockEntity.this.updateFluidTransform(); + + if (this.lastFluid != this.fluid.getFluid()) { + this.lastFluid = this.fluid.getFluid(); + AbstractCrucibleBlockEntity.updateLight(BarrelBlockEntity.this.level, BarrelBlockEntity.this.worldPosition, this.lastFluid); + } } } } diff --git a/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateMessage.java b/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateMessage.java index ea3e44fb..e2ffeaa6 100644 --- a/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateMessage.java +++ b/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateMessage.java @@ -55,7 +55,7 @@ class VisualUpdateMessage implements CustomPacketPayload { public void write(FriendlyByteBuf buffer) { buffer.writeBlockPos(this.pos); buffer.writeId(BuiltInRegistries.BLOCK_ENTITY_TYPE, this.blockEntityType); - // write a placeholder value for the number of data bytes + // write a placeholder value for the number of data bytes, keeping its index for updating later var dataBytesIndex = buffer.writerIndex(); buffer.writeInt(0); // write data bytes