mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
EntityPickupItemEvent fixes
Fixes double firing of the event in PiglinAi Fixes cancelling the event for piglins still triggering the advancement trigger Fires the event when a Raider tries to pick up a raid banner to become raid leader.
This commit is contained in:
parent
3f8bb2073a
commit
945f6ef6e6
@ -120,6 +120,15 @@
|
||||
|
||||
return flag && !flag1 ? true : (!flag && flag1 ? false : super.canReplaceCurrentItem(newStack, currentStack, slot));
|
||||
}
|
||||
@@ -410,7 +438,7 @@
|
||||
|
||||
@Override
|
||||
protected void pickUpItem(ServerLevel world, ItemEntity itemEntity) {
|
||||
- this.onItemPickup(itemEntity);
|
||||
+ // this.onItemPickup(itemEntity); // Paper - EntityPickupItemEvent fixes; call in PiglinAi#pickUpItem after EntityPickupItemEvent is fired
|
||||
PiglinAi.pickUpItem(world, this, itemEntity);
|
||||
}
|
||||
|
||||
@@ -431,7 +459,7 @@
|
||||
|
||||
@Override
|
||||
|
@ -50,19 +50,26 @@
|
||||
|
||||
Objects.requireNonNull(piglin);
|
||||
optional.ifPresent(piglin::makeSound);
|
||||
@@ -235,23 +243,27 @@
|
||||
@@ -235,23 +243,32 @@
|
||||
PiglinAi.stopWalking(piglin);
|
||||
ItemStack itemstack;
|
||||
|
||||
- if (itemEntity.getItem().is(Items.GOLD_NUGGET)) {
|
||||
+ // CraftBukkit start
|
||||
+ if (itemEntity.getItem().is(Items.GOLD_NUGGET) && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(piglin, itemEntity, 0, false).isCancelled()) {
|
||||
piglin.take(itemEntity, itemEntity.getItem().getCount());
|
||||
itemstack = itemEntity.getItem();
|
||||
- piglin.take(itemEntity, itemEntity.getItem().getCount());
|
||||
- itemstack = itemEntity.getItem();
|
||||
- itemEntity.discard();
|
||||
- } else {
|
||||
+ // CraftBukkit start
|
||||
+ // Paper start - EntityPickupItemEvent fixes; fix event firing twice
|
||||
+ if (itemEntity.getItem().is(Items.GOLD_NUGGET)/* && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(piglin, itemEntity, 0, false).isCancelled()*/) { // Paper
|
||||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(piglin, itemEntity, 0, false).isCancelled()) return;
|
||||
+ piglin.onItemPickup(itemEntity); // Paper - moved from Piglin#pickUpItem - call prior to item entity modification
|
||||
+ // Paper end
|
||||
+ piglin.take(itemEntity, itemEntity.getItem().getCount());
|
||||
+ itemstack = itemEntity.getItem();
|
||||
+ itemEntity.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
|
||||
+ } else if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(piglin, itemEntity, itemEntity.getItem().getCount() - 1, false).isCancelled()) {
|
||||
+ piglin.onItemPickup(itemEntity); // Paper - EntityPickupItemEvent fixes; moved from Piglin#pickUpItem - call prior to item entity modification
|
||||
piglin.take(itemEntity, 1);
|
||||
itemstack = PiglinAi.removeOneItemFromItemEntity(itemEntity);
|
||||
+ } else {
|
||||
@ -79,11 +86,11 @@
|
||||
PiglinAi.eat(piglin);
|
||||
} else {
|
||||
- boolean flag = !piglin.equipItemIfPossible(world, itemstack).equals(ItemStack.EMPTY);
|
||||
+ boolean flag = !piglin.equipItemIfPossible(world, itemstack, itemEntity).equals(ItemStack.EMPTY); // CraftBukkit
|
||||
+ boolean flag = !piglin.equipItemIfPossible(world, itemstack, null).equals(ItemStack.EMPTY); // CraftBukkit // Paper - pass null item entity to prevent duplicate pickup item event call - called above.
|
||||
|
||||
if (!flag) {
|
||||
PiglinAi.putInInventory(piglin, itemstack);
|
||||
@@ -261,7 +273,9 @@
|
||||
@@ -261,7 +278,9 @@
|
||||
|
||||
private static void holdInOffhand(ServerLevel world, Piglin piglin, ItemStack stack) {
|
||||
if (PiglinAi.isHoldingItemInOffHand(piglin)) {
|
||||
@ -93,7 +100,7 @@
|
||||
}
|
||||
|
||||
piglin.holdInOffHand(stack);
|
||||
@@ -272,7 +286,7 @@
|
||||
@@ -272,7 +291,7 @@
|
||||
ItemStack itemstack1 = itemstack.split(1);
|
||||
|
||||
if (itemstack.isEmpty()) {
|
||||
@ -102,7 +109,7 @@
|
||||
} else {
|
||||
stack.setItem(itemstack);
|
||||
}
|
||||
@@ -287,9 +301,14 @@
|
||||
@@ -287,9 +306,14 @@
|
||||
boolean flag1;
|
||||
|
||||
if (piglin.isAdult()) {
|
||||
@ -119,7 +126,7 @@
|
||||
} else if (!flag1) {
|
||||
boolean flag2 = !piglin.equipItemIfPossible(world, itemstack).isEmpty();
|
||||
|
||||
@@ -302,7 +321,7 @@
|
||||
@@ -302,7 +326,7 @@
|
||||
if (!flag1) {
|
||||
ItemStack itemstack1 = piglin.getMainHandItem();
|
||||
|
||||
@ -128,7 +135,7 @@
|
||||
PiglinAi.putInInventory(piglin, itemstack1);
|
||||
} else {
|
||||
PiglinAi.throwItems(piglin, Collections.singletonList(itemstack1));
|
||||
@@ -316,7 +335,9 @@
|
||||
@@ -316,7 +340,9 @@
|
||||
|
||||
protected static void cancelAdmiring(ServerLevel world, Piglin piglin) {
|
||||
if (PiglinAi.isAdmiringItem(piglin) && !piglin.getOffhandItem().isEmpty()) {
|
||||
@ -138,7 +145,7 @@
|
||||
piglin.setItemInHand(InteractionHand.OFF_HAND, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@@ -379,15 +400,21 @@
|
||||
@@ -379,15 +405,21 @@
|
||||
return false;
|
||||
} else if (PiglinAi.isAdmiringDisabled(piglin) && piglin.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) {
|
||||
return false;
|
||||
@ -162,7 +169,7 @@
|
||||
protected static boolean isLovedItem(ItemStack stack) {
|
||||
return stack.is(ItemTags.PIGLIN_LOVED);
|
||||
}
|
||||
@@ -451,6 +478,7 @@
|
||||
@@ -451,6 +483,7 @@
|
||||
}
|
||||
|
||||
public static void angerNearbyPiglins(ServerLevel world, Player player, boolean blockOpen) {
|
||||
@ -170,7 +177,7 @@
|
||||
List<Piglin> list = player.level().getEntitiesOfClass(Piglin.class, player.getBoundingBox().inflate(16.0D));
|
||||
|
||||
list.stream().filter(PiglinAi::isIdle).filter((entitypiglin) -> {
|
||||
@@ -481,7 +509,7 @@
|
||||
@@ -481,7 +514,7 @@
|
||||
}
|
||||
|
||||
protected static boolean canAdmire(Piglin piglin, ItemStack nearbyItems) {
|
||||
@ -179,7 +186,7 @@
|
||||
}
|
||||
|
||||
protected static void wasHurtBy(ServerLevel world, Piglin piglin, LivingEntity attacker) {
|
||||
@@ -735,6 +763,12 @@
|
||||
@@ -735,6 +768,12 @@
|
||||
return entity.getBrain().hasMemoryValue(MemoryModuleType.ADMIRING_ITEM);
|
||||
}
|
||||
|
||||
@ -192,7 +199,7 @@
|
||||
private static boolean isBarterCurrency(ItemStack stack) {
|
||||
return stack.is(PiglinAi.BARTERING_ITEM);
|
||||
}
|
||||
@@ -772,7 +806,7 @@
|
||||
@@ -772,7 +811,7 @@
|
||||
}
|
||||
|
||||
private static boolean isNotHoldingLovedItemInOffHand(Piglin piglin) {
|
||||
|
@ -10,7 +10,17 @@
|
||||
|
||||
public abstract class Raider extends PatrollingMonster {
|
||||
|
||||
@@ -230,13 +233,15 @@
|
||||
@@ -225,18 +228,25 @@
|
||||
boolean flag = this.hasActiveRaid() && this.getCurrentRaid().getLeader(this.getWave()) != null;
|
||||
|
||||
if (this.hasActiveRaid() && !flag && ItemStack.matches(itemstack, Raid.getOminousBannerInstance(this.registryAccess().lookupOrThrow(Registries.BANNER_PATTERN)))) {
|
||||
+ // Paper start - EntityPickupItemEvent fixes
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, itemEntity, 0, false).isCancelled()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ // Paper end - EntityPickupItemEvent fixes
|
||||
EquipmentSlot enumitemslot = EquipmentSlot.HEAD;
|
||||
ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
|
||||
double d0 = (double) this.getEquipmentDropChance(enumitemslot);
|
||||
|
||||
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
|
||||
@ -27,7 +37,7 @@
|
||||
this.getCurrentRaid().setLeader(this.getWave(), this);
|
||||
this.setPatrolLeader(true);
|
||||
} else {
|
||||
@@ -290,7 +295,7 @@
|
||||
@@ -290,7 +300,7 @@
|
||||
@Nullable
|
||||
private ItemEntity pursuedBannerItemEntity;
|
||||
|
||||
@ -36,7 +46,7 @@
|
||||
this.mob = entityraider;
|
||||
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
|
||||
}
|
||||
@@ -335,6 +340,7 @@
|
||||
@@ -335,6 +345,7 @@
|
||||
}
|
||||
|
||||
private boolean cannotPickUpBanner() {
|
||||
@ -44,7 +54,7 @@
|
||||
if (!this.mob.hasActiveRaid()) {
|
||||
return true;
|
||||
} else if (this.mob.getCurrentRaid().isOver()) {
|
||||
@@ -518,7 +524,7 @@
|
||||
@@ -518,7 +529,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +63,7 @@
|
||||
|
||||
private final Raider mob;
|
||||
private final float hostileRadiusSqr;
|
||||
@@ -547,7 +553,7 @@
|
||||
@@ -547,7 +558,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
Raider entityraider = (Raider) iterator.next();
|
||||
|
||||
@ -62,7 +72,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -564,7 +570,7 @@
|
||||
@@ -564,7 +575,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
Raider entityraider = (Raider) iterator.next();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user