mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 18:33:41 +01:00
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:
parent
68a4478b38
commit
c9789169b3
3 changed files with 43 additions and 36 deletions
|
@ -1,9 +1,6 @@
|
||||||
package com.simibubi.create.content.contraptions.components.structureMovement;
|
package com.simibubi.create.content.contraptions.components.structureMovement;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.light.GridAlignedBB;
|
import com.jozufozu.flywheel.light.*;
|
||||||
import com.jozufozu.flywheel.light.ILightUpdateListener;
|
|
||||||
import com.jozufozu.flywheel.light.LightUpdater;
|
|
||||||
import com.jozufozu.flywheel.light.LightVolume;
|
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption;
|
import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption;
|
||||||
|
|
||||||
import net.minecraft.world.IBlockDisplayReader;
|
import net.minecraft.world.IBlockDisplayReader;
|
||||||
|
@ -40,19 +37,18 @@ public abstract class ContraptionLighter<C extends Contraption> implements ILigh
|
||||||
public abstract GridAlignedBB getContraptionBounds();
|
public abstract GridAlignedBB getContraptionBounds();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) {
|
public ListenerStatus status() {
|
||||||
lightVolume.notifyLightUpdate(world, type, changed);
|
return ListenerStatus.OKAY;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLightPacket(IBlockDisplayReader world, int chunkX, int chunkZ) {
|
public void onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) {
|
||||||
lightVolume.notifyLightPacket(world, chunkX, chunkZ);
|
lightVolume.notifyLightUpdate(world, type, changed);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startListening() {
|
@Override
|
||||||
LightUpdater.getInstance().startListening(bounds, this);
|
public void onLightPacket(IBlockDisplayReader world, int chunkX, int chunkZ) {
|
||||||
|
lightVolume.notifyLightPacket(world, chunkX, chunkZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) {
|
protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) {
|
||||||
|
@ -66,4 +62,9 @@ public abstract class ContraptionLighter<C extends Contraption> implements ILigh
|
||||||
public GridAlignedBB getBounds() {
|
public GridAlignedBB getBounds() {
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Volume.Box getVolume() {
|
||||||
|
return new Volume.Box(getBounds());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import com.jozufozu.flywheel.core.instancing.GroupInstance;
|
||||||
import com.jozufozu.flywheel.core.instancing.SelectInstance;
|
import com.jozufozu.flywheel.core.instancing.SelectInstance;
|
||||||
import com.jozufozu.flywheel.core.materials.OrientedData;
|
import com.jozufozu.flywheel.core.materials.OrientedData;
|
||||||
import com.jozufozu.flywheel.light.GridAlignedBB;
|
import com.jozufozu.flywheel.light.GridAlignedBB;
|
||||||
import com.jozufozu.flywheel.light.ILightUpdateListener;
|
|
||||||
import com.jozufozu.flywheel.light.LightUpdater;
|
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.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance;
|
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.IBlockDisplayReader;
|
||||||
import net.minecraft.world.LightType;
|
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 OrientedData coil;
|
||||||
final SelectInstance<OrientedData> magnet;
|
final SelectInstance<OrientedData> magnet;
|
||||||
|
@ -145,7 +145,7 @@ public abstract class AbstractPulleyInstance extends ShaftInstance implements ID
|
||||||
|
|
||||||
initLight(world, volume);
|
initLight(world, volume);
|
||||||
|
|
||||||
LightUpdater.getInstance().startListening(volume, this);
|
needsUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,13 +175,17 @@ public abstract class AbstractPulleyInstance extends ShaftInstance implements ID
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean needsUpdate;
|
||||||
@Override
|
@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);
|
changed.intersectAssign(volume);
|
||||||
|
|
||||||
initLight(world, changed);
|
initLight(world, changed);
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLight(IBlockDisplayReader world, GridAlignedBB changed) {
|
private void initLight(IBlockDisplayReader world, GridAlignedBB changed) {
|
||||||
|
|
|
@ -16,6 +16,8 @@ import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||||
import com.jozufozu.flywheel.light.GridAlignedBB;
|
import com.jozufozu.flywheel.light.GridAlignedBB;
|
||||||
import com.jozufozu.flywheel.light.ILightUpdateListener;
|
import com.jozufozu.flywheel.light.ILightUpdateListener;
|
||||||
import com.jozufozu.flywheel.light.LightUpdater;
|
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.AllBlocks;
|
||||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
|
@ -118,7 +120,7 @@ public class BeltTileEntity extends KineticTileEntity implements ILightUpdateLis
|
||||||
if (light == null && level.isClientSide) {
|
if (light == null && level.isClientSide) {
|
||||||
initializeLight();
|
initializeLight();
|
||||||
LightUpdater.getInstance()
|
LightUpdater.getInstance()
|
||||||
.startListening(getBeltVolume(), this);
|
.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getInventory().tick();
|
getInventory().tick();
|
||||||
|
@ -526,30 +528,30 @@ public class BeltTileEntity extends KineticTileEntity implements ILightUpdateLis
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) {
|
public Volume.Box getVolume() {
|
||||||
if (this.remove) {
|
BlockPos endPos = BeltHelper.getPositionForOffset(this, beltLength - 1);
|
||||||
return true;
|
|
||||||
|
GridAlignedBB bb = GridAlignedBB.from(worldPosition, endPos);
|
||||||
|
bb.fixMinMax();
|
||||||
|
return new Volume.Box(bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
GridAlignedBB beltVolume = getBeltVolume();
|
@Override
|
||||||
|
public ListenerStatus status() {
|
||||||
|
return remove ? ListenerStatus.REMOVE : ListenerStatus.OKAY;
|
||||||
|
}
|
||||||
|
|
||||||
if (beltVolume.intersects(changed)) {
|
@Override
|
||||||
|
public void onLightUpdate(IBlockDisplayReader world, LightType type, GridAlignedBB changed) {
|
||||||
|
Volume.Box beltVolume = getVolume();
|
||||||
|
|
||||||
|
if (beltVolume.box.intersects(changed)) {
|
||||||
if (type == LightType.BLOCK)
|
if (type == LightType.BLOCK)
|
||||||
updateBlockLight();
|
updateBlockLight();
|
||||||
|
|
||||||
if (type == LightType.SKY)
|
if (type == LightType.SKY)
|
||||||
updateSkyLight();
|
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() {
|
private void initializeLight() {
|
||||||
|
|
Loading…
Reference in a new issue