Fix custom piglin loved items

Upstream didn't modify the isLovedItem check in wantsToPickup
so piglins never actually tried to pickup interestItems
This commit is contained in:
Jake Potrebic 2022-07-04 21:50:44 -07:00
parent dbfc5fda14
commit 3f8bb2073a

View file

@ -138,7 +138,7 @@
piglin.setItemInHand(InteractionHand.OFF_HAND, ItemStack.EMPTY); piglin.setItemInHand(InteractionHand.OFF_HAND, ItemStack.EMPTY);
} }
@@ -379,14 +400,20 @@ @@ -379,15 +400,21 @@
return false; return false;
} else if (PiglinAi.isAdmiringDisabled(piglin) && piglin.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) { } else if (PiglinAi.isAdmiringDisabled(piglin) && piglin.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) {
return false; return false;
@ -148,18 +148,20 @@
} else { } else {
boolean flag = piglin.canAddToInventory(stack); boolean flag = piglin.canAddToInventory(stack);
return stack.is(Items.GOLD_NUGGET) ? flag : (PiglinAi.isFood(stack) ? !PiglinAi.hasEatenRecently(piglin) && flag : (!PiglinAi.isLovedItem(stack) ? piglin.canReplaceCurrentItem(stack) : PiglinAi.isNotHoldingLovedItemInOffHand(piglin) && flag)); - return stack.is(Items.GOLD_NUGGET) ? flag : (PiglinAi.isFood(stack) ? !PiglinAi.hasEatenRecently(piglin) && flag : (!PiglinAi.isLovedItem(stack) ? piglin.canReplaceCurrentItem(stack) : PiglinAi.isNotHoldingLovedItemInOffHand(piglin) && flag));
+ return stack.is(Items.GOLD_NUGGET) ? flag : (PiglinAi.isFood(stack) ? !PiglinAi.hasEatenRecently(piglin) && flag : (!PiglinAi.isLovedItem(stack, piglin) ? piglin.canReplaceCurrentItem(stack) : PiglinAi.isNotHoldingLovedItemInOffHand(piglin) && flag)); // Paper - upstream missed isLovedItem check
} }
+ } }
+
+ // CraftBukkit start - Added method to allow checking for custom payment items + // CraftBukkit start - Added method to allow checking for custom payment items
+ protected static boolean isLovedItem(ItemStack itemstack, Piglin piglin) { + protected static boolean isLovedItem(ItemStack itemstack, Piglin piglin) {
+ return PiglinAi.isLovedItem(itemstack) || (piglin.interestItems.contains(itemstack.getItem()) || piglin.allowedBarterItems.contains(itemstack.getItem())); + return PiglinAi.isLovedItem(itemstack) || (piglin.interestItems.contains(itemstack.getItem()) || piglin.allowedBarterItems.contains(itemstack.getItem()));
} + }
+ // CraftBukkit end + // CraftBukkit end
+
protected static boolean isLovedItem(ItemStack stack) { protected static boolean isLovedItem(ItemStack stack) {
return stack.is(ItemTags.PIGLIN_LOVED); return stack.is(ItemTags.PIGLIN_LOVED);
}
@@ -451,6 +478,7 @@ @@ -451,6 +478,7 @@
} }