Paper/Spigot-Server-Patches/0363-Prevent-Mob-AI-Rules-from-Loading-Chunks.patch
Aikar 2a2d9fb508
Improvements to Logging Warnings/Dupe Entities - Resolves #1544
1) Removed "Regen" mode of Dupe UUID resolver, forced safe.
Some servers who updated before we had safe mode added still had this value.

There's really no reason to keep this mode, as we've seen that vanilla
triggers this often and 99.9999999% of cases will be an actual duplicate
that needs to be deleted.

2) Made Vanilla Debug messages about dupe UUIDs and dupe uuid resolve messages
only show up if the debug.entities flag is on. This will stop server owners
from panicing from seeing these logs, and stop opening bug reports on this,
only for us to tell you "don't worry about it".

3) Avoid adding entities to world that are already added to world.

This can be triggered by anything that causes an entity to be added
to the world during the chunk load process, such as chunk conversions.

Issue #1544 was a case of this.

4) Removed debug warning about ExpiringMap.

Nothing more I know to do about this anyways. We recover from it,
stop warning to reduce noise of issues to us.
2018-10-07 15:10:23 -04:00

112 lines
5.3 KiB
Diff

From 3d09204659809325eb40edd7532c90cc9bd8328e 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/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index b8d87beae6..300c54c806 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -481,6 +481,7 @@ public class Chunk implements IChunkAccess {
}
}
+ public Fluid getFluid(BlockPosition blockposition) { return b(blockposition); } // Paper - OBFHELPER
public Fluid b(BlockPosition blockposition) {
return this.b(blockposition.getX(), blockposition.getY(), blockposition.getZ());
}
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalRemoveBlock.java b/src/main/java/net/minecraft/server/PathfinderGoalRemoveBlock.java
index b1661693cf..2cbb6c8f91 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalRemoveBlock.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoalRemoveBlock.java
@@ -7,11 +7,13 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
private final Block f;
private final EntityInsentient g;
private int h;
+ private World world; // Paper
public PathfinderGoalRemoveBlock(Block block, EntityCreature entitycreature, double d0, int i) {
super(entitycreature, d0, 24, i);
this.f = block;
this.g = entitycreature;
+ this.world = entitycreature.world; // Paper
}
public boolean a() {
@@ -89,13 +91,15 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
@Nullable
private BlockPosition a(BlockPosition blockposition, IBlockAccess iblockaccess) {
- if (iblockaccess.getType(blockposition).getBlock() == this.f) {
+ Block block = world.getBlockIfLoaded(blockposition); // Paper
+ if (block == null) return null; // Paper
+ if (block == this.f) { // Paper
return blockposition;
} else {
BlockPosition[] ablockposition = new BlockPosition[]{blockposition.down(), blockposition.west(), blockposition.east(), blockposition.north(), blockposition.south(), blockposition.down().down()};
for(BlockPosition blockposition1 : ablockposition) {
- if (iblockaccess.getType(blockposition1).getBlock() == this.f) {
+ if (world.getBlockIfLoaded(blockposition1) == this.f) { // Paper
return blockposition1;
}
}
@@ -105,7 +109,8 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
}
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.f && 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 800e0046a8..bfa6c2eef8 100644
--- a/src/main/java/net/minecraft/server/RandomPositionGenerator.java
+++ b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
@@ -78,6 +78,7 @@ public class RandomPositionGenerator {
}
BlockPosition blockposition2 = new BlockPosition((double)j1 + entitycreature.locX, (double)k1 + entitycreature.locY, (double)l1 + entitycreature.locZ);
+ if (!entitycreature.world.isLoaded(blockposition2)) continue; // Paper
if ((!flag1 || entitycreature.f(blockposition2)) && navigationabstract.a(blockposition2)) {
if (!flag) {
blockposition2 = a(blockposition2, entitycreature);
@@ -141,6 +142,7 @@ public class RandomPositionGenerator {
}
private static boolean b(BlockPosition blockposition, EntityCreature entitycreature) {
- return entitycreature.world.b(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 af7cbb5fcf..a2559f0c19 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -763,6 +763,18 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
}
}
+ // 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
+ public Fluid getFluid(BlockPosition blockposition) { return b(blockposition); } // Paper - OBFHELPER
public Fluid b(BlockPosition blockposition) {
if (blockposition.isInvalidYLocation()) { // Paper
return FluidTypes.a.i();
--
2.19.0