145 lines
7.3 KiB
Diff
145 lines
7.3 KiB
Diff
--- a/net/minecraft/world/entity/monster/piglin/PiglinAI.java
|
|
+++ b/net/minecraft/world/entity/monster/piglin/PiglinAI.java
|
|
@@ -72,6 +72,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;
|
|
@@ -187,13 +194,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);
|
|
@@ -225,23 +232,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);
|
|
@@ -277,9 +288,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);
|
|
|
|
@@ -292,7 +308,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));
|
|
@@ -369,7 +385,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);
|
|
@@ -378,6 +394,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((Tag) TagsItem.PIGLIN_LOVED);
|
|
}
|
|
@@ -473,7 +495,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) {
|
|
@@ -740,6 +762,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);
|
|
}
|
|
@@ -777,7 +805,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) {
|