Light update convergence

- Move light update logic for all instances to use LightUpdater
 - Begin refactor of LightUpdater to account for moving listeners
This commit is contained in:
Jozufozu 2021-08-29 14:40:47 -07:00
parent 68a4478b38
commit c9789169b3
3 changed files with 43 additions and 36 deletions

View file

@ -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<C extends Contraption> 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<C extends Contraption> implements ILigh
public GridAlignedBB getBounds() {
return bounds;
}
@Override
public Volume.Box getVolume() {
return new Volume.Box(getBounds());
}
}

View file

@ -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<OrientedData> 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) {

View file

@ -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() {