summaryrefslogtreecommitdiffstats
path: root/nms-patches/TileEntityBrewingStand.patch
blob: 012112d59e28d01fa9189105bb68830a28b81e5b (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
--- /home/matt/mc-dev-private//net/minecraft/server/TileEntityBrewingStand.java	2015-02-26 22:40:23.123608134 +0000
+++ src/main/java/net/minecraft/server/TileEntityBrewingStand.java	2015-02-26 22:40:23.123608134 +0000
@@ -3,18 +3,50 @@
 import java.util.Arrays;
 import java.util.List;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.inventory.BrewEvent;
+// CraftBukkit end
+
 public class TileEntityBrewingStand extends TileEntityContainer implements IUpdatePlayerListBox, IWorldInventory {
 
     private static final int[] a = new int[] { 3};
     private static final int[] f = new int[] { 0, 1, 2};
     private ItemStack[] items = new ItemStack[4];
-    private int brewTime;
+    public int brewTime; // CraftBukkit - public
     private boolean[] i;
     private Item j;
     private String k;
+    private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field
 
     public TileEntityBrewingStand() {}
 
+    // CraftBukkit start - add fields and methods
+    public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+    private int maxStack = 64;
+
+    public void onOpen(CraftHumanEntity who) {
+        transaction.add(who);
+    }
+
+    public void onClose(CraftHumanEntity who) {
+        transaction.remove(who);
+    }
+
+    public List<HumanEntity> getViewers() {
+        return transaction;
+    }
+
+    public ItemStack[] getContents() {
+        return this.items;
+    }
+
+    public void setMaxStackSize(int size) {
+        maxStack = size;
+    }
+    // CraftBukkit end
+
     public String getName() {
         return this.hasCustomName() ? this.k : "container.brewing";
     }
@@ -32,9 +64,14 @@
     }
 
     public void c() {
+        // CraftBukkit start - Use wall time instead of ticks for brewing
+        int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+        this.lastTick = MinecraftServer.currentTick;
+
         if (this.brewTime > 0) {
-            --this.brewTime;
-            if (this.brewTime == 0) {
+            this.brewTime -= elapsedTicks;
+            if (this.brewTime <= 0) { // == -> <=
+                // CraftBukkit end
                 this.o();
                 this.update();
             } else if (!this.n()) {
@@ -110,6 +147,16 @@
         if (this.n()) {
             ItemStack itemstack = this.items[3];
 
+            // CraftBukkit start
+            if (getOwner() != null) {
+                BrewEvent event = new BrewEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), (org.bukkit.inventory.BrewerInventory) this.getOwner().getInventory());
+                org.bukkit.Bukkit.getPluginManager().callEvent(event);
+                if (event.isCancelled()) {
+                    return;
+                }
+            }
+            // CraftBukkit end
+
             for (int i = 0; i < 3; ++i) {
                 if (this.items[i] != null && this.items[i].getItem() == Items.POTION) {
                     int j = this.items[i].getData();
@@ -221,7 +268,7 @@
     }
 
     public int getMaxStackSize() {
-        return 64;
+        return this.maxStack; // CraftBukkit
     }
 
     public boolean a(EntityHuman entityhuman) {