SPIGOT-6093: Can't change ItemStack in EntityPickupItemEvent

This commit is contained in:
Shane Bee 2020-08-21 18:46:42 +10:00 committed by md_5
parent eaf0bace20
commit fe4efd19f5
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
3 changed files with 20 additions and 13 deletions

View File

@ -9,7 +9,7 @@
}
public static AttributeProvider.Builder eM() {
@@ -176,6 +176,11 @@
@@ -176,6 +176,12 @@
ItemStack itemstack = entityitem.getItemStack();
if (this.canPickup(itemstack)) {
@ -17,11 +17,12 @@
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, false).isCancelled()) {
+ return;
+ }
+ itemstack = entityitem.getItemStack(); // update ItemStack from event
+ // CraftBukkit end
this.a(entityitem);
this.setSlot(EnumItemSlot.MAINHAND, itemstack);
this.dropChanceHand[EnumItemSlot.MAINHAND.b()] = 2.0F;
@@ -323,7 +328,7 @@
@@ -323,7 +329,7 @@
@Override
public boolean a() {
@ -30,7 +31,7 @@
}
@Override
@@ -432,7 +437,7 @@
@@ -432,7 +438,7 @@
@Override
public void c() {
@ -39,7 +40,7 @@
}
@Override
@@ -451,7 +456,7 @@
@@ -451,7 +457,7 @@
}
if (this.c.isSwimming() && this.c.world.random.nextInt(6) == 0) {

View File

@ -11,16 +11,17 @@
return list;
}
@@ -401,7 +401,7 @@
@@ -401,7 +401,8 @@
protected void b(EntityItem entityitem) {
ItemStack itemstack = entityitem.getItemStack();
- if (this.canPickup(itemstack)) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, itemstack.getCount() - 1, !this.canPickup(itemstack)).isCancelled()) { // CraftBukkit - call EntityPickupItemEvent
+ itemstack = entityitem.getItemStack(); // CraftBukkit - update ItemStack from event
int i = itemstack.getCount();
if (i > 1) {
@@ -923,6 +923,11 @@
@@ -923,6 +924,11 @@
int i = (Integer) iblockdata.get(BlockSweetBerryBush.a);
iblockdata.set(BlockSweetBerryBush.a, 1);
@ -32,7 +33,7 @@
int j = 1 + EntityFox.this.world.random.nextInt(2) + (i == 3 ? 1 : 0);
ItemStack itemstack = EntityFox.this.getEquipment(EnumItemSlot.MAINHAND);
@@ -962,7 +967,7 @@
@@ -962,7 +968,7 @@
private int f;
public r() {
@ -41,7 +42,7 @@
this.a(EnumSet.of(PathfinderGoal.Type.MOVE, PathfinderGoal.Type.LOOK));
}
@@ -1014,7 +1019,7 @@
@@ -1014,7 +1020,7 @@
private int c;
public t() {
@ -50,7 +51,7 @@
this.c = EntityFox.this.random.nextInt(140);
this.a(EnumSet.of(PathfinderGoal.Type.MOVE, PathfinderGoal.Type.LOOK, PathfinderGoal.Type.JUMP));
}
@@ -1125,7 +1130,7 @@
@@ -1125,7 +1131,7 @@
private EntityLiving k;
private int l;
@ -59,7 +60,7 @@
super(EntityFox.this, oclass, 10, flag, flag1, predicate);
}
@@ -1205,6 +1210,14 @@
@@ -1205,6 +1211,14 @@
if (entityplayer1 != null && entityplayer != entityplayer1) {
entityfox.b(entityplayer1.getUniqueID());
}
@ -74,7 +75,7 @@
if (entityplayer2 != null) {
entityplayer2.a(StatisticList.ANIMALS_BRED);
@@ -1217,10 +1230,14 @@
@@ -1217,10 +1231,14 @@
this.partner.resetLove();
entityfox.setAgeRaw(-24000);
entityfox.setPositionRotation(this.animal.locX(), this.animal.locY(), this.animal.locZ(), 0.0F, 0.0F);

View File

@ -85,7 +85,7 @@
this.velocityChanged();
this.f = (int) ((float) this.f - f);
if (this.f <= 0) {
@@ -285,6 +307,40 @@
@@ -285,6 +307,45 @@
Item item = itemstack.getItem();
int i = itemstack.getCount();
@ -113,6 +113,11 @@
+ return;
+ }
+
+ // Update the ItemStack incase it was changed in the event
+ itemstack = this.getItemStack();
+ canHold = entityhuman.inventory.canHold(itemstack);
+ remaining = itemstack.getCount() - canHold;
+
+ itemstack.setCount(canHold + remaining); // = i
+
+ // Possibly < 0; fix here so we do not have to modify code below
@ -126,7 +131,7 @@
if (this.pickupDelay == 0 && (this.owner == null || this.owner.equals(entityhuman.getUniqueID())) && entityhuman.inventory.pickup(itemstack)) {
entityhuman.receive(this, i);
if (itemstack.isEmpty()) {
@@ -328,7 +384,9 @@
@@ -328,7 +389,9 @@
}
public void setItemStack(ItemStack itemstack) {