summaryrefslogtreecommitdiffstats
path: root/nms-patches/PlayerInventory.patch
blob: 285ff230382700fa1defda2c43dc63cfa4b43f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
--- a/net/minecraft/server/PlayerInventory.java
+++ b/net/minecraft/server/PlayerInventory.java
@@ -3,6 +3,14 @@
 import java.util.Arrays;
 import java.util.concurrent.Callable;
 
+// CraftBukkit start
+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 ItemStack[] items = new ItemStack[36];
@@ -14,6 +22,44 @@
     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 ItemStack[] getContents() {
+        return this.items;
+    }
+
+    public 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.g = new ItemStack[][] { this.items, this.armor, this.extraSlots};
         this.player = entityhuman;
@@ -35,6 +81,22 @@
         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.count;
+        for (int i = 0; i < this.items.length; ++i) {
+            if (this.items[i] == null) return itemstack.count;
+
+            // Taken from firstPartial(ItemStack)
+            if (this.items[i] != null && this.items[i].getItem() == itemstack.getItem() && this.items[i].isStackable() && this.items[i].count < this.items[i].getMaxStackSize() && this.items[i].count < this.getMaxStackSize() && (!this.items[i].usesData() || this.items[i].getData() == itemstack.getData()) && ItemStack.equals(this.items[i], itemstack)) {
+                remains -= (this.items[i].getMaxStackSize() < this.getMaxStackSize() ? this.items[i].getMaxStackSize() : this.getMaxStackSize()) - this.items[i].count;
+            }
+            if (remains <= 0) return itemstack.count;
+        }
+        return itemstack.count - remains;
+    }
+    // CraftBukkit end
+
     public int getFirstEmptySlotIndex() {
         for (int i = 0; i < this.items.length; ++i) {
             if (this.items[i] == null) {
@@ -455,7 +517,7 @@
     }
 
     public int getMaxStackSize() {
-        return 64;
+        return maxStack; // CraftBukkit
     }
 
     public boolean b(IBlockData iblockdata) {
@@ -511,6 +573,11 @@
     }
 
     public ItemStack getCarried() {
+        // CraftBukkit start
+        if (this.carried != null && this.carried.count == 0) {
+            this.setCarried(null);
+        }
+        // CraftBukkit end
         return this.carried;
     }