From f7e17b68ded48ef599de9971476be86b37a8a575 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Sat, 2 Jul 2011 14:05:31 -0400 Subject: [PATCH] Fixed PlayerPickupItem event returning wrong amount picked up and added function to get the amount remaining on the ground. --- src/main/java/net/minecraft/server/EntityArrow.java | 2 +- src/main/java/net/minecraft/server/EntityItem.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java index 5bd6cafb2d..f07021689b 100644 --- a/src/main/java/net/minecraft/server/EntityArrow.java +++ b/src/main/java/net/minecraft/server/EntityArrow.java @@ -292,7 +292,7 @@ public class EntityArrow extends Entity { if (this.inGround && this.fromPlayer && this.shake <= 0 && entityhuman.inventory.canHold(itemstack) > 0) { net.minecraft.server.EntityItem item = new net.minecraft.server.EntityItem(this.world, this.locX, this.locY, this.locZ, itemstack); - PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.world.getServer(), item)); + PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.world.getServer(), item), 0); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java index 8aa0b161f6..d8558b6743 100644 --- a/src/main/java/net/minecraft/server/EntityItem.java +++ b/src/main/java/net/minecraft/server/EntityItem.java @@ -124,9 +124,13 @@ public class EntityItem extends Entity { int i = this.itemStack.count; // CraftBukkit start - if (this.pickupDelay <= 0 && entityhuman.inventory.canHold(this.itemStack) > 0) { - PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity()); + int canHold = entityhuman.inventory.canHold(this.itemStack); + int remaining = this.itemStack.count - canHold; + if (this.pickupDelay <= 0 && canHold > 0) { + this.itemStack.count = canHold; + PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining); this.world.getServer().getPluginManager().callEvent(event); + this.itemStack.count = canHold + remaining; if (event.isCancelled()) { return;