145 lines
7.2 KiB
Diff
145 lines
7.2 KiB
Diff
--- a/net/minecraft/world/entity/monster/piglin/PiglinAI.java
|
|
+++ b/net/minecraft/world/entity/monster/piglin/PiglinAI.java
|
|
@@ -71,6 +71,13 @@
|
|
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.PiglinBarterEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class PiglinAI {
|
|
|
|
public static final int REPELLENT_DETECTION_RANGE_HORIZONTAL = 8;
|
|
@@ -186,13 +193,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::playSound);
|
|
@@ -224,23 +231,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 {
|
|
+ } 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(entitypiglin, itemstack);
|
|
admireGoldItem(entitypiglin);
|
|
} else if (isFood(itemstack) && !hasEatenRecently(entitypiglin)) {
|
|
eat(entitypiglin);
|
|
} else {
|
|
- boolean flag = entitypiglin.equipItemIfPossible(itemstack);
|
|
+ boolean flag = entitypiglin.equipItemIfPossible(itemstack, entityitem); // CraftBukkit
|
|
|
|
if (!flag) {
|
|
putInInventory(entitypiglin, itemstack);
|
|
@@ -276,9 +287,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(itemstack);
|
|
|
|
@@ -291,7 +307,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));
|
|
@@ -368,7 +384,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);
|
|
@@ -377,6 +393,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);
|
|
}
|
|
@@ -472,7 +494,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(EntityPiglin entitypiglin, EntityLiving entityliving) {
|
|
@@ -739,6 +761,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);
|
|
}
|
|
@@ -776,7 +804,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) {
|