summaryrefslogtreecommitdiffstats
path: root/nms-patches/TileEntityChest.patch
blob: a5e476f09aea4735eecd47452b21c46433d96b7c (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
--- ../work/decompile-8eb82bde//net/minecraft/server/TileEntityChest.java	2014-11-28 17:43:43.393707428 +0000
+++ src/main/java/net/minecraft/server/TileEntityChest.java	2014-11-28 17:38:17.000000000 +0000
@@ -3,6 +3,11 @@
 import java.util.Iterator;
 import java.util.List;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
 public class TileEntityChest extends TileEntityContainer implements IUpdatePlayerListBox, IInventory {
 
     private ItemStack[] items = new ItemStack[27];
@@ -19,6 +24,31 @@
     private String p;
 
     public TileEntityChest() {}
+    
+    // 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 void onOpen(CraftHumanEntity who) {
+        transaction.add(who);
+    }
+
+    public void onClose(CraftHumanEntity who) {
+        transaction.remove(who);
+    }
+
+    public List<HumanEntity> getViewers() {
+        return transaction;
+    }
+
+    public void setMaxStackSize(int size) {
+        maxStack = size;
+    }
+    // CraftBukkit end
 
     public int getSize() {
         return 27;
@@ -125,10 +155,11 @@
     }
 
     public int getMaxStackSize() {
-        return 64;
+        return maxStack; // CraftBukkit
     }
 
     public boolean a(EntityHuman entityhuman) {
+        if (this.world == null) return true; // CraftBukkit
         return this.world.getTileEntity(this.position) != this ? false : entityhuman.e((double) this.position.getX() + 0.5D, (double) this.position.getY() + 0.5D, (double) this.position.getZ() + 0.5D) <= 64.0D;
     }
 
@@ -304,9 +335,22 @@
             if (this.l < 0) {
                 this.l = 0;
             }
+            
+            int oldPower = Math.max(0, Math.min(15, this.l)); // CraftBukkit - Get power before new viewer is added
 
             ++this.l;
+            if (this.world == null) return; // CraftBukkit
             this.world.playBlockAction(this.position, this.w(), 1, this.l);
+
+            // CraftBukkit start - Call redstone event
+            if (this.w() == Blocks.TRAPPED_CHEST) {
+                int newPower = Math.max(0, Math.min(15, this.l));
+
+                if (oldPower != newPower) {
+                    org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, position.getX(), position.getY(), position.getZ(), oldPower, newPower);
+                }
+            }
+            // CraftBukkit end
             this.world.applyPhysics(this.position, this.w());
             this.world.applyPhysics(this.position.down(), this.w());
         }
@@ -315,8 +359,21 @@
 
     public void closeContainer(EntityHuman entityhuman) {
         if (!entityhuman.v() && this.w() instanceof BlockChest) {
+            int oldPower = Math.max(0, Math.min(15, this.l)); // CraftBukkit - Get power before new viewer is added
+            
             --this.l;
+            if (this.world == null) return; // CraftBukkit
             this.world.playBlockAction(this.position, this.w(), 1, this.l);
+            
+            // CraftBukkit start - Call redstone event
+            if (this.w() == Blocks.TRAPPED_CHEST) {
+                int newPower = Math.max(0, Math.min(15, this.l));
+
+                if (oldPower != newPower) {
+                    org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, position.getX(), position.getY(), position.getZ(), oldPower, newPower);
+                }
+            }
+            // CraftBukkit end
             this.world.applyPhysics(this.position, this.w());
             this.world.applyPhysics(this.position.down(), this.w());
         }