summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockFire.patch
blob: c2fb2103b90437fbcaaba78383cb8b97397ffa90 (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
--- a/net/minecraft/server/BlockFire.java
+++ b/net/minecraft/server/BlockFire.java
@@ -5,6 +5,12 @@
 import java.util.Random;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockBurnEvent;
+import org.bukkit.event.block.BlockSpreadEvent;
+// CraftBukkit end
+
 public class BlockFire extends Block {
 
     public static final BlockStateInteger AGE = BlockStateInteger.of("age", 0, 15);
@@ -95,7 +101,7 @@
     public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
         if (world.getGameRules().getBoolean("doFireTick")) {
             if (!this.canPlace(world, blockposition)) {
-                world.setAir(blockposition);
+                fireExtinguished(world, blockposition); // CraftBukkit - invalid place location
             }
 
             Block block = world.getType(blockposition.down()).getBlock();
@@ -108,7 +114,7 @@
             int i = ((Integer) iblockdata.get(BlockFire.AGE)).intValue();
 
             if (!flag && world.W() && this.b(world, blockposition) && random.nextFloat() < 0.2F + (float) i * 0.03F) {
-                world.setAir(blockposition);
+                fireExtinguished(world, blockposition); // CraftBukkit - extinguished by rain
             } else {
                 if (i < 15) {
                     iblockdata = iblockdata.set(BlockFire.AGE, Integer.valueOf(i + random.nextInt(3) / 2));
@@ -119,14 +125,14 @@
                 if (!flag) {
                     if (!this.c(world, blockposition)) {
                         if (!world.getType(blockposition.down()).r() || i > 3) {
-                            world.setAir(blockposition);
+                            fireExtinguished(world, blockposition); // CraftBukkit
                         }
 
                         return;
                     }
 
                     if (!this.c((IBlockAccess) world, blockposition.down()) && i == 15 && random.nextInt(4) == 0) {
-                        world.setAir(blockposition);
+                        fireExtinguished(world, blockposition); // CraftBukkit
                         return;
                     }
                 }
@@ -138,12 +144,14 @@
                     b0 = -50;
                 }
 
-                this.a(world, blockposition.east(), 300 + b0, random, i);
-                this.a(world, blockposition.west(), 300 + b0, random, i);
-                this.a(world, blockposition.down(), 250 + b0, random, i);
-                this.a(world, blockposition.up(), 250 + b0, random, i);
-                this.a(world, blockposition.north(), 300 + b0, random, i);
-                this.a(world, blockposition.south(), 300 + b0, random, i);
+                // CraftBukkit start - add source blockposition to burn calls
+                this.a(world, blockposition.east(), 300 + b0, random, i, blockposition);
+                this.a(world, blockposition.west(), 300 + b0, random, i, blockposition);
+                this.a(world, blockposition.down(), 250 + b0, random, i, blockposition);
+                this.a(world, blockposition.up(), 250 + b0, random, i, blockposition);
+                this.a(world, blockposition.north(), 300 + b0, random, i, blockposition);
+                this.a(world, blockposition.south(), 300 + b0, random, i, blockposition);
+                // CraftBukkit end
 
                 for (int j = -1; j <= 1; ++j) {
                     for (int k = -1; k <= 1; ++k) {
@@ -172,7 +180,26 @@
                                             l1 = 15;
                                         }
 
-                                        world.setTypeAndData(blockposition1, iblockdata.set(BlockFire.AGE, Integer.valueOf(l1)), 3);
+                                        // CraftBukkit start - Call to stop spread of fire
+                                        if (world.getType(blockposition1) != Blocks.FIRE) {
+                                            if (CraftEventFactory.callBlockIgniteEvent(world, blockposition1.getX(), blockposition1.getY(), blockposition1.getZ(), blockposition.getX(), blockposition.getY(), blockposition.getZ()).isCancelled()) {
+                                                continue;
+                                            }
+
+                                            org.bukkit.Server server = world.getServer();
+                                            org.bukkit.World bworld = world.getWorld();
+                                            org.bukkit.block.BlockState blockState = bworld.getBlockAt(blockposition1.getX(), blockposition1.getY(), blockposition1.getZ()).getState();
+                                            blockState.setTypeId(Block.getId(this));
+                                            blockState.setData(new org.bukkit.material.MaterialData(Block.getId(this), (byte) l1));
+
+                                            BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), blockState);
+                                            server.getPluginManager().callEvent(spreadEvent);
+
+                                            if (!spreadEvent.isCancelled()) {
+                                                blockState.update(true);
+                                            }
+                                        }
+                                        // CraftBukkit end
                                     }
                                 }
                             }
@@ -204,12 +231,24 @@
         return integer == null ? 0 : integer.intValue();
     }
 
-    private void a(World world, BlockPosition blockposition, int i, Random random, int j) {
+    private void a(World world, BlockPosition blockposition, int i, Random random, int j, BlockPosition sourceposition) { // CraftBukkit add sourceposition
         int k = this.c(world.getType(blockposition).getBlock());
 
         if (random.nextInt(i) < k) {
             IBlockData iblockdata = world.getType(blockposition);
 
+            // CraftBukkit start
+            org.bukkit.block.Block theBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+            org.bukkit.block.Block sourceBlock = world.getWorld().getBlockAt(sourceposition.getX(), sourceposition.getY(), sourceposition.getZ());
+
+            BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock);
+            world.getServer().getPluginManager().callEvent(event);
+
+            if (event.isCancelled()) {
+                return;
+            }
+            // CraftBukkit end
+
             if (random.nextInt(j + 10) < 5 && !world.isRainingAt(blockposition)) {
                 int l = j + random.nextInt(5) / 4;
 
@@ -276,7 +315,7 @@
 
     public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, BlockPosition blockposition1) {
         if (!world.getType(blockposition.down()).r() && !this.c(world, blockposition)) {
-            world.setAir(blockposition);
+            fireExtinguished(world, blockposition); // CraftBukkit - fuel block gone
         }
 
     }
@@ -284,7 +323,7 @@
     public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata) {
         if (world.worldProvider.getDimensionManager().getDimensionID() > 0 || !Blocks.PORTAL.b(world, blockposition)) {
             if (!world.getType(blockposition.down()).r() && !this.c(world, blockposition)) {
-                world.setAir(blockposition);
+                fireExtinguished(world, blockposition); // CraftBukkit - fuel block broke
             } else {
                 world.a(blockposition, (Block) this, this.a(world) + world.random.nextInt(10));
             }
@@ -306,4 +345,12 @@
     protected BlockStateList getStateList() {
         return new BlockStateList(this, new IBlockState[] { BlockFire.AGE, BlockFire.NORTH, BlockFire.EAST, BlockFire.SOUTH, BlockFire.WEST, BlockFire.UPPER});
     }
+
+    // CraftBukkit start
+    private void fireExtinguished(World world, BlockPosition position) {
+        if (!CraftEventFactory.callBlockFadeEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), Blocks.AIR).isCancelled()) {
+            world.setAir(position);
+        }
+    }
+    // CraftBukkit end
 }