--- a/net/minecraft/world/entity/monster/piglin/PiglinAI.java
+++ b/net/minecraft/world/entity/monster/piglin/PiglinAI.java
@@ -72,6 +72,14 @@
 import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
 import net.minecraft.world.phys.Vec3D;
 
+// CraftBukkit start
+import java.util.stream.Collectors;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.PiglinBarterEvent;
+// CraftBukkit end
+
 public class PiglinAI {
 
     public static final int REPELLENT_DETECTION_RANGE_HORIZONTAL = 8;
@@ -166,7 +174,8 @@
     }
 
     private static void initRideHoglinActivity(BehaviorController<EntityPiglin> behaviorcontroller) {
-        behaviorcontroller.addActivityAndRemoveMemoryWhenStopped(Activity.RIDE, 10, ImmutableList.of(BehaviorStartRiding.create(0.8F), BehaviorLookTarget.create(PiglinAI::isPlayerHoldingLovedItem, 8.0F), BehaviorBuilder.sequence(BehaviorBuilder.triggerIf(Entity::isPassenger), TriggerGate.triggerOneShuffled(ImmutableList.builder().addAll(createLookBehaviors()).add(Pair.of(BehaviorBuilder.triggerIf((entitypiglin) -> {
+        // CraftBukkit - decompile error
+        behaviorcontroller.addActivityAndRemoveMemoryWhenStopped(Activity.RIDE, 10, ImmutableList.of(BehaviorStartRiding.create(0.8F), BehaviorLookTarget.create(PiglinAI::isPlayerHoldingLovedItem, 8.0F), BehaviorBuilder.sequence(BehaviorBuilder.triggerIf(Entity::isPassenger), TriggerGate.triggerOneShuffled(ImmutableList.<Pair<? extends net.minecraft.world.entity.ai.behavior.declarative.Trigger<? super EntityLiving>, Integer>>builder().addAll(createLookBehaviors()).add(Pair.of(BehaviorBuilder.triggerIf((entitypiglin) -> {
             return true;
         }), 1)).build())), BehaviorStopRiding.create(8, PiglinAI::wantsToStopRiding)), MemoryModuleType.RIDE_TARGET);
     }
@@ -176,7 +185,7 @@
     }
 
     private static BehaviorGateSingle<EntityLiving> createIdleLookBehaviors() {
-        return new BehaviorGateSingle<>(ImmutableList.builder().addAll(createLookBehaviors()).add(Pair.of(new BehaviorNop(30, 60), 1)).build());
+        return new BehaviorGateSingle<>(ImmutableList.<Pair<? extends BehaviorControl<? super EntityLiving>, Integer>>builder().addAll(createLookBehaviors()).add(Pair.of(new BehaviorNop(30, 60), 1)).build()); // CraftBukkit - decompile error
     }
 
     private static BehaviorGateSingle<EntityPiglin> createIdleMovementBehaviors() {
@@ -197,13 +206,13 @@
 
     protected static void updateActivity(EntityPiglin entitypiglin) {
         BehaviorController<EntityPiglin> behaviorcontroller = entitypiglin.getBrain();
-        Activity activity = (Activity) behaviorcontroller.getActiveNonCoreActivity().orElse((Object) null);
+        Activity activity = (Activity) behaviorcontroller.getActiveNonCoreActivity().orElse(null); // CraftBukkit - decompile error
 
         behaviorcontroller.setActiveActivityToFirstValid(ImmutableList.of(Activity.ADMIRE_ITEM, Activity.FIGHT, Activity.AVOID, Activity.CELEBRATE, Activity.RIDE, Activity.IDLE));
-        Activity activity1 = (Activity) behaviorcontroller.getActiveNonCoreActivity().orElse((Object) null);
+        Activity activity1 = (Activity) behaviorcontroller.getActiveNonCoreActivity().orElse(null); // CraftBukkit - decompile error
 
         if (activity != activity1) {
-            Optional optional = getSoundForCurrentActivity(entitypiglin);
+            Optional<SoundEffect> optional = getSoundForCurrentActivity(entitypiglin); // CraftBukkit - decompile error
 
             Objects.requireNonNull(entitypiglin);
             optional.ifPresent(entitypiglin::makeSound);
@@ -235,23 +244,27 @@
         stopWalking(entitypiglin);
         ItemStack itemstack;
 
-        if (entityitem.getItem().is(Items.GOLD_NUGGET)) {
+        // CraftBukkit start
+        if (entityitem.getItem().is(Items.GOLD_NUGGET) && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(entitypiglin, entityitem, 0, false).isCancelled()) {
             entitypiglin.take(entityitem, entityitem.getItem().getCount());
             itemstack = entityitem.getItem();
-            entityitem.discard();
-        } else {
+            entityitem.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
+        } else if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(entitypiglin, entityitem, entityitem.getItem().getCount() - 1, false).isCancelled()) {
             entitypiglin.take(entityitem, 1);
             itemstack = removeOneItemFromItemEntity(entityitem);
+        } else {
+            return;
         }
+        // CraftBukkit end
 
-        if (isLovedItem(itemstack)) {
+        if (isLovedItem(itemstack, entitypiglin)) { // CraftBukkit - Changes to allow for custom payment in bartering
             entitypiglin.getBrain().eraseMemory(MemoryModuleType.TIME_TRYING_TO_REACH_ADMIRE_ITEM);
             holdInOffhand(worldserver, entitypiglin, itemstack);
             admireGoldItem(entitypiglin);
         } else if (isFood(itemstack) && !hasEatenRecently(entitypiglin)) {
             eat(entitypiglin);
         } else {
-            boolean flag = !entitypiglin.equipItemIfPossible(worldserver, itemstack).equals(ItemStack.EMPTY);
+            boolean flag = !entitypiglin.equipItemIfPossible(worldserver, itemstack, entityitem).equals(ItemStack.EMPTY); // CraftBukkit
 
             if (!flag) {
                 putInInventory(entitypiglin, itemstack);
@@ -272,7 +285,7 @@
         ItemStack itemstack1 = itemstack.split(1);
 
         if (itemstack.isEmpty()) {
-            entityitem.discard();
+            entityitem.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
         } else {
             entityitem.setItem(itemstack);
         }
@@ -287,9 +300,14 @@
         boolean flag1;
 
         if (entitypiglin.isAdult()) {
-            flag1 = isBarterCurrency(itemstack);
+            flag1 = isBarterCurrency(itemstack, entitypiglin); // CraftBukkit - Changes to allow custom payment for bartering
             if (flag && flag1) {
-                throwItems(entitypiglin, getBarterResponseItems(entitypiglin));
+                // CraftBukkit start
+                PiglinBarterEvent event = CraftEventFactory.callPiglinBarterEvent(entitypiglin, getBarterResponseItems(entitypiglin), itemstack);
+                if (!event.isCancelled()) {
+                    throwItems(entitypiglin, event.getOutcome().stream().map(CraftItemStack::asNMSCopy).collect(Collectors.toList()));
+                }
+                // CraftBukkit end
             } else if (!flag1) {
                 boolean flag2 = !entitypiglin.equipItemIfPossible(worldserver, itemstack).isEmpty();
 
@@ -302,7 +320,7 @@
             if (!flag1) {
                 ItemStack itemstack1 = entitypiglin.getMainHandItem();
 
-                if (isLovedItem(itemstack1)) {
+                if (isLovedItem(itemstack1, entitypiglin)) { // CraftBukkit - Changes to allow for custom payment in bartering
                     putInInventory(entitypiglin, itemstack1);
                 } else {
                     throwItems(entitypiglin, Collections.singletonList(itemstack1));
@@ -379,7 +397,7 @@
             return false;
         } else if (isAdmiringDisabled(entitypiglin) && entitypiglin.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) {
             return false;
-        } else if (isBarterCurrency(itemstack)) {
+        } else if (isBarterCurrency(itemstack, entitypiglin)) { // CraftBukkit
             return isNotHoldingLovedItemInOffHand(entitypiglin);
         } else {
             boolean flag = entitypiglin.canAddToInventory(itemstack);
@@ -388,6 +406,12 @@
         }
     }
 
+    // CraftBukkit start - Added method to allow checking for custom payment items
+    protected static boolean isLovedItem(ItemStack itemstack, EntityPiglin piglin) {
+        return isLovedItem(itemstack) || (piglin.interestItems.contains(itemstack.getItem()) || piglin.allowedBarterItems.contains(itemstack.getItem()));
+    }
+    // CraftBukkit end
+
     protected static boolean isLovedItem(ItemStack itemstack) {
         return itemstack.is(TagsItem.PIGLIN_LOVED);
     }
@@ -481,7 +505,7 @@
     }
 
     protected static boolean canAdmire(EntityPiglin entitypiglin, ItemStack itemstack) {
-        return !isAdmiringDisabled(entitypiglin) && !isAdmiringItem(entitypiglin) && entitypiglin.isAdult() && isBarterCurrency(itemstack);
+        return !isAdmiringDisabled(entitypiglin) && !isAdmiringItem(entitypiglin) && entitypiglin.isAdult() && isBarterCurrency(itemstack, entitypiglin); // CraftBukkit
     }
 
     protected static void wasHurtBy(WorldServer worldserver, EntityPiglin entitypiglin, EntityLiving entityliving) {
@@ -735,6 +759,12 @@
         return entitypiglin.getBrain().hasMemoryValue(MemoryModuleType.ADMIRING_ITEM);
     }
 
+    // CraftBukkit start - Changes to allow custom payment for bartering
+    private static boolean isBarterCurrency(ItemStack itemstack, EntityPiglin piglin) {
+        return isBarterCurrency(itemstack) || piglin.allowedBarterItems.contains(itemstack.getItem());
+    }
+    // CraftBukkit end
+
     private static boolean isBarterCurrency(ItemStack itemstack) {
         return itemstack.is(PiglinAI.BARTERING_ITEM);
     }
@@ -772,7 +802,7 @@
     }
 
     private static boolean isNotHoldingLovedItemInOffHand(EntityPiglin entitypiglin) {
-        return entitypiglin.getOffhandItem().isEmpty() || !isLovedItem(entitypiglin.getOffhandItem());
+        return entitypiglin.getOffhandItem().isEmpty() || !isLovedItem(entitypiglin.getOffhandItem(), entitypiglin); // CraftBukkit - Changes to allow custom payment for bartering
     }
 
     public static boolean isZombified(EntityTypes<?> entitytypes) {
