aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/SimpleContainer.java.patch
blob: 788edcea8f3446348690cbe3a22b8708a01265d0 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
--- a/net/minecraft/world/SimpleContainer.java
+++ b/net/minecraft/world/SimpleContainer.java
@@ -1,6 +1,7 @@
 package net.minecraft.world;
 
 import com.google.common.collect.Lists;
+import java.util.Iterator;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.annotation.Nullable;
@@ -13,17 +14,76 @@
 import net.minecraft.world.item.Item;
 import net.minecraft.world.item.ItemStack;
 
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
 public class SimpleContainer implements Container, StackedContentsCompatible {
+
     private final int size;
-    private final NonNullList<ItemStack> items;
+    public final NonNullList<ItemStack> items;
     @Nullable
     private List<ContainerListener> listeners;
 
+    // CraftBukkit start - add fields and methods
+    public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+    private int maxStack = MAX_STACK;
+    protected org.bukkit.inventory.InventoryHolder bukkitOwner;
+
+    public List<ItemStack> getContents() {
+        return this.items;
+    }
+
+    public void onOpen(CraftHumanEntity who) {
+        transaction.add(who);
+    }
+
+    public void onClose(CraftHumanEntity who) {
+        transaction.remove(who);
+    }
+
+    public List<HumanEntity> getViewers() {
+        return transaction;
+    }
+
+    @Override
+    public int getMaxStackSize() {
+        return maxStack;
+    }
+
+    public void setMaxStackSize(int i) {
+        maxStack = i;
+    }
+
+    public org.bukkit.inventory.InventoryHolder getOwner() {
+        return bukkitOwner;
+    }
+
+    @Override
+    public Location getLocation() {
+        return null;
+    }
+
+    public SimpleContainer(SimpleContainer original) {
+        this(original.size);
+        for (int slot = 0; slot < original.size; slot++) {
+            this.items.set(slot, original.items.get(slot).copy());
+        }
+    }
+
     public SimpleContainer(int size) {
-        this.size = size;
-        this.items = NonNullList.withSize(size, ItemStack.EMPTY);
+        this(size, null);
     }
 
+    public SimpleContainer(int i, org.bukkit.inventory.InventoryHolder owner) {
+        this.bukkitOwner = owner;
+        // CraftBukkit end
+        this.size = i;
+        this.items = NonNullList.withSize(i, ItemStack.EMPTY);
+    }
+
     public SimpleContainer(ItemStack... items) {
         this.size = items.length;
         this.items = NonNullList.of(ItemStack.EMPTY, items);
@@ -41,71 +101,82 @@
         if (this.listeners != null) {
             this.listeners.remove(listener);
         }
+
     }
 
     @Override
     public ItemStack getItem(int index) {
-        return index >= 0 && index < this.items.size() ? this.items.get(index) : ItemStack.EMPTY;
+        return index >= 0 && index < this.items.size() ? (ItemStack) this.items.get(index) : ItemStack.EMPTY;
     }
 
     public List<ItemStack> removeAllItems() {
-        List<ItemStack> list = this.items.stream().filter(stack -> !stack.isEmpty()).collect(Collectors.toList());
+        List<ItemStack> list = (List) this.items.stream().filter((itemstack) -> {
+            return !itemstack.isEmpty();
+        }).collect(Collectors.toList());
+
         this.clearContent();
         return list;
     }
 
     @Override
     public ItemStack removeItem(int index, int count) {
-        ItemStack itemStack = ContainerHelper.removeItem(this.items, index, count);
-        if (!itemStack.isEmpty()) {
+        ItemStack itemstack = ContainerHelper.removeItem(this.items, index, count);
+
+        if (!itemstack.isEmpty()) {
             this.setChanged();
         }
 
-        return itemStack;
+        return itemstack;
     }
 
     public ItemStack removeItemType(Item item, int amount) {
-        ItemStack itemStack = new ItemStack(item, 0);
+        ItemStack itemstack = new ItemStack(item, 0);
 
-        for (int i = this.size - 1; i >= 0; i--) {
-            ItemStack item1 = this.getItem(i);
-            if (item1.getItem().equals(item)) {
-                int i1 = amount - itemStack.getCount();
-                ItemStack itemStack1 = item1.split(i1);
-                itemStack.grow(itemStack1.getCount());
-                if (itemStack.getCount() == amount) {
+        for (int j = this.size - 1; j >= 0; --j) {
+            ItemStack itemstack1 = this.getItem(j);
+
+            if (itemstack1.getItem().equals(item)) {
+                int k = amount - itemstack.getCount();
+                ItemStack itemstack2 = itemstack1.split(k);
+
+                itemstack.grow(itemstack2.getCount());
+                if (itemstack.getCount() == amount) {
                     break;
                 }
             }
         }
 
-        if (!itemStack.isEmpty()) {
+        if (!itemstack.isEmpty()) {
             this.setChanged();
         }
 
-        return itemStack;
+        return itemstack;
     }
 
     public ItemStack addItem(ItemStack stack) {
         if (stack.isEmpty()) {
             return ItemStack.EMPTY;
         } else {
-            ItemStack itemStack = stack.copy();
-            this.moveItemToOccupiedSlotsWithSameType(itemStack);
-            if (itemStack.isEmpty()) {
+            ItemStack itemstack1 = stack.copy();
+
+            this.moveItemToOccupiedSlotsWithSameType(itemstack1);
+            if (itemstack1.isEmpty()) {
                 return ItemStack.EMPTY;
             } else {
-                this.moveItemToEmptySlots(itemStack);
-                return itemStack.isEmpty() ? ItemStack.EMPTY : itemStack;
+                this.moveItemToEmptySlots(itemstack1);
+                return itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1;
             }
         }
     }
 
     public boolean canAddItem(ItemStack stack) {
         boolean flag = false;
+        Iterator iterator = this.items.iterator();
 
-        for (ItemStack itemStack : this.items) {
-            if (itemStack.isEmpty() || ItemStack.isSameItemSameTags(itemStack, stack) && itemStack.getCount() < itemStack.getMaxStackSize()) {
+        while (iterator.hasNext()) {
+            ItemStack itemstack1 = (ItemStack) iterator.next();
+
+            if (itemstack1.isEmpty() || ItemStack.isSameItemSameTags(itemstack1, stack) && itemstack1.getCount() < itemstack1.getMaxStackSize()) {
                 flag = true;
                 break;
             }
@@ -116,12 +187,13 @@
 
     @Override
     public ItemStack removeItemNoUpdate(int index) {
-        ItemStack itemStack = this.items.get(index);
-        if (itemStack.isEmpty()) {
+        ItemStack itemstack = (ItemStack) this.items.get(index);
+
+        if (itemstack.isEmpty()) {
             return ItemStack.EMPTY;
         } else {
             this.items.set(index, ItemStack.EMPTY);
-            return itemStack;
+            return itemstack;
         }
     }
 
@@ -142,22 +214,33 @@
 
     @Override
     public boolean isEmpty() {
-        for (ItemStack itemStack : this.items) {
-            if (!itemStack.isEmpty()) {
-                return false;
+        Iterator iterator = this.items.iterator();
+
+        ItemStack itemstack;
+
+        do {
+            if (!iterator.hasNext()) {
+                return true;
             }
-        }
 
-        return true;
+            itemstack = (ItemStack) iterator.next();
+        } while (itemstack.isEmpty());
+
+        return false;
     }
 
     @Override
     public void setChanged() {
         if (this.listeners != null) {
-            for (ContainerListener containerListener : this.listeners) {
-                containerListener.containerChanged(this);
+            Iterator iterator = this.listeners.iterator();
+
+            while (iterator.hasNext()) {
+                ContainerListener iinventorylistener = (ContainerListener) iterator.next();
+
+                iinventorylistener.containerChanged(this);
             }
         }
+
     }
 
     @Override
@@ -173,70 +256,85 @@
 
     @Override
     public void fillStackedContents(StackedContents helper) {
-        for (ItemStack itemStack : this.items) {
-            helper.accountStack(itemStack);
+        Iterator iterator = this.items.iterator();
+
+        while (iterator.hasNext()) {
+            ItemStack itemstack = (ItemStack) iterator.next();
+
+            helper.accountStack(itemstack);
         }
+
     }
 
-    @Override
     public String toString() {
-        return this.items.stream().filter(stack -> !stack.isEmpty()).collect(Collectors.toList()).toString();
+        return ((List) this.items.stream().filter((itemstack) -> {
+            return !itemstack.isEmpty();
+        }).collect(Collectors.toList())).toString();
     }
 
     private void moveItemToEmptySlots(ItemStack stack) {
-        for (int i = 0; i < this.size; i++) {
-            ItemStack item = this.getItem(i);
-            if (item.isEmpty()) {
+        for (int i = 0; i < this.size; ++i) {
+            ItemStack itemstack1 = this.getItem(i);
+
+            if (itemstack1.isEmpty()) {
                 this.setItem(i, stack.copyAndClear());
                 return;
             }
         }
+
     }
 
     private void moveItemToOccupiedSlotsWithSameType(ItemStack stack) {
-        for (int i = 0; i < this.size; i++) {
-            ItemStack item = this.getItem(i);
-            if (ItemStack.isSameItemSameTags(item, stack)) {
-                this.moveItemsBetweenStacks(stack, item);
+        for (int i = 0; i < this.size; ++i) {
+            ItemStack itemstack1 = this.getItem(i);
+
+            if (ItemStack.isSameItemSameTags(itemstack1, stack)) {
+                this.moveItemsBetweenStacks(stack, itemstack1);
                 if (stack.isEmpty()) {
                     return;
                 }
             }
         }
+
     }
 
     private void moveItemsBetweenStacks(ItemStack stack, ItemStack other) {
-        int min = Math.min(this.getMaxStackSize(), other.getMaxStackSize());
-        int min1 = Math.min(stack.getCount(), min - other.getCount());
-        if (min1 > 0) {
-            other.grow(min1);
-            stack.shrink(min1);
+        int i = Math.min(this.getMaxStackSize(), other.getMaxStackSize());
+        int j = Math.min(stack.getCount(), i - other.getCount());
+
+        if (j > 0) {
+            other.grow(j);
+            stack.shrink(j);
             this.setChanged();
         }
+
     }
 
     public void fromTag(ListTag containerNbt) {
         this.clearContent();
 
-        for (int i = 0; i < containerNbt.size(); i++) {
-            ItemStack itemStack = ItemStack.of(containerNbt.getCompound(i));
-            if (!itemStack.isEmpty()) {
-                this.addItem(itemStack);
+        for (int i = 0; i < containerNbt.size(); ++i) {
+            ItemStack itemstack = ItemStack.of(containerNbt.getCompound(i));
+
+            if (!itemstack.isEmpty()) {
+                this.addItem(itemstack);
             }
         }
+
     }
 
     public ListTag createTag() {
-        ListTag list = new ListTag();
+        ListTag nbttaglist = new ListTag();
 
-        for (int i = 0; i < this.getContainerSize(); i++) {
-            ItemStack item = this.getItem(i);
-            if (!item.isEmpty()) {
-                list.add(item.save(new CompoundTag()));
+        for (int i = 0; i < this.getContainerSize(); ++i) {
+            ItemStack itemstack = this.getItem(i);
+
+            if (!itemstack.isEmpty()) {
+                nbttaglist.add(itemstack.save(new CompoundTag()));
             }
         }
 
-        return list;
+        return nbttaglist;
     }
 
     public NonNullList<ItemStack> getItems() {