testserver/Spigot-Server-Patches/0285-Prevent-Mob-AI-Rules-f...

84 lines
5.0 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 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/world/entity/ai/goal/PathfinderGoalRemoveBlock.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.java
index b5c7b39a49afae1089a293b9b06bdd94deed1f64..61a62c093b24c43064f116630d85096159e082d3 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.java
@@ -30,11 +30,13 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
2019-05-05 08:33:44 +00:00
private final Block g;
private final EntityInsentient entity;
2019-05-05 08:33:44 +00:00
private int i;
+ private World world; // Paper
public PathfinderGoalRemoveBlock(Block block, EntityCreature entitycreature, double d0, int i) {
super(entitycreature, d0, 24, i);
2019-05-05 08:33:44 +00:00
this.g = block;
this.entity = entitycreature;
+ this.world = entitycreature.world; // Paper
}
2019-05-05 08:33:44 +00:00
@Override
@@ -132,7 +134,9 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
@Nullable
private BlockPosition a(BlockPosition blockposition, IBlockAccess iblockaccess) {
2020-06-25 14:09:55 +00:00
- if (iblockaccess.getType(blockposition).a(this.g)) {
+ Block block = world.getBlockIfLoaded(blockposition); // Paper
+ if (block == null) return null; // Paper
2020-06-25 14:09:55 +00:00
+ if (block.a(this.g)) { // Paper
return blockposition;
} else {
2019-05-27 23:01:45 +00:00
BlockPosition[] ablockposition = new BlockPosition[]{blockposition.down(), blockposition.west(), blockposition.east(), blockposition.north(), blockposition.south(), blockposition.down().down()};
@@ -142,7 +146,7 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
for (int j = 0; j < i; ++j) {
BlockPosition blockposition1 = ablockposition1[j];
2020-06-25 14:09:55 +00:00
- if (iblockaccess.getType(blockposition1).a(this.g)) {
+ if (iblockaccess.getBlockIfLoaded(blockposition1).a(this.g)) { // Paper
return blockposition1;
}
}
@@ -153,7 +157,7 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
2019-05-05 08:33:44 +00:00
@Override
protected boolean a(IWorldReader iworldreader, BlockPosition blockposition) {
2019-07-20 04:01:24 +00:00
- IChunkAccess ichunkaccess = iworldreader.getChunkAt(blockposition.getX() >> 4, blockposition.getZ() >> 4, ChunkStatus.FULL, false);
+ IChunkAccess ichunkaccess = iworldreader.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4); // Paper
2020-06-25 14:09:55 +00:00
return ichunkaccess == null ? false : ichunkaccess.getType(blockposition).a(this.g) && ichunkaccess.getType(blockposition.up()).isAir() && ichunkaccess.getType(blockposition.up(2)).isAir();
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/util/RandomPositionGenerator.java b/src/main/java/net/minecraft/world/entity/ai/util/RandomPositionGenerator.java
2021-03-16 15:50:45 +00:00
index 129ea3857969ddb99e15ae817ee3eec67b4c3ccf..f9c40c8223109a9a40e7e7523c8f1f2e5aeddba1 100644
--- a/src/main/java/net/minecraft/world/entity/ai/util/RandomPositionGenerator.java
+++ b/src/main/java/net/minecraft/world/entity/ai/util/RandomPositionGenerator.java
2021-03-16 15:50:45 +00:00
@@ -13,6 +13,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.entity.EntityCreature;
import net.minecraft.world.entity.ai.navigation.NavigationAbstract;
import net.minecraft.world.level.IBlockAccess;
+import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.level.pathfinder.PathfinderNormal;
import net.minecraft.world.phys.Vec3D;
@@ -128,6 +129,7 @@ public class RandomPositionGenerator {
}
blockposition2 = new BlockPosition((double) k1 + entitycreature.locX(), (double) l1 + entitycreature.locY(), (double) i2 + entitycreature.locZ());
+ if (!entitycreature.world.isLoaded(blockposition2)) continue; // Paper
if (blockposition2.getY() >= 0 && blockposition2.getY() <= entitycreature.world.getBuildHeight() && (!flag3 || entitycreature.a(blockposition2)) && (!flag2 || navigationabstract.a(blockposition2))) {
if (flag1) {
blockposition2 = a(blockposition2, random.nextInt(l + 1) + i1, entitycreature.world.getBuildHeight(), (blockposition3) -> {
2021-03-16 15:50:45 +00:00
@@ -135,7 +137,8 @@ public class RandomPositionGenerator {
});
}
2020-06-25 14:09:55 +00:00
- if (flag || !entitycreature.world.getFluid(blockposition2).a((Tag) TagsFluid.WATER)) {
+ Fluid fluid = entitycreature.world.getFluidIfLoaded(blockposition2); // Paper
2020-06-25 14:09:55 +00:00
+ if (flag || (fluid != null && !fluid.a((Tag) TagsFluid.WATER))) { // Paper
PathType pathtype = PathfinderNormal.a((IBlockAccess) entitycreature.world, blockposition2.i());
if (entitycreature.a(pathtype) == 0.0F) {