diff --git a/src/main/java/net/minecraft/server/BlockSapling.java b/src/main/java/net/minecraft/server/BlockSapling.java index a22aac91fa..3f437bead3 100644 --- a/src/main/java/net/minecraft/server/BlockSapling.java +++ b/src/main/java/net/minecraft/server/BlockSapling.java @@ -2,6 +2,7 @@ package net.minecraft.server; import java.util.Random; // CraftBukkit start +import org.bukkit.BlockChangeDelegate; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.TreeType; @@ -43,56 +44,61 @@ public class BlockSapling extends BlockFlower { // CraftBukkit - added bonemeal, player and itemstack public void grow(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) { int l = world.getData(i, j, k) & 3; - - // CraftBukkit start - records tree generation and calls StructureGrowEvent - StructureGrowDelegate delegate = new StructureGrowDelegate(world); - TreeType treeType; int i1 = 0; int j1 = 0; + // CraftBukkit start - records tree generation and calls StructureGrowEvent + StructureGrowDelegate delegate = new StructureGrowDelegate(world); + TreeType treeType = null; + TreeGenerator gen = null; boolean grownTree = false; - boolean megaTree = false; - // All of these are 'false' because we need the 'raw' calls so the block-delegate works + boolean flag = false; + if (l == 1) { treeType = TreeType.REDWOOD; - world.setRawTypeId(i, j, k, 0); - grownTree = new WorldGenTaiga2(false).generate(delegate, random, i, j, k); + gen = new WorldGenTaiga2(false); } else if (l == 2) { treeType = TreeType.BIRCH; - world.setRawTypeId(i, j, k, 0); - grownTree = new WorldGenForest(false).generate(delegate, random, i, j, k); + gen = new WorldGenForest(false); } else if (l == 3) { - treeType = TreeType.JUNGLE; for (i1 = 0; i1 >= -1; --i1) { for (j1 = 0; j1 >= -1; --j1) { if (world.getTypeId(i + i1, j, k + j1) == this.id && world.getTypeId(i + i1 + 1, j, k + j1) == this.id && world.getTypeId(i + i1, j, k + j1 + 1) == this.id && world.getTypeId(i + i1 + 1, j, k + j1 + 1) == this.id) { - world.setRawTypeId(i + i1, j, k + j1, 0); - world.setRawTypeId(i + i1 + 1, j, k + j1, 0); - world.setRawTypeId(i + i1, j, k + j1 + 1, 0); - world.setRawTypeId(i + i1 + 1, j, k + j1 + 1, 0); - grownTree = new WorldGenMegaTree(false, 10 + random.nextInt(20), 3, 3).generate(delegate, random, i + i1, j, k + j1); - megaTree = true; + treeType = TreeType.JUNGLE; + gen = new WorldGenMegaTree(false, 10 + random.nextInt(20), 3, 3); + flag = true; break; } } + + if (gen != null) { + break; + } } - if (!grownTree) { + + if (gen == null) { j1 = 0; i1 = 0; - world.setRawTypeId(i, j, k, 0); - grownTree = new WorldGenTrees(false, 4 + random.nextInt(7), 3, 3, false).generate(delegate, random, i, j, k); + treeType = TreeType.TREE; + gen = new WorldGenTrees(false, 4 + random.nextInt(7), 3, 3, false); } } else { + treeType = TreeType.TREE; + gen = new WorldGenTrees(false); if (random.nextInt(10) == 0) { treeType = TreeType.BIG_TREE; - world.setRawTypeId(i, j, k, 0); - grownTree = new WorldGenBigTree(false).generate(delegate, random, i, j, k); - } else { - treeType = TreeType.TREE; - world.setRawTypeId(i, j, k, 0); - grownTree = new WorldGenTrees(false).generate(delegate, random, i, j, k); + gen = new WorldGenBigTree(false); } } + if (flag) { + world.setRawTypeId(i + i1, j, k + j1, 0); + world.setRawTypeId(i + i1 + 1, j, k + j1, 0); + world.setRawTypeId(i + i1, j, k + j1 + 1, 0); + world.setRawTypeId(i + i1 + 1, j, k + j1 + 1, 0); + } else { + world.setRawTypeId(i, j, k, 0); + } + grownTree = gen.generate(delegate, random, i + i1, j, k + j1); if (grownTree) { Location location = new Location(world.getWorld(), i, j, k); StructureGrowEvent event = new StructureGrowEvent(location, treeType, bonemeal, player, delegate.getBlocks()); @@ -108,10 +114,8 @@ public class BlockSapling extends BlockFlower { } } } - if (!grownTree) { - if (megaTree) { - // CraftBukkit end + if (flag) { world.setRawTypeIdAndData(i + i1, j, k + j1, this.id, l); world.setRawTypeIdAndData(i + i1 + 1, j, k + j1, this.id, l); world.setRawTypeIdAndData(i + i1, j, k + j1 + 1, this.id, l); @@ -120,9 +124,19 @@ public class BlockSapling extends BlockFlower { world.setRawTypeIdAndData(i, j, k, this.id, l); } } + // CraftBukkit end } protected int getDropData(int i) { return i & 3; } + + // CraftBukkit start + interface TreeGenerator { + + public boolean a(World world, Random random, int i, int j, int k); + + public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k); + } + // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/WorldGenBigTree.java b/src/main/java/net/minecraft/server/WorldGenBigTree.java index c4d3f17a6a..864ab1c77e 100644 --- a/src/main/java/net/minecraft/server/WorldGenBigTree.java +++ b/src/main/java/net/minecraft/server/WorldGenBigTree.java @@ -4,7 +4,7 @@ import java.util.Random; import org.bukkit.BlockChangeDelegate; // CraftBukkit -public class WorldGenBigTree extends WorldGenerator { +public class WorldGenBigTree extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface static final byte[] a = new byte[] { (byte) 2, (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 1}; Random b = new Random(); diff --git a/src/main/java/net/minecraft/server/WorldGenForest.java b/src/main/java/net/minecraft/server/WorldGenForest.java index 0ea716f763..a792b1ed8f 100644 --- a/src/main/java/net/minecraft/server/WorldGenForest.java +++ b/src/main/java/net/minecraft/server/WorldGenForest.java @@ -4,7 +4,7 @@ import java.util.Random; import org.bukkit.BlockChangeDelegate; // CraftBukkit -public class WorldGenForest extends WorldGenerator { +public class WorldGenForest extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface public WorldGenForest(boolean flag) { super(flag); diff --git a/src/main/java/net/minecraft/server/WorldGenMegaTree.java b/src/main/java/net/minecraft/server/WorldGenMegaTree.java index 0a9da96512..736e63b3ac 100644 --- a/src/main/java/net/minecraft/server/WorldGenMegaTree.java +++ b/src/main/java/net/minecraft/server/WorldGenMegaTree.java @@ -4,7 +4,7 @@ import java.util.Random; import org.bukkit.BlockChangeDelegate; // CraftBukkit -public class WorldGenMegaTree extends WorldGenerator { +public class WorldGenMegaTree extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface private final int a; private final int b; diff --git a/src/main/java/net/minecraft/server/WorldGenTaiga1.java b/src/main/java/net/minecraft/server/WorldGenTaiga1.java index 2a82880570..edd3056c82 100644 --- a/src/main/java/net/minecraft/server/WorldGenTaiga1.java +++ b/src/main/java/net/minecraft/server/WorldGenTaiga1.java @@ -4,7 +4,7 @@ import java.util.Random; import org.bukkit.BlockChangeDelegate; // CraftBukkit -public class WorldGenTaiga1 extends WorldGenerator { +public class WorldGenTaiga1 extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface public WorldGenTaiga1() {} diff --git a/src/main/java/net/minecraft/server/WorldGenTaiga2.java b/src/main/java/net/minecraft/server/WorldGenTaiga2.java index 34367ab9b0..0f3a6d6f28 100644 --- a/src/main/java/net/minecraft/server/WorldGenTaiga2.java +++ b/src/main/java/net/minecraft/server/WorldGenTaiga2.java @@ -4,7 +4,7 @@ import java.util.Random; import org.bukkit.BlockChangeDelegate; // CraftBukkit -public class WorldGenTaiga2 extends WorldGenerator { +public class WorldGenTaiga2 extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface public WorldGenTaiga2(boolean flag) { super(flag); diff --git a/src/main/java/net/minecraft/server/WorldGenTrees.java b/src/main/java/net/minecraft/server/WorldGenTrees.java index 8bf16cd4a1..bc8f8facbb 100644 --- a/src/main/java/net/minecraft/server/WorldGenTrees.java +++ b/src/main/java/net/minecraft/server/WorldGenTrees.java @@ -4,7 +4,7 @@ import java.util.Random; import org.bukkit.BlockChangeDelegate; // CraftBukkit -public class WorldGenTrees extends WorldGenerator { +public class WorldGenTrees extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface private final int a; private final boolean b;