From 84028e28a579bd38b52ef10a2ebb6520b55f36fc Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Sat, 15 Jan 2022 08:05:24 -0600 Subject: [PATCH] Dont eat blocks in non ticking chunks --- ...ont-eat-blocks-in-non-ticking-chunks.patch | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 patches/server/0259-Dont-eat-blocks-in-non-ticking-chunks.patch diff --git a/patches/server/0259-Dont-eat-blocks-in-non-ticking-chunks.patch b/patches/server/0259-Dont-eat-blocks-in-non-ticking-chunks.patch new file mode 100644 index 0000000000..520d563237 --- /dev/null +++ b/patches/server/0259-Dont-eat-blocks-in-non-ticking-chunks.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: BillyGalbreath +Date: Sat, 15 Jan 2022 06:23:04 -0600 +Subject: [PATCH] Dont eat blocks in non ticking chunks + + +diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java +index 35bb7a3502c90462eb2d67e23bddb18030f40ad1..892d4914efe022619d061fc3e4b8a29a0adf6b68 100644 +--- a/src/main/java/net/minecraft/server/level/ChunkMap.java ++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +@@ -1748,7 +1748,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider + return this.anyPlayerCloseEnoughForSpawning(this.getUpdatingChunkIfPresent(chunkcoordintpair.toLong()), chunkcoordintpair, reducedRange); + } + +- final boolean anyPlayerCloseEnoughForSpawning(ChunkHolder playerchunk, ChunkPos chunkcoordintpair, boolean reducedRange) { ++ public final boolean anyPlayerCloseEnoughForSpawning(ChunkHolder playerchunk, ChunkPos chunkcoordintpair, boolean reducedRange) { // Purpur - package -> public + // this function is so hot that removing the map lookup call can have an order of magnitude impact on its performance + // tested and confirmed via System.nanoTime() + com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet playersInRange = reducedRange ? playerchunk.playersInMobSpawnRange : playerchunk.playersInChunkTickRange; +diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java +index 8a4080a77bd5b73ac812e3ae67c6f21dcd270215..16e66ae7cf761fabb74a035e2fd8c28615365dc2 100644 +--- a/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java ++++ b/src/main/java/net/minecraft/world/entity/ai/goal/EatBlockGoal.java +@@ -32,6 +32,12 @@ public class EatBlockGoal extends Goal { + + @Override + public boolean canUse() { ++ // Purpur start ++ net.minecraft.world.level.chunk.LevelChunk chunk = this.mob.level.getChunkIfLoaded(this.mob.blockPosition); ++ if (chunk == null || chunk.playerChunk == null || !((net.minecraft.server.level.ServerLevel) this.mob.level).getChunkSource().chunkMap.anyPlayerCloseEnoughForSpawning(chunk.playerChunk, this.mob.chunkPosition(), false)) { ++ return false; ++ } ++ // Purpur end + if (this.mob.getRandom().nextInt(this.mob.isBaby() ? 50 : 1000) != 0) { + return false; + } else {