mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 01:12:47 +01:00
99 lines
4.8 KiB
Diff
99 lines
4.8 KiB
Diff
From f29dcfd87c3bff303269693956d68e7e3cb8197d Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
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/server/PathfinderGoalRemoveBlock.java b/src/main/java/net/minecraft/server/PathfinderGoalRemoveBlock.java
|
|
index ce9318c575..541d97344e 100644
|
|
--- a/src/main/java/net/minecraft/server/PathfinderGoalRemoveBlock.java
|
|
+++ b/src/main/java/net/minecraft/server/PathfinderGoalRemoveBlock.java
|
|
@@ -12,11 +12,13 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
|
|
private final Block g;
|
|
private final EntityInsentient entity;
|
|
private int i;
|
|
+ private World world; // Paper
|
|
|
|
public PathfinderGoalRemoveBlock(Block block, EntityCreature entitycreature, double d0, int i) {
|
|
super(entitycreature, d0, 24, i);
|
|
this.g = block;
|
|
this.entity = entitycreature;
|
|
+ this.world = entitycreature.world; // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -114,7 +116,9 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
|
|
|
|
@Nullable
|
|
private BlockPosition a(BlockPosition blockposition, IBlockAccess iblockaccess) {
|
|
- if (iblockaccess.getType(blockposition).getBlock() == this.g) {
|
|
+ Block block = world.getBlockIfLoaded(blockposition); // Paper
|
|
+ if (block == null) return null; // Paper
|
|
+ if (block == this.g) { // Paper
|
|
return blockposition;
|
|
} else {
|
|
BlockPosition[] ablockposition = new BlockPosition[] { blockposition.down(), blockposition.west(), blockposition.east(), blockposition.north(), blockposition.south(), blockposition.down().down()};
|
|
@@ -124,7 +128,7 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
|
|
for (int j = 0; j < i; ++j) {
|
|
BlockPosition blockposition1 = ablockposition1[j];
|
|
|
|
- if (iblockaccess.getType(blockposition1).getBlock() == this.g) {
|
|
+ if (world.getBlockIfLoaded(blockposition1) == this.g) { // Paper
|
|
return blockposition1;
|
|
}
|
|
}
|
|
@@ -135,7 +139,8 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
|
|
|
|
@Override
|
|
protected boolean a(IWorldReader iworldreader, BlockPosition blockposition) {
|
|
- Block block = iworldreader.getType(blockposition).getBlock();
|
|
+ Block block = world.getBlockIfLoaded(blockposition); // Paper
|
|
+ if (block == null) return false; // Paper
|
|
|
|
return block == this.g && iworldreader.getType(blockposition.up()).isAir() && iworldreader.getType(blockposition.up(2)).isAir();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/RandomPositionGenerator.java b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
|
index 8340d6d25b..78eb1b39cf 100644
|
|
--- a/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
|
+++ b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
|
@@ -93,6 +93,7 @@ public class RandomPositionGenerator {
|
|
}
|
|
|
|
blockposition1 = new BlockPosition((double) k1 + entitycreature.locX, (double) l1 + entitycreature.locY, (double) i2 + entitycreature.locZ);
|
|
+ if (!entitycreature.world.isLoaded(blockposition1)) continue; // Paper
|
|
if ((!flag1 || entitycreature.a(blockposition1)) && navigationabstract.a(blockposition1)) {
|
|
if (!flag) {
|
|
blockposition1 = a(blockposition1, entitycreature);
|
|
@@ -161,6 +162,7 @@ public class RandomPositionGenerator {
|
|
}
|
|
|
|
private static boolean b(BlockPosition blockposition, EntityCreature entitycreature) {
|
|
- return entitycreature.world.getFluid(blockposition).a(TagsFluid.WATER);
|
|
+ Fluid fluid = entitycreature.world.getFluidIfLoaded(blockposition); // Paper
|
|
+ return fluid != null && fluid.a(TagsFluid.WATER); // Paper
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index 5544c4dbf3..39d5a8f5e5 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -646,6 +646,16 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
return chunk.getType(blockposition);
|
|
}
|
|
}
|
|
+ // Paper start
|
|
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
|
|
+ if (blockposition.isInvalidYLocation()) { // Paper
|
|
+ return getFluid(blockposition);
|
|
+ } else {
|
|
+ Chunk chunk = this.getChunkIfLoaded(blockposition);
|
|
+ return chunk != null ? chunk.getFluid(blockposition) : null;
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public Fluid getFluid(BlockPosition blockposition) {
|
|
--
|
|
2.21.0
|
|
|