diff --git a/patches/server/Only-erase-allay-memory-on-non-item-targets.patch b/patches/server/Only-erase-allay-memory-on-non-item-targets.patch new file mode 100644 index 000000000..b5f09f65c --- /dev/null +++ b/patches/server/Only-erase-allay-memory-on-non-item-targets.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bjarne Koll +Date: Fri, 4 Aug 2023 15:53:36 +0200 +Subject: [PATCH] Only erase allay memory on non-item targets + +Spigot incorrectly instanceOf checks the EntityTargetEvent#getTarget +against the internal ItemEntity type and removes the nearest wanted item +memory if said instanceOf check fails, (which is always the case) +causing allays to behave differently as they constantly loose their +target item. + +This commit fixes the faulty behaviour by instance performing a check +against the CraftItem type. + +diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java b/src/main/java/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java ++++ b/src/main/java/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java +@@ -0,0 +0,0 @@ public class GoToWantedItem { + if (event.isCancelled()) { + return false; + } +- if (!(event.getTarget() instanceof ItemEntity)) { ++ if (!(event.getTarget() instanceof org.bukkit.craftbukkit.entity.CraftItem)) { // Paper - only erase allay memory on non-item targets + memoryaccessor2.erase(); ++ return false; // Paper - only erase allay memory on non-item targets + } + + entityitem = (ItemEntity) ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle(); diff --git a/patches/server/Remove-streams-for-villager-AI.patch b/patches/server/Remove-streams-for-villager-AI.patch index 392aa3baa..20855f3d2 100644 --- a/patches/server/Remove-streams-for-villager-AI.patch +++ b/patches/server/Remove-streams-for-villager-AI.patch @@ -120,7 +120,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 Brain brain = entity.getBrain(); List list = world.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(32.0D, 16.0D, 32.0D), (itemEntity) -> { - return true; -+ return itemEntity.closerThan(entity, 9.0D) && entity.wantsToPickUp(itemEntity.getItem()); // Paper - move predicate into getEntities ++ return itemEntity.closerThan(entity, MAX_DISTANCE_TO_WANTED_ITEM) && entity.wantsToPickUp(itemEntity.getItem()); // Paper - move predicate into getEntities }); - list.sort(Comparator.comparingDouble(entity::distanceToSqr)); + list.sort((e1, e2) -> Double.compare(entity.distanceToSqr(e1), entity.distanceToSqr(e2))); // better to take the sort perf hit than using line of sight more than we need to.