--- a/net/minecraft/server/BlockSapling.java +++ b/net/minecraft/server/BlockSapling.java @@ -2,11 +2,19 @@ import java.util.Random; +// CraftBukkit start +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.au; 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); @@ -23,7 +31,30 @@ public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, Random random) { super.tick(iblockdata, worldserver, blockposition, random); if (worldserver.getLightLevel(blockposition.up()) >= 9 && random.nextInt(7) == 0) { + // CraftBukkit start + worldserver.captureTreeGeneration = true; + // CraftBukkit end this.grow(worldserver, blockposition, iblockdata, random); + // CraftBukkit start + worldserver.captureTreeGeneration = false; + if (worldserver.capturedBlockStates.size() > 0) { + TreeType treeType = BlockSapling.treeType; + BlockSapling.treeType = null; + Location location = new Location(worldserver.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()); + java.util.List blocks = new java.util.ArrayList<>(worldserver.capturedBlockStates.values()); + worldserver.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 } }