summaryrefslogtreecommitdiffstats
path: root/nms-patches/PlayerInventory.patch
blob: 9058f9888d7e16806069881ad004e92e2013636b (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
107
108
109
110
111
112
113
--- a/net/minecraft/server/PlayerInventory.java
+++ b/net/minecraft/server/PlayerInventory.java
@@ -6,6 +6,15 @@
 import java.util.function.Predicate;
 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;
@@ -17,6 +26,49 @@
     private ItemStack carried;
     private int h;
 
+    // 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.f) {
+            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);
@@ -42,6 +94,23 @@
         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();
+
+            // Taken from firstPartial(ItemStack)
+            if (!this.a(itemstack, itemstack1)) {
+                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()) {
@@ -502,7 +571,7 @@
     }
 
     public int getMaxStackSize() {
-        return 64;
+        return maxStack; // CraftBukkit
     }
 
     public boolean b(IBlockData iblockdata) {
@@ -552,6 +621,11 @@
     }
 
     public ItemStack getCarried() {
+        // CraftBukkit start
+        if (this.carried.isEmpty()) {
+            this.setCarried(ItemStack.a);
+        }
+        // CraftBukkit end
         return this.carried;
     }