diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java index 7b130e908..51cfbbb89 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java @@ -1,9 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ILightUpdateListener; -import com.jozufozu.flywheel.light.LightUpdater; -import com.jozufozu.flywheel.light.LightVolume; +import com.jozufozu.flywheel.light.*; import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; import net.minecraft.world.IBlockDisplayReader; @@ -39,20 +36,19 @@ public abstract class ContraptionLighter implements ILigh public abstract GridAlignedBB getContraptionBounds(); - @Override - public boolean onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) { + @Override + public ListenerStatus status() { + return ListenerStatus.OKAY; + } + + @Override + public void onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) { lightVolume.notifyLightUpdate(world, type, changed); - return false; } @Override - public boolean onLightPacket(IBlockDisplayReader world, int chunkX, int chunkZ) { + public void onLightPacket(IBlockDisplayReader world, int chunkX, int chunkZ) { lightVolume.notifyLightPacket(world, chunkX, chunkZ); - return false; - } - - protected void startListening() { - LightUpdater.getInstance().startListening(bounds, this); } protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) { @@ -66,4 +62,9 @@ public abstract class ContraptionLighter implements ILigh public GridAlignedBB getBounds() { return bounds; } + + @Override + public Volume.Box getVolume() { + return new Volume.Box(getBounds()); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java index c1212282f..747123f19 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java @@ -10,8 +10,8 @@ import com.jozufozu.flywheel.core.instancing.GroupInstance; import com.jozufozu.flywheel.core.instancing.SelectInstance; import com.jozufozu.flywheel.core.materials.OrientedData; import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ILightUpdateListener; import com.jozufozu.flywheel.light.LightUpdater; +import com.jozufozu.flywheel.light.ListenerStatus; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; @@ -22,7 +22,7 @@ import net.minecraft.util.math.vector.Vector3f; import net.minecraft.world.IBlockDisplayReader; import net.minecraft.world.LightType; -public abstract class AbstractPulleyInstance extends ShaftInstance implements IDynamicInstance, ILightUpdateListener { +public abstract class AbstractPulleyInstance extends ShaftInstance implements IDynamicInstance { final OrientedData coil; final SelectInstance magnet; @@ -145,7 +145,7 @@ public abstract class AbstractPulleyInstance extends ShaftInstance implements ID initLight(world, volume); - LightUpdater.getInstance().startListening(volume, this); + needsUpdate = true; } } @@ -175,13 +175,17 @@ public abstract class AbstractPulleyInstance extends ShaftInstance implements ID return false; } + boolean needsUpdate; @Override - public boolean onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) { + public ListenerStatus status() { + return needsUpdate ? ListenerStatus.UPDATE : super.status(); + } + + @Override + public void onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) { changed.intersectAssign(volume); initLight(world, changed); - - return false; } private void initLight(IBlockDisplayReader world, GridAlignedBB changed) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 30ac4da87..8a70a7160 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -16,6 +16,8 @@ import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.light.GridAlignedBB; import com.jozufozu.flywheel.light.ILightUpdateListener; import com.jozufozu.flywheel.light.LightUpdater; +import com.jozufozu.flywheel.light.ListenerStatus; +import com.jozufozu.flywheel.light.Volume; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; @@ -118,7 +120,7 @@ public class BeltTileEntity extends KineticTileEntity implements ILightUpdateLis if (light == null && level.isClientSide) { initializeLight(); LightUpdater.getInstance() - .startListening(getBeltVolume(), this); + .addListener(this); } getInventory().tick(); @@ -526,30 +528,30 @@ public class BeltTileEntity extends KineticTileEntity implements ILightUpdateLis } @Override - public boolean onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) { - if (this.remove) { - return true; - } + public Volume.Box getVolume() { + BlockPos endPos = BeltHelper.getPositionForOffset(this, beltLength - 1); - GridAlignedBB beltVolume = getBeltVolume(); + GridAlignedBB bb = GridAlignedBB.from(worldPosition, endPos); + bb.fixMinMax(); + return new Volume.Box(bb); + } - if (beltVolume.intersects(changed)) { + @Override + public ListenerStatus status() { + return remove ? ListenerStatus.REMOVE : ListenerStatus.OKAY; + } + + @Override + public void onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) { + Volume.Box beltVolume = getVolume(); + + if (beltVolume.box.intersects(changed)) { if (type == LightType.BLOCK) updateBlockLight(); if (type == LightType.SKY) updateSkyLight(); } - - return false; - } - - private GridAlignedBB getBeltVolume() { - BlockPos endPos = BeltHelper.getPositionForOffset(this, beltLength - 1); - - GridAlignedBB bb = GridAlignedBB.from(worldPosition, endPos); - bb.fixMinMax(); - return bb; } private void initializeLight() {