Skip to content

Commit

Permalink
Make LightOverlay & SpawnProofer faster (#4164)
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored Oct 24, 2023
1 parent 2491946 commit 686b3b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,11 @@ private void onTick(TickEvent.Pre event) {
for (Cross cross : crosses) crossPool.free(cross);
crosses.clear();

int spawnLightLevel = newMobSpawnLightLevel.get() ? 0 : 7;
BlockIterator.register(horizontalRange.get(), verticalRange.get(), (blockPos, blockState) -> {
switch (BlockUtils.isValidMobSpawn(blockPos, newMobSpawnLightLevel.get())) {
case Never:
break;
case Potential:
crosses.add(crossPool.get().set(blockPos, true));
break;
case Always:
crosses.add((crossPool.get().set(blockPos, false)));
break;
switch (BlockUtils.isValidMobSpawn(blockPos, blockState, spawnLightLevel)) {
case Potential -> crosses.add(crossPool.get().set(blockPos, true));
case Always -> crosses.add((crossPool.get().set(blockPos, false)));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ private void onTickPre(TickEvent.Pre event) {
// Find spawn locations
for (BlockPos.Mutable blockPos : spawns) spawnPool.free(blockPos);
spawns.clear();

int lightLevel = newMobSpawnLightLevel.get() ? 0 : 7;
BlockIterator.register(range.get(), range.get(), (blockPos, blockState) -> {
BlockUtils.MobSpawn spawn = BlockUtils.isValidMobSpawn(blockPos, newMobSpawnLightLevel.get());
BlockUtils.MobSpawn spawn = BlockUtils.isValidMobSpawn(blockPos, blockState, lightLevel);

if ((spawn == BlockUtils.MobSpawn.Always && (mode.get() == Mode.Always || mode.get() == Mode.Both)) ||
spawn == BlockUtils.MobSpawn.Potential && (mode.get() == Mode.Potential || mode.get() == Mode.Both)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,20 @@ public static boolean isClickable(Block block) {
}

public static MobSpawn isValidMobSpawn(BlockPos blockPos, boolean newMobSpawnLightLevel) {
int spawnLightLimit = newMobSpawnLightLevel ? 0 : 7;
if (!(mc.world.getBlockState(blockPos).getBlock() instanceof AirBlock) ||
mc.world.getBlockState(blockPos.down()).getBlock() == Blocks.BEDROCK) return MobSpawn.Never;
return isValidMobSpawn(blockPos, mc.world.getBlockState(blockPos), newMobSpawnLightLevel ? 0 : 7);
}

public static MobSpawn isValidMobSpawn(BlockPos blockPos, BlockState blockState, int spawnLightLimit) {
if (!(blockState.getBlock() instanceof AirBlock)) return MobSpawn.Never;

BlockPos down = blockPos.down();
BlockState downState = mc.world.getBlockState(down);
if (downState.getBlock() == Blocks.BEDROCK) return MobSpawn.Never;

if (!topSurface(mc.world.getBlockState(blockPos.down()))) {
if (mc.world.getBlockState(blockPos.down()).getCollisionShape(mc.world, blockPos.down()) != VoxelShapes.fullCube())
if (!topSurface(downState)) {
if (downState.getCollisionShape(mc.world, down) != VoxelShapes.fullCube())
return MobSpawn.Never;
if (mc.world.getBlockState(blockPos.down()).isTransparent(mc.world, blockPos.down())) return MobSpawn.Never;
if (downState.isTransparent(mc.world, down)) return MobSpawn.Never;
}

if (mc.world.getLightLevel(blockPos, 0) <= spawnLightLimit) return MobSpawn.Potential;
Expand Down

0 comments on commit 686b3b7

Please sign in to comment.