summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockSapling.patch
blob: 2f9f89664470246078a58a7cac4b6ae250e70d90 (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/BlockSapling.java
+++ b/net/minecraft/server/BlockSapling.java
@@ -2,11 +2,21 @@
 
 import java.util.Random;
 
+// CraftBukkit start
+import java.util.List;
+
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.event.world.StructureGrowEvent;
+// CraftBukkit end
+
 public class BlockSapling extends BlockPlant implements IBlockFragilePlantElement {
 
     public static final BlockStateInteger STAGE = BlockProperties.am;
     protected static final VoxelShape b = Block.a(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
     private final WorldGenTreeProvider c;
+    public static TreeType treeType; // CraftBukkit
 
     protected BlockSapling(WorldGenTreeProvider worldgentreeprovider, Block.Info block_info) {
         super(block_info);
@@ -21,7 +31,30 @@
     public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Random random) {
         super.a(iblockdata, world, blockposition, random);
         if (world.getLightLevel(blockposition.up()) >= 9 && random.nextInt(7) == 0) {
+            // CraftBukkit start
+            world.captureTreeGeneration = true;
+            // CraftBukkit end
             this.grow(world, blockposition, iblockdata, random);
+            // CraftBukkit start
+            world.captureTreeGeneration = false;
+            if (world.capturedBlockStates.size() > 0) {
+                TreeType treeType = BlockSapling.treeType;
+                BlockSapling.treeType = null;
+                Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
+                List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone();
+                world.capturedBlockStates.clear();
+                StructureGrowEvent event = null;
+                if (treeType != null) {
+                    event = new StructureGrowEvent(location, treeType, false, null, blocks);
+                    org.bukkit.Bukkit.getPluginManager().callEvent(event);
+                }
+                if (event == null || !event.isCancelled()) {
+                    for (BlockState blockstate : blocks) {
+                        blockstate.update(true);
+                    }
+                }
+            }
+            // CraftBukkit end
         }
 
     }