--- a/net/minecraft/world/entity/ai/behavior/BehaviorFindAdmirableItem.java
+++ b/net/minecraft/world/entity/ai/behavior/BehaviorFindAdmirableItem.java
@@ -28,6 +28,20 @@
                     EntityItem entityitem = (EntityItem) behaviorbuilder_b.get(memoryaccessor2);
 
                     if (behaviorbuilder_b.tryGet(memoryaccessor3).isEmpty() && predicate.test(entityliving) && entityitem.closerThan(entityliving, (double) i) && entityliving.level().getWorldBorder().isWithinBounds(entityitem.blockPosition())) {
+                        // CraftBukkit start
+                        if (entityliving instanceof net.minecraft.world.entity.animal.allay.Allay) {
+                            org.bukkit.event.entity.EntityTargetEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(entityliving, entityitem, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_ENTITY);
+
+                            if (event.isCancelled()) {
+                                return false;
+                            }
+                            if (!(event.getTarget() instanceof EntityItem)) {
+                                memoryaccessor2.erase();
+                            }
+
+                            entityitem = (EntityItem) ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();
+                        }
+                        // CraftBukkit end
                         MemoryTarget memorytarget = new MemoryTarget(new BehaviorPositionEntity(entityitem, false), f, 0);
 
                         memoryaccessor.set(new BehaviorPositionEntity(entityitem, true));
