summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockSapling.patch
blob: 2b65eaf19961bc92163e3ce506b0e092f3c65cf7 (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
--- ../work/decompile-8eb82bde//net/minecraft/server/BlockSapling.java	2014-11-28 17:43:42.957707438 +0000
+++ src/main/java/net/minecraft/server/BlockSapling.java	2014-11-28 17:38:17.000000000 +0000
@@ -2,10 +2,20 @@
 
 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 BlockStateEnum TYPE = BlockStateEnum.of("type", EnumLogVariant.class);
     public static final BlockStateInteger STAGE = BlockStateInteger.of("stage", 0, 1);
+    public static TreeType treeType; // CraftBukkit
 
     protected BlockSapling() {
         this.j(this.blockStateList.getBlockData().set(BlockSapling.TYPE, EnumLogVariant.OAK).set(BlockSapling.STAGE, Integer.valueOf(0)));
@@ -19,7 +29,30 @@
         if (!world.isStatic) {
             super.b(world, blockposition, iblockdata, 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
             }
 
         }
@@ -35,7 +68,17 @@
     }
 
     public void e(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
-        Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
+        // CraftBukkit start - Turn ternary operator into if statement to set treeType
+        // Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
+        Object object;
+        if (random.nextInt(10) == 0) {
+            treeType = TreeType.BIG_TREE;
+            object = new WorldGenBigTree(true);
+        } else {
+            treeType = TreeType.TREE;
+            object = new WorldGenTrees(true);
+        }
+        // CraftBukkit end
         int i = 0;
         int j = 0;
         boolean flag = false;
@@ -46,6 +89,7 @@
             for (i = 0; i >= -1; --i) {
                 for (j = 0; j >= -1; --j) {
                     if (this.a(world, blockposition.a(i, 0, j), EnumLogVariant.SPRUCE) && this.a(world, blockposition.a(i + 1, 0, j), EnumLogVariant.SPRUCE) && this.a(world, blockposition.a(i, 0, j + 1), EnumLogVariant.SPRUCE) && this.a(world, blockposition.a(i + 1, 0, j + 1), EnumLogVariant.SPRUCE)) {
+                        treeType = TreeType.MEGA_REDWOOD; // CraftBukkit
                         object = new WorldGenMegaTree(false, random.nextBoolean());
                         flag = true;
                         break label78;
@@ -56,11 +100,13 @@
             if (!flag) {
                 j = 0;
                 i = 0;
+                treeType = TreeType.REDWOOD; // CraftBukkit
                 object = new WorldGenTaiga2(true);
             }
             break;
 
         case 2:
+            treeType = TreeType.BIRCH; // CraftBukkit
             object = new WorldGenForest(true, false);
             break;
 
@@ -69,6 +115,7 @@
             for (i = 0; i >= -1; --i) {
                 for (j = 0; j >= -1; --j) {
                     if (this.a(world, blockposition.a(i, 0, j), EnumLogVariant.JUNGLE) && this.a(world, blockposition.a(i + 1, 0, j), EnumLogVariant.JUNGLE) && this.a(world, blockposition.a(i, 0, j + 1), EnumLogVariant.JUNGLE) && this.a(world, blockposition.a(i + 1, 0, j + 1), EnumLogVariant.JUNGLE)) {
+                        treeType = TreeType.JUNGLE; // CraftBukkit
                         object = new WorldGenJungleTree(true, 10, 20, EnumLogVariant.JUNGLE.a(), EnumLogVariant.JUNGLE.a());
                         flag = true;
                         break label93;
@@ -79,11 +126,13 @@
             if (!flag) {
                 j = 0;
                 i = 0;
+                treeType = TreeType.SMALL_JUNGLE; // CraftBukkit
                 object = new WorldGenTrees(true, 4 + random.nextInt(7), EnumLogVariant.JUNGLE.a(), EnumLogVariant.JUNGLE.a(), false);
             }
             break;
 
         case 4:
+            treeType = TreeType.ACACIA; // CraftBukki
             object = new WorldGenAcaciaTree(true);
             break;
 
@@ -92,6 +141,7 @@
             for (i = 0; i >= -1; --i) {
                 for (j = 0; j >= -1; --j) {
                     if (this.a(world, blockposition.a(i, 0, j), EnumLogVariant.DARK_OAK) && this.a(world, blockposition.a(i + 1, 0, j), EnumLogVariant.DARK_OAK) && this.a(world, blockposition.a(i, 0, j + 1), EnumLogVariant.DARK_OAK) && this.a(world, blockposition.a(i + 1, 0, j + 1), EnumLogVariant.DARK_OAK)) {
+                        treeType = TreeType.DARK_OAK; // CraftBukkit
                         object = new WorldGenForestTree(true);
                         flag = true;
                         break label108;