--- a/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java
+++ b/net/minecraft/world/entity/ai/behavior/GoToWantedItem.java
@@ -10,22 +10,42 @@
 import net.minecraft.world.entity.item.ItemEntity;
 
 public class GoToWantedItem {
+
+    public GoToWantedItem() {}
+
     public static BehaviorControl<LivingEntity> create(float speed, boolean requiresWalkTarget, int radius) {
-        return create((entity) -> {
+        return GoToWantedItem.create((entityliving) -> {
             return true;
         }, speed, requiresWalkTarget, radius);
     }
 
     public static <E extends LivingEntity> BehaviorControl<E> create(Predicate<E> startCondition, float speed, boolean requiresWalkTarget, int radius) {
-        return BehaviorBuilder.create((context) -> {
-            BehaviorBuilder<E, ? extends MemoryAccessor<? extends K1, WalkTarget>> behaviorBuilder = requiresWalkTarget ? context.registered(MemoryModuleType.WALK_TARGET) : context.absent(MemoryModuleType.WALK_TARGET);
-            return context.group(context.registered(MemoryModuleType.LOOK_TARGET), behaviorBuilder, context.present(MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM), context.registered(MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS)).apply(context, (lookTarget, walkTarget, nearestVisibleWantedItem, itemPickupCooldownTicks) -> {
-                return (world, entity, time) -> {
-                    ItemEntity itemEntity = context.get(nearestVisibleWantedItem);
-                    if (context.tryGet(itemPickupCooldownTicks).isEmpty() && startCondition.test(entity) && itemEntity.closerThan(entity, (double)radius) && entity.level.getWorldBorder().isWithinBounds(itemEntity.blockPosition())) {
-                        WalkTarget walkTarget = new WalkTarget(new EntityTracker(itemEntity, false), speed, 0);
-                        lookTarget.set(new EntityTracker(itemEntity, true));
-                        walkTarget.set(walkTarget);
+        return BehaviorBuilder.create((behaviorbuilder_b) -> {
+            BehaviorBuilder<E, ? extends MemoryAccessor<? extends K1, WalkTarget>> behaviorbuilder = requiresWalkTarget ? behaviorbuilder_b.registered(MemoryModuleType.WALK_TARGET) : behaviorbuilder_b.absent(MemoryModuleType.WALK_TARGET);
+
+            return behaviorbuilder_b.group(behaviorbuilder_b.registered(MemoryModuleType.LOOK_TARGET), behaviorbuilder, behaviorbuilder_b.present(MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM), behaviorbuilder_b.registered(MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS)).apply(behaviorbuilder_b, (memoryaccessor, memoryaccessor1, memoryaccessor2, memoryaccessor3) -> {
+                return (worldserver, entityliving, j) -> {
+                    ItemEntity entityitem = (ItemEntity) behaviorbuilder_b.get(memoryaccessor2);
+
+                    if (behaviorbuilder_b.tryGet(memoryaccessor3).isEmpty() && startCondition.test(entityliving) && entityitem.closerThan(entityliving, (double) radius) && 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.v1_19_R2.event.CraftEventFactory.callEntityTargetEvent(entityliving, entityitem, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_ENTITY);
+
+                            if (event.isCancelled()) {
+                                return false;
+                            }
+                            if (!(event.getTarget() instanceof ItemEntity)) {
+                                memoryaccessor2.erase();
+                            }
+
+                            entityitem = (ItemEntity) ((org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity) event.getTarget()).getHandle();
+                        }
+                        // CraftBukkit end
+                        WalkTarget memorytarget = new WalkTarget(new EntityTracker(entityitem, false), speed, 0);
+
+                        memoryaccessor.set(new EntityTracker(entityitem, true));
+                        memoryaccessor1.set(memorytarget);
                         return true;
                     } else {
                         return false;
