From 886d2e150467409c45b09d691c512f51774de942 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 21 Aug 2020 18:46:42 +1000 Subject: [PATCH] SPIGOT-6093: Can't change ItemStack in EntityPickupItemEvent By: Shane Bee --- paper-server/nms-patches/EntityDolphin.patch | 9 +++++---- paper-server/nms-patches/EntityFox.patch | 15 ++++++++------- paper-server/nms-patches/EntityItem.patch | 9 +++++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/paper-server/nms-patches/EntityDolphin.patch b/paper-server/nms-patches/EntityDolphin.patch index e498398644..5d27eed5c6 100644 --- a/paper-server/nms-patches/EntityDolphin.patch +++ b/paper-server/nms-patches/EntityDolphin.patch @@ -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) { diff --git a/paper-server/nms-patches/EntityFox.patch b/paper-server/nms-patches/EntityFox.patch index b9e912e694..63a2019624 100644 --- a/paper-server/nms-patches/EntityFox.patch +++ b/paper-server/nms-patches/EntityFox.patch @@ -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); diff --git a/paper-server/nms-patches/EntityItem.patch b/paper-server/nms-patches/EntityItem.patch index c1631939d5..0114d83776 100644 --- a/paper-server/nms-patches/EntityItem.patch +++ b/paper-server/nms-patches/EntityItem.patch @@ -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) {