summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockMushroom.patch
blob: 20bdf91acb3aa25bd9e6840a691e9297945a3433 (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
--- a/net/minecraft/server/BlockMushroom.java
+++ b/net/minecraft/server/BlockMushroom.java
@@ -3,6 +3,12 @@
 import java.util.Iterator;
 import java.util.Random;
 
+// CraftBukkit start
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.event.block.BlockSpreadEvent;
+// CraftBukkit end
+
 public class BlockMushroom extends BlockPlant implements IBlockFragilePlantElement {
 
     protected BlockMushroom() {
@@ -13,6 +19,7 @@
     }
 
     public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
+        final int sourceX = blockposition.getX(), sourceY = blockposition.getY(), sourceZ = blockposition.getZ(); // CraftBukkit
         if (random.nextInt(25) == 0) {
             int i = 5;
             boolean flag = true;
@@ -40,7 +47,19 @@
             }
 
             if (world.isEmpty(blockposition2) && this.f(world, blockposition2, this.getBlockData())) {
-                world.setTypeAndData(blockposition2, this.getBlockData(), 2);
+                // CraftBukkit start
+                // world.setTypeAndData(blockposition2, this.getBlockData(), 2);
+                org.bukkit.World bworld = world.getWorld();
+                BlockState blockState = bworld.getBlockAt(blockposition2.getX(), blockposition2.getY(), blockposition2.getZ()).getState();
+                blockState.setType(org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(this)); // nms: this.id, 0, 2
+
+                BlockSpreadEvent event = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(sourceX, sourceY, sourceZ), blockState);
+                world.getServer().getPluginManager().callEvent(event);
+
+                if (!event.isCancelled()) {
+                    blockState.update(true);
+                }
+                // CraftBukkit end
             }
         }
 
@@ -69,8 +88,10 @@
         WorldGenHugeMushroom worldgenhugemushroom = null;
 
         if (this == Blocks.BROWN_MUSHROOM) {
+            BlockSapling.treeType = TreeType.BROWN_MUSHROOM; // CraftBukkit
             worldgenhugemushroom = new WorldGenHugeMushroom(Blocks.BROWN_MUSHROOM_BLOCK);
         } else if (this == Blocks.RED_MUSHROOM) {
+            BlockSapling.treeType = TreeType.RED_MUSHROOM; // CraftBukkit
             worldgenhugemushroom = new WorldGenHugeMushroom(Blocks.RED_MUSHROOM_BLOCK);
         }