13
0
geforkt von Mirrors/Paper

SPIGOT-6093: Can't change ItemStack in EntityPickupItemEvent

By: Shane Bee <shanebolenback@me.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2020-08-21 18:46:42 +10:00
Ursprung 9262b0c735
Commit 886d2e1504
3 geänderte Dateien mit 20 neuen und 13 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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