From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 10 Sep 2018 23:56:36 -0400 Subject: [PATCH] Prevent Mob AI Rules from Loading Chunks diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java index 61afe72beb9f17a6c2b09d2aed9dd6aa4c36a816..0035461aff86fa3f44c860e7d77589b974446048 100644 --- a/src/main/java/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java +++ b/src/main/java/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java @@ -129,7 +129,9 @@ public class RemoveBlockGoal extends MoveToBlockGoal { @Nullable private BlockPos getPosWithBlock(BlockPos pos, BlockGetter world) { - if (world.getBlockState(pos).is(this.blockToRemove)) { + net.minecraft.world.level.block.state.BlockState block = world.getBlockStateIfLoaded(pos); // Paper + if (block == null) return null; // Paper + if (block.is(this.blockToRemove)) { // Paper return pos; } else { BlockPos[] ablockposition = new BlockPos[]{pos.below(), pos.west(), pos.east(), pos.north(), pos.south(), pos.below().below()}; @@ -139,7 +141,8 @@ public class RemoveBlockGoal extends MoveToBlockGoal { for (int j = 0; j < i; ++j) { BlockPos blockposition1 = ablockposition1[j]; - if (world.getBlockState(blockposition1).is(this.blockToRemove)) { + net.minecraft.world.level.block.state.BlockState block2 = world.getBlockStateIfLoaded(blockposition1); // Paper + if (block2 != null && block2.is(this.blockToRemove)) { // Paper return blockposition1; } } @@ -150,7 +153,7 @@ public class RemoveBlockGoal extends MoveToBlockGoal { @Override protected boolean isValidTarget(LevelReader world, BlockPos pos) { - ChunkAccess ichunkaccess = world.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()), ChunkStatus.FULL, false); + ChunkAccess ichunkaccess = world.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); // Paper return ichunkaccess == null ? false : ichunkaccess.getBlockState(pos).is(this.blockToRemove) && ichunkaccess.getBlockState(pos.above()).isAir() && ichunkaccess.getBlockState(pos.above(2)).isAir(); }