From 3f03434248626dac24d394b259132ff644dfbaa6 Mon Sep 17 00:00:00 2001 From: Voidsong Dragonfly Date: Wed, 24 Jul 2024 16:39:15 -0400 Subject: [PATCH] Increase average performance of floodlights (#6023) - Makes floodlight fakelights not ticky - Now only updated on place/remove and as necessary, are removed on floodlight break --- .../common/blocks/FakeLightBlock.java | 21 +++---------------- .../blocks/metal/FloodlightBlockEntity.java | 6 +++++- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/FakeLightBlock.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/FakeLightBlock.java index 14be09cf8b..744d613909 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/FakeLightBlock.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/FakeLightBlock.java @@ -62,7 +62,7 @@ public boolean isPathfindable(BlockState state, BlockGetter worldIn, BlockPos po return true; } - public static class FakeLightBlockEntity extends IEBaseBlockEntity implements IEServerTickableBE, ISpawnInterdiction + public static class FakeLightBlockEntity extends IEBaseBlockEntity implements ISpawnInterdiction { public BlockPos floodlightCoords = null; @@ -71,23 +71,6 @@ public FakeLightBlockEntity(BlockPos pos, BlockState state) super(IEBlockEntities.FAKE_LIGHT.get(), pos, state); } - @Override - public void tickServer() - { - if(floodlightCoords==null) - { - level.removeBlock(getBlockPos(), false); - return; - } - if(level.getGameTime()%256==((getBlockPos().getX()^getBlockPos().getZ())&255)) - { - BlockEntity tile = Utils.getExistingTileEntity(level, floodlightCoords); - if(!(tile instanceof FloodlightBlockEntity)||!((FloodlightBlockEntity)tile).getIsActive()) - level.removeBlock(getBlockPos(), false); - } - - } - @Override public double getInterdictionRangeSquared() { @@ -112,6 +95,8 @@ public void onChunkUnloaded() public void onLoad() { super.onLoad(); + if(floodlightCoords==null||!(Utils.getExistingTileEntity(level, floodlightCoords) instanceof FloodlightBlockEntity floodlight)||!floodlight.getIsActive()) + level.removeBlock(getBlockPos(), false); SpawnInterdictionHandler.addInterdictionTile(this); } diff --git a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/FloodlightBlockEntity.java b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/FloodlightBlockEntity.java index a1df4638c4..287f05d7f3 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/FloodlightBlockEntity.java +++ b/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/FloodlightBlockEntity.java @@ -11,6 +11,7 @@ import blusunrize.immersiveengineering.api.IEProperties; import blusunrize.immersiveengineering.api.Lib; import blusunrize.immersiveengineering.api.utils.ComputerControlState; +import blusunrize.immersiveengineering.api.utils.SafeChunkUtils; import blusunrize.immersiveengineering.api.wires.ConnectionPoint; import blusunrize.immersiveengineering.api.wires.WireType; import blusunrize.immersiveengineering.api.wires.localhandlers.EnergyTransferHandler.EnergyConnector; @@ -245,7 +246,7 @@ public void placeLightAlongVector(Vec3 vec, int offset, ArrayList chec { Vec3 light = Vec3.atCenterOf(getBlockPos()).add(0, 0.25, 0); int range = 32; - HashSet ignore = new HashSet(); + HashSet ignore = new HashSet<>(); ignore.add(getBlockPos()); BlockPos hit = Utils.rayTraceForFirst(vec.add(light), light.add(vec.x*range, vec.y*range, vec.z*range), level, ignore); double maxDistance = hit!=null?Vec3.atCenterOf(hit).add(0, 0.25, 0).distanceToSqr(light): range*range; @@ -279,6 +280,9 @@ public double getInterdictionRangeSquared() public void setRemovedIE() { SpawnInterdictionHandler.removeFromInterdictionTiles(this); + for(BlockPos pos : fakeLights) + if(SafeChunkUtils.getSafeBE(level, pos) instanceof FakeLightBlockEntity light) + level.removeBlock(pos, false); super.setRemovedIE(); }