Skip to content

Commit

Permalink
Increase average performance of floodlights
Browse files Browse the repository at this point in the history
 - Makes floodlight fakelights not ticky
 - Now only updated on place/remove and as necessary, are removed on floodlight break
  • Loading branch information
voidsong-dragonfly committed Jul 16, 2024
1 parent cc8ef6d commit adfac8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
{
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,7 +246,7 @@ public void placeLightAlongVector(Vec3 vec, int offset, ArrayList<BlockPos> chec
{
Vec3 light = Vec3.atCenterOf(getBlockPos()).add(0, 0.25, 0);
int range = 32;
HashSet<BlockPos> ignore = new HashSet<BlockPos>();
HashSet<BlockPos> 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;
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit adfac8e

Please sign in to comment.