PaperMC/nms-patches/PlayerInventory.patch
2016-11-17 12:41:03 +11:00

119 lines
4 KiB
Diff

--- a/net/minecraft/server/PlayerInventory.java
+++ b/net/minecraft/server/PlayerInventory.java
@@ -5,6 +5,15 @@
import java.util.List;
import javax.annotation.Nullable;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.Location;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class PlayerInventory implements IInventory {
public final NonNullList<ItemStack> items;
@@ -16,11 +25,54 @@
private ItemStack carried;
public boolean f;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
+ public List<ItemStack> getContents() {
+ List<ItemStack> combined = new ArrayList<ItemStack>(items.size() + armor.size() + extraSlots.size());
+ for (List<net.minecraft.server.ItemStack> sub : this.g) {
+ combined.addAll(sub);
+ }
+
+ return combined;
+ }
+
+ public List<ItemStack> getArmorContents() {
+ return this.armor;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ return this.player.getBukkitEntity();
+ }
+
+ 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);
this.extraSlots = NonNullList.a(1, ItemStack.a);
- this.g = Arrays.asList(new NonNullList[] { this.items, this.armor, this.extraSlots});
+ this.g = (List) Arrays.asList(new NonNullList[] { this.items, this.armor, this.extraSlots}); // CraftBukkit - decompile error
this.carried = ItemStack.a;
this.player = entityhuman;
}
@@ -41,6 +93,23 @@
return itemstack.getItem() == itemstack1.getItem() && (!itemstack.usesData() || itemstack.getData() == itemstack1.getData()) && 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();
+
+ // Taken from firstPartial(ItemStack)
+ if (!itemstack1.isEmpty() && itemstack1.getItem() == itemstack.getItem() && itemstack1.isStackable() && itemstack1.getCount() < itemstack1.getMaxStackSize() && itemstack1.getCount() < this.getMaxStackSize() && (!itemstack1.usesData() || itemstack1.getData() == itemstack.getData()) && ItemStack.equals(itemstack1, itemstack)) {
+ remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.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()) {
@@ -477,7 +546,7 @@
}
public int getMaxStackSize() {
- return 64;
+ return maxStack; // CraftBukkit
}
public boolean b(IBlockData iblockdata) {
@@ -533,6 +602,11 @@
}
public ItemStack getCarried() {
+ // CraftBukkit start
+ if (this.carried.isEmpty()) {
+ this.setCarried(ItemStack.a);
+ }
+ // CraftBukkit end
return this.carried;
}