--- a/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java
+++ b/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java
@@ -35,6 +_,21 @@
                                 && itemEntity.closerThan(entity, maxDistToWalk)
                                 && entity.level().getWorldBorder().isWithinBounds(itemEntity.blockPosition())
                                 && entity.canPickUpLoot()) {
+                                // CraftBukkit start
+                                if (entity instanceof net.minecraft.world.entity.animal.allay.Allay) {
+                                    org.bukkit.event.entity.EntityTargetEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(entity, itemEntity, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_ENTITY);
+
+                                    if (event.isCancelled()) {
+                                        return false;
+                                    }
+                                    if (!(event.getTarget() instanceof org.bukkit.craftbukkit.entity.CraftItem targetItem)) { // Paper - only erase allay memory on non-item targets
+                                        nearestVisibleWantedItem.erase();
+                                        return false; // Paper - only erase allay memory on non-item targets
+                                    }
+
+                                    itemEntity = targetItem.getHandle();
+                                }
+                                // CraftBukkit end
                                 WalkTarget walkTarget1 = new WalkTarget(new EntityTracker(itemEntity, false), speedModifier, 0);
                                 lookTarget.set(new EntityTracker(itemEntity, true));
                                 walkTarget.set(walkTarget1);
