Alex's Caves

Alex's Caves

5M Downloads

Performance: Make melting-down nuclear furnaces find nearby nuclear sirens instead of vice-versa

ByThePowerOfScience opened this issue ยท 0 comments

commented

if (entity.nearestMeltdownFurnace == null || !entity.isTrackedFurnaceCritical()) {
entity.nearestMeltdownFurnace = null;
boolean flag = false;
if (entity.age % 20 == 0 && level instanceof ServerLevel) {
BlockPos pos = entity.getNearbyCriticalFurnaces((ServerLevel) level, 128).findAny().orElse(null);
if (pos != null && entity.nearestMeltdownFurnace == null) {
entity.nearestMeltdownFurnace = pos;
flag = true;
}
}
if (flag) {
level.sendBlockUpdated(entity.getBlockPos(), entity.getBlockState(), entity.getBlockState(), 2);
}
}

entity.getNearbyCriticalFurnaces((ServerLevel) level, 128).findAny() ends up being a fairly expensive process when run so frequently, with one nuclear siren on the server using roughly .38% of the total server time.

Since melting down happens less frequently than once per second, making the Siren a POI and having the Furnace find nearby Sirens to trigger would run the POI check less often.