--- a/net/minecraft/server/PlayerInventory.java +++ b/net/minecraft/server/PlayerInventory.java @@ -5,6 +5,13 @@ import java.util.List; import java.util.function.Predicate; +// CraftBukkit start +import java.util.ArrayList; +import org.bukkit.Location; +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.entity.HumanEntity; +// CraftBukkit end + public class PlayerInventory implements IInventory, INamableTileEntity { public final NonNullList items; @@ -16,6 +23,54 @@ private ItemStack carried; private int h; + // CraftBukkit start - add fields and methods + public List transaction = new java.util.ArrayList(); + private int maxStack = MAX_STACK; + + public List getContents() { + List combined = new ArrayList(items.size() + armor.size() + extraSlots.size()); + for (List sub : this.f) { + combined.addAll(sub); + } + + return combined; + } + + public List getArmorContents() { + return this.armor; + } + + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + } + + public List getViewers() { + return transaction; + } + + public org.bukkit.inventory.InventoryHolder getOwner() { + return this.player.getBukkitEntity(); + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public Location getLocation() { + return player.getBukkitEntity().getLocation(); + } + // CraftBukkit end + public PlayerInventory(EntityHuman entityhuman) { this.items = NonNullList.a(36, ItemStack.a); this.armor = NonNullList.a(4, ItemStack.a); @@ -41,6 +96,28 @@ return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1); } + // CraftBukkit start - Watch method above! :D + public int canHold(ItemStack itemstack) { + int remains = itemstack.getCount(); + for (int i = 0; i < this.items.size(); ++i) { + ItemStack itemstack1 = this.getItem(i); + if (itemstack1.isEmpty()) return itemstack.getCount(); + + if (this.isSimilarAndNotFull(itemstack1, itemstack)) { + remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount(); + } + if (remains <= 0) return itemstack.getCount(); + } + ItemStack offhandItemStack = this.getItem(this.items.size() + this.armor.size()); + if (this.isSimilarAndNotFull(offhandItemStack, itemstack)) { + remains -= (offhandItemStack.getMaxStackSize() < this.getMaxStackSize() ? offhandItemStack.getMaxStackSize() : this.getMaxStackSize()) - offhandItemStack.getCount(); + } + if (remains <= 0) return itemstack.getCount(); + + return itemstack.getCount() - remains; + } + // CraftBukkit end + public int getFirstEmptySlotIndex() { for (int i = 0; i < this.items.size(); ++i) { if (((ItemStack) this.items.get(i)).isEmpty()) { @@ -513,8 +590,9 @@ ItemStack itemstack = (ItemStack) this.armor.get(i); if (itemstack.getItem() instanceof ItemArmor) { + int finalI = i; // CraftBukkit - decompile error itemstack.damage((int) f, this.player, (entityhuman) -> { - entityhuman.broadcastItemBreak(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, i)); + entityhuman.broadcastItemBreak(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, finalI)); // CraftBukkit - decompile error }); } } @@ -550,6 +628,11 @@ } public ItemStack getCarried() { + // CraftBukkit start + if (this.carried.isEmpty()) { + this.setCarried(ItemStack.a); + } + // CraftBukkit end return this.carried; }