2011-05-16 05:52:11 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2012-07-22 08:18:00 +02:00
|
|
|
|
2011-12-09 17:11:56 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.TreeType;
|
2011-12-23 00:54:34 +01:00
|
|
|
import org.bukkit.craftbukkit.util.StructureGrowDelegate;
|
2011-12-09 17:11:56 +01:00
|
|
|
import org.bukkit.event.world.StructureGrowEvent;
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2011-05-16 05:52:11 +02:00
|
|
|
|
|
|
|
public class BlockSapling extends BlockFlower {
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public static final String[] a = new String[] { "oak", "spruce", "birch", "jungle"};
|
|
|
|
|
2011-05-16 05:52:11 +02:00
|
|
|
protected BlockSapling(int i, int j) {
|
|
|
|
super(i, j);
|
|
|
|
float f = 0.4F;
|
|
|
|
|
|
|
|
this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(CreativeModeTab.c);
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void b(World world, int i, int j, int k, Random random) {
|
2011-05-26 14:48:22 +02:00
|
|
|
if (!world.isStatic) {
|
2012-07-29 09:33:13 +02:00
|
|
|
super.b(world, i, j, k, random);
|
2011-11-20 09:01:14 +01:00
|
|
|
if (world.getLightLevel(i, j + 1, k) >= 9 && random.nextInt(7) == 0) {
|
2011-05-26 14:48:22 +02:00
|
|
|
int l = world.getData(i, j, k);
|
|
|
|
|
|
|
|
if ((l & 8) == 0) {
|
|
|
|
world.setData(i, j, k, l | 8);
|
|
|
|
} else {
|
2012-01-14 21:03:48 +01:00
|
|
|
this.grow(world, i, j, k, random, false, null, null); // CraftBukkit - added bonemeal, player and itemstack
|
2011-05-26 14:48:22 +02:00
|
|
|
}
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int a(int i, int j) {
|
|
|
|
j &= 3;
|
2012-03-01 11:49:23 +01:00
|
|
|
return j == 1 ? 63 : (j == 2 ? 79 : (j == 3 ? 30 : super.a(i, j)));
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
|
2011-12-09 17:11:56 +01:00
|
|
|
// CraftBukkit - added bonemeal, player and itemstack
|
2012-07-22 08:18:00 +02:00
|
|
|
public void grow(World world, int i, int j, int k, Random random, boolean bonemeal, org.bukkit.entity.Player player, ItemStack itemstack) {
|
2011-05-16 05:52:11 +02:00
|
|
|
int l = world.getData(i, j, k) & 3;
|
2012-03-02 10:50:18 +01:00
|
|
|
int i1 = 0;
|
|
|
|
int j1 = 0;
|
2012-07-29 09:33:13 +02:00
|
|
|
boolean flag = false;
|
2012-03-16 07:32:25 +01:00
|
|
|
// CraftBukkit start - records tree generation and calls StructureGrowEvent
|
|
|
|
StructureGrowDelegate delegate = new StructureGrowDelegate(world);
|
|
|
|
TreeType treeType = null;
|
|
|
|
TreeGenerator gen = null;
|
2012-03-02 10:50:18 +01:00
|
|
|
boolean grownTree = false;
|
2012-03-16 07:32:25 +01:00
|
|
|
|
2011-05-16 05:52:11 +02:00
|
|
|
if (l == 1) {
|
2011-12-23 00:54:34 +01:00
|
|
|
treeType = TreeType.REDWOOD;
|
2012-03-16 07:32:25 +01:00
|
|
|
gen = new WorldGenTaiga2(false);
|
2011-05-16 05:52:11 +02:00
|
|
|
} else if (l == 2) {
|
2011-12-23 00:54:34 +01:00
|
|
|
treeType = TreeType.BIRCH;
|
2012-03-16 07:32:25 +01:00
|
|
|
gen = new WorldGenForest(false);
|
2012-03-02 10:50:18 +01:00
|
|
|
} else if (l == 3) {
|
|
|
|
for (i1 = 0; i1 >= -1; --i1) {
|
|
|
|
for (j1 = 0; j1 >= -1; --j1) {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.d(world, i + i1, j, k + j1, 3) && this.d(world, i + i1 + 1, j, k + j1, 3) && this.d(world, i + i1, j, k + j1 + 1, 3) && this.d(world, i + i1 + 1, j, k + j1 + 1, 3)) {
|
2012-03-16 07:32:25 +01:00
|
|
|
treeType = TreeType.JUNGLE;
|
|
|
|
gen = new WorldGenMegaTree(false, 10 + random.nextInt(20), 3, 3);
|
|
|
|
flag = true;
|
2012-03-02 10:50:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 07:32:25 +01:00
|
|
|
|
|
|
|
if (gen != null) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-02 10:50:18 +01:00
|
|
|
}
|
2012-03-16 07:32:25 +01:00
|
|
|
|
|
|
|
if (gen == null) {
|
2012-03-02 10:50:18 +01:00
|
|
|
j1 = 0;
|
|
|
|
i1 = 0;
|
2012-03-14 03:38:39 +01:00
|
|
|
treeType = TreeType.SMALL_JUNGLE;
|
2012-03-16 07:32:25 +01:00
|
|
|
gen = new WorldGenTrees(false, 4 + random.nextInt(7), 3, 3, false);
|
2012-03-02 10:50:18 +01:00
|
|
|
}
|
2011-05-16 05:52:11 +02:00
|
|
|
} else {
|
2012-03-16 07:32:25 +01:00
|
|
|
treeType = TreeType.TREE;
|
|
|
|
gen = new WorldGenTrees(false);
|
2011-05-16 05:52:11 +02:00
|
|
|
if (random.nextInt(10) == 0) {
|
2011-12-23 00:54:34 +01:00
|
|
|
treeType = TreeType.BIG_TREE;
|
2012-03-16 07:32:25 +01:00
|
|
|
gen = new WorldGenBigTree(false);
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
2011-12-23 00:54:34 +01:00
|
|
|
|
2012-03-16 07:32:25 +01:00
|
|
|
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);
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-03-16 07:32:25 +01:00
|
|
|
grownTree = gen.generate(delegate, random, i + i1, j, k + j1);
|
2011-12-23 00:54:34 +01:00
|
|
|
if (grownTree) {
|
|
|
|
Location location = new Location(world.getWorld(), i, j, k);
|
|
|
|
StructureGrowEvent event = new StructureGrowEvent(location, treeType, bonemeal, player, delegate.getBlocks());
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.Bukkit.getPluginManager().callEvent(event);
|
2011-12-23 00:54:34 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
grownTree = false;
|
|
|
|
} else {
|
2012-07-22 08:18:00 +02:00
|
|
|
for (org.bukkit.block.BlockState state : event.getBlocks()) {
|
2011-12-23 00:54:34 +01:00
|
|
|
state.update(true);
|
|
|
|
}
|
|
|
|
if (event.isFromBonemeal() && itemstack != null) {
|
|
|
|
--itemstack.count;
|
|
|
|
}
|
|
|
|
}
|
2011-12-19 17:41:55 +01:00
|
|
|
}
|
2011-12-23 00:54:34 +01:00
|
|
|
if (!grownTree) {
|
2012-03-16 07:32:25 +01:00
|
|
|
if (flag) {
|
2012-03-02 10:50:18 +01:00
|
|
|
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);
|
|
|
|
world.setRawTypeIdAndData(i + i1 + 1, j, k + j1 + 1, this.id, l);
|
|
|
|
} else {
|
|
|
|
world.setRawTypeIdAndData(i, j, k, this.id, l);
|
|
|
|
}
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
2012-03-16 07:32:25 +01:00
|
|
|
// CraftBukkit end
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean d(World world, int i, int j, int k, int l) {
|
2012-03-22 21:39:39 +01:00
|
|
|
return world.getTypeId(i, j, k) == this.id && (world.getData(i, j, k) & 3) == l;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public int getDropData(int i) {
|
2011-05-16 05:52:11 +02:00
|
|
|
return i & 3;
|
|
|
|
}
|
2012-03-16 07:32:25 +01:00
|
|
|
|
|
|
|
// CraftBukkit start
|
2012-03-14 03:38:39 +01:00
|
|
|
public interface TreeGenerator {
|
2012-03-16 07:32:25 +01:00
|
|
|
|
|
|
|
public boolean a(World world, Random random, int i, int j, int k);
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
public boolean generate(org.bukkit.BlockChangeDelegate world, Random random, int i, int j, int k);
|
2012-03-16 07:32:25 +01:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|