summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockCauldron.patch
blob: fdea61417dae1ad7256e08eadbf9a96b8e0387ed (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
--- a/net/minecraft/server/BlockCauldron.java
+++ b/net/minecraft/server/BlockCauldron.java
@@ -1,5 +1,7 @@
 package net.minecraft.server;
 
+import org.bukkit.event.block.CauldronLevelChangeEvent; // CraftBukkit
+
 public class BlockCauldron extends Block {
 
     public static final BlockStateInteger LEVEL = BlockProperties.af;
@@ -32,8 +34,13 @@
         float f = (float) blockposition.getY() + (6.0F + (float) (3 * i)) / 16.0F;
 
         if (!world.isClientSide && entity.isBurning() && i > 0 && entity.getBoundingBox().minY <= (double) f) {
+            // CraftBukkit start
+            if (!this.changeLevel(world, blockposition, iblockdata, i - 1, entity, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH)) {
+                return;
+            }
             entity.extinguish();
-            this.a(world, blockposition, iblockdata, i - 1);
+            // this.a(world, blockposition, iblockdata, i - 1);
+            // CraftBukkit end
         }
 
     }
@@ -49,18 +56,27 @@
 
             if (item == Items.WATER_BUCKET) {
                 if (i < 3 && !world.isClientSide) {
+                    // CraftBukkit start
+                    if (!this.changeLevel(world, blockposition, iblockdata, 3, entityhuman, CauldronLevelChangeEvent.ChangeReason.BUCKET_EMPTY)) {
+                        return true;
+                    }
                     if (!entityhuman.abilities.canInstantlyBuild) {
                         entityhuman.a(enumhand, new ItemStack(Items.BUCKET));
                     }
 
                     entityhuman.a(StatisticList.FILL_CAULDRON);
-                    this.a(world, blockposition, iblockdata, 3);
+                    // this.a(world, blockposition, iblockdata, 3);
+                    // CraftBukkit end
                     world.a((EntityHuman) null, blockposition, SoundEffects.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
                 }
 
                 return true;
             } else if (item == Items.BUCKET) {
                 if (i == 3 && !world.isClientSide) {
+                    // CraftBukkit start
+                    if (!this.changeLevel(world, blockposition, iblockdata, 0, entityhuman, CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL)) {
+                        return true;
+                    }
                     if (!entityhuman.abilities.canInstantlyBuild) {
                         itemstack.subtract(1);
                         if (itemstack.isEmpty()) {
@@ -71,7 +87,8 @@
                     }
 
                     entityhuman.a(StatisticList.USE_CAULDRON);
-                    this.a(world, blockposition, iblockdata, 0);
+                    // this.a(world, blockposition, iblockdata, 0);
+                    // CraftBukkit end
                     world.a((EntityHuman) null, blockposition, SoundEffects.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
                 }
 
@@ -81,6 +98,10 @@
 
                 if (item == Items.GLASS_BOTTLE) {
                     if (i > 0 && !world.isClientSide) {
+                        // CraftBukkit start
+                        if (!this.changeLevel(world, blockposition, iblockdata, i - 1, entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL)) {
+                            return true;
+                        }
                         if (!entityhuman.abilities.canInstantlyBuild) {
                             itemstack1 = PotionUtil.a(new ItemStack(Items.POTION), Potions.b);
                             entityhuman.a(StatisticList.USE_CAULDRON);
@@ -95,12 +116,17 @@
                         }
 
                         world.a((EntityHuman) null, blockposition, SoundEffects.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
-                        this.a(world, blockposition, iblockdata, i - 1);
+                        // this.a(world, blockposition, iblockdata, i - 1);
+                        // CraftBukkit end
                     }
 
                     return true;
                 } else if (item == Items.POTION && PotionUtil.d(itemstack) == Potions.b) {
                     if (i < 3 && !world.isClientSide) {
+                        // CraftBukkit start
+                        if (!this.changeLevel(world, blockposition, iblockdata, i + 1, entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY)) {
+                            return true;
+                        }
                         if (!entityhuman.abilities.canInstantlyBuild) {
                             itemstack1 = new ItemStack(Items.GLASS_BOTTLE);
                             entityhuman.a(StatisticList.USE_CAULDRON);
@@ -111,7 +137,8 @@
                         }
 
                         world.a((EntityHuman) null, blockposition, SoundEffects.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
-                        this.a(world, blockposition, iblockdata, i + 1);
+                        // this.a(world, blockposition, iblockdata, i + 1);
+                        // CraftBukkit end
                     }
 
                     return true;
@@ -120,8 +147,13 @@
                         ItemArmorColorable itemarmorcolorable = (ItemArmorColorable) item;
 
                         if (itemarmorcolorable.e(itemstack) && !world.isClientSide) {
+                            // CraftBukkit start
+                            if (!this.changeLevel(world, blockposition, iblockdata, i - 1, entityhuman, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) {
+                                return true;
+                            }
                             itemarmorcolorable.g(itemstack);
-                            this.a(world, blockposition, iblockdata, i - 1);
+                            // this.a(world, blockposition, iblockdata, i - 1);
+                            // CraftBukkit end
                             entityhuman.a(StatisticList.CLEAN_ARMOR);
                             return true;
                         }
@@ -129,13 +161,18 @@
 
                     if (i > 0 && item instanceof ItemBanner) {
                         if (TileEntityBanner.a(itemstack) > 0 && !world.isClientSide) {
+                            // CraftBukkit start
+                            if (!this.changeLevel(world, blockposition, iblockdata, i - 1, entityhuman, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) {
+                                return true;
+                            }
                             itemstack1 = itemstack.cloneItemStack();
                             itemstack1.setCount(1);
                             TileEntityBanner.b(itemstack1);
                             entityhuman.a(StatisticList.CLEAN_BANNER);
                             if (!entityhuman.abilities.canInstantlyBuild) {
                                 itemstack.subtract(1);
-                                this.a(world, blockposition, iblockdata, i - 1);
+                                // this.a(world, blockposition, iblockdata, i - 1);
+                                // CraftBukkit end
                             }
 
                             if (itemstack.isEmpty()) {
@@ -172,9 +209,25 @@
         }
     }
 
+    // CraftBukkit start
     public void a(World world, BlockPosition blockposition, IBlockData iblockdata, int i) {
-        world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockCauldron.LEVEL, MathHelper.clamp(i, 0, 3)), 2);
+        this.changeLevel(world, blockposition, iblockdata, i, null, CauldronLevelChangeEvent.ChangeReason.UNKNOWN);
+    }
+
+    private boolean changeLevel(World world, BlockPosition blockposition, IBlockData iblockdata, int i, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) {
+        int newLevel = Integer.valueOf(MathHelper.clamp(i, 0, 3));
+        CauldronLevelChangeEvent event = new CauldronLevelChangeEvent(
+                world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()),
+                (entity == null) ? null : entity.getBukkitEntity(), reason, iblockdata.get(BlockCauldron.LEVEL), newLevel
+        );
+        world.getServer().getPluginManager().callEvent(event);
+        if (event.isCancelled()) {
+            return false;
+        }
+        world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockCauldron.LEVEL, event.getNewLevel()), 2);
         world.updateAdjacentComparators(blockposition, this);
+        return true;
+        // CraftBukkit end
     }
 
     public void c(World world, BlockPosition blockposition) {
@@ -185,7 +238,7 @@
                 IBlockData iblockdata = world.getType(blockposition);
 
                 if ((Integer) iblockdata.get(BlockCauldron.LEVEL) < 3) {
-                    world.setTypeAndData(blockposition, (IBlockData) iblockdata.a((IBlockState) BlockCauldron.LEVEL), 2);
+                    this.a(world, blockposition, (IBlockData) iblockdata.a((IBlockState) BlockCauldron.LEVEL), 2); // CraftBukkit
                 }
 
             }