From e5274eeac92224f51815cf4e2f50406e5746dbc8 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 18 Nov 2023 15:59:12 -0800 Subject: [PATCH] Fix spawners checking max nearby entities with correct type (#8945) Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> --- .../0856-Fix-a-bunch-of-vanilla-bugs.patch | 36 +++++++++++++++++++ .../0871-Ignore-impossible-spawn-tick.patch | 4 +-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/patches/server/0856-Fix-a-bunch-of-vanilla-bugs.patch b/patches/server/0856-Fix-a-bunch-of-vanilla-bugs.patch index 5ef20d44ed..6247c69382 100644 --- a/patches/server/0856-Fix-a-bunch-of-vanilla-bugs.patch +++ b/patches/server/0856-Fix-a-bunch-of-vanilla-bugs.patch @@ -395,6 +395,42 @@ index ca6a2b9840c9ade87ec8effab01d4f184fe876b7..43129ecefcc8beccbcf2978f262b1ce8 entity.level().gameEvent(entity, GameEvent.EQUIP, entity.position()); stack.shrink(1); } +diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java +index ae2b95f53e875716489821dc9b0a3a35039bfcc9..9284c550ab2fe21331986a70eac414147662003d 100644 +--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java ++++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java +@@ -46,6 +46,22 @@ public abstract class BaseSpawner { + public int requiredPlayerRange = 16; + public int spawnRange = 4; + private int tickDelay = 0; // Paper ++ // Paper start - ported from 1.20.3 Fix MC-259321 ++ static net.minecraft.world.level.entity.EntityTypeTest forExactClass(Class clazz) { ++ return new net.minecraft.world.level.entity.EntityTypeTest<>() { ++ @Nullable ++ @Override ++ public T tryCast(B clazz) { ++ return (T)(clazz.equals(clazz.getClass()) ? clazz : null); ++ } ++ ++ @Override ++ public Class getBaseClass() { ++ return clazz; ++ } ++ }; ++ } ++ // Paper end + + public BaseSpawner() {} + +@@ -160,7 +176,7 @@ public abstract class BaseSpawner { + return; + } + +- int k = world.getEntitiesOfClass(entity.getClass(), (new AABB((double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), (double) (pos.getX() + 1), (double) (pos.getY() + 1), (double) (pos.getZ() + 1))).inflate((double) this.spawnRange)).size(); ++ int k = world.getEntities(forExactClass(entity.getClass()), (new AABB((double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), (double) (pos.getX() + 1), (double) (pos.getY() + 1), (double) (pos.getZ() + 1))).inflate((double) this.spawnRange), net.minecraft.world.entity.EntitySelector.NO_SPECTATORS).size(); // Paper - Fix MC-259321 (only count exact entity types for nearby checks) + + if (k >= this.maxNearbyEntities) { + this.delay(world, pos); diff --git a/src/main/java/net/minecraft/world/level/block/AzaleaBlock.java b/src/main/java/net/minecraft/world/level/block/AzaleaBlock.java index eba153ad0025d92ffb5d8de65f69a8e812b81533..087f3b3cc180e16195efdc0b402701fd9f5d78b4 100644 --- a/src/main/java/net/minecraft/world/level/block/AzaleaBlock.java diff --git a/patches/server/0871-Ignore-impossible-spawn-tick.patch b/patches/server/0871-Ignore-impossible-spawn-tick.patch index 46cd469266..7e2918d8ae 100644 --- a/patches/server/0871-Ignore-impossible-spawn-tick.patch +++ b/patches/server/0871-Ignore-impossible-spawn-tick.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Ignore impossible spawn tick diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java -index ae2b95f53e875716489821dc9b0a3a35039bfcc9..633500aefd515df5dadda3802b94079f75a03fa0 100644 +index 9284c550ab2fe21331986a70eac414147662003d..1279132e2fb3e8f64f062df0ac8b8197f9d8f343 100644 --- a/src/main/java/net/minecraft/world/level/BaseSpawner.java +++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java -@@ -80,6 +80,7 @@ public abstract class BaseSpawner { +@@ -96,6 +96,7 @@ public abstract class BaseSpawner { } public void serverTick(ServerLevel world, BlockPos pos) {