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;
|
2013-11-04 14:07:38 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftBlockChangeDelegate;
|
2011-12-23 00:54:34 +01:00
|
|
|
import org.bukkit.craftbukkit.util.StructureGrowDelegate;
|
2013-03-25 05:22:32 +01:00
|
|
|
import org.bukkit.entity.Player;
|
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
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public class BlockSapling extends BlockPlant implements IBlockFragilePlantElement {
|
2011-05-16 05:52:11 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public static final String[] a = new String[] { "oak", "spruce", "birch", "jungle", "acacia", "roofed_oak"};
|
|
|
|
private static final IIcon[] b = new IIcon[a.length];
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected BlockSapling() {
|
2011-05-16 05:52:11 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void a(World world, int i, int j, int k, Random random) {
|
2011-05-26 14:48:22 +02:00
|
|
|
if (!world.isStatic) {
|
2013-03-13 23:33:27 +01:00
|
|
|
super.a(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) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.grow(world, i, j, k, random, false, null, null); // CraftBukkit - added bonemeal, player and itemstack
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
// CraftBukkit - added bonemeal, player and itemstack
|
2013-03-25 05:22:32 +01:00
|
|
|
public void grow(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
|
2013-03-13 23:33:27 +01:00
|
|
|
int l = world.getData(i, j, k);
|
|
|
|
|
|
|
|
if ((l & 8) == 0) {
|
|
|
|
world.setData(i, j, k, l | 8, 4);
|
|
|
|
} else {
|
|
|
|
this.d(world, i, j, k, random, bonemeal, player, itemstack); // CraftBukkit
|
|
|
|
}
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit - Added bonemeal, player and itemstack
|
|
|
|
public void d(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
|
2013-11-04 14:07:38 +01:00
|
|
|
int l = world.getData(i, j, k) & 7;
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Records tree generation and calls StructureGrowEvent
|
2012-03-16 07:32:25 +01:00
|
|
|
StructureGrowDelegate delegate = new StructureGrowDelegate(world);
|
|
|
|
TreeType treeType = null;
|
2012-03-02 10:50:18 +01:00
|
|
|
boolean grownTree = false;
|
2013-11-04 14:07:38 +01:00
|
|
|
// Turn ternary operator into if statement to set treeType
|
|
|
|
//Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
|
|
|
|
TreeGenerator object; // Changed to TreeGenerator
|
|
|
|
if (random.nextInt(10) == 0) {
|
|
|
|
treeType = TreeType.BIG_TREE;
|
|
|
|
object = new WorldGenBigTree(true);
|
|
|
|
} else {
|
|
|
|
treeType = TreeType.TREE;
|
|
|
|
object = new WorldGenTrees(true);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
int i1 = 0;
|
|
|
|
int j1 = 0;
|
|
|
|
boolean flag = false;
|
|
|
|
|
|
|
|
switch (l) {
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
break;
|
2012-03-16 07:32:25 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
case 1:
|
|
|
|
treeType = TreeType.REDWOOD; // CraftBukkit
|
|
|
|
label78:
|
2012-03-02 10:50:18 +01:00
|
|
|
for (i1 = 0; i1 >= -1; --i1) {
|
|
|
|
for (j1 = 0; j1 >= -1; --j1) {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.a(world, i + i1, j, k + j1, 1) && this.a(world, i + i1 + 1, j, k + j1, 1) && this.a(world, i + i1, j, k + j1 + 1, 1) && this.a(world, i + i1 + 1, j, k + j1 + 1, 1)) {
|
|
|
|
object = new WorldGenMegaTree(false, random.nextBoolean());
|
2012-03-16 07:32:25 +01:00
|
|
|
flag = true;
|
2013-11-04 14:07:38 +01:00
|
|
|
break label78;
|
2012-03-02 10:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2013-11-04 14:07:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
j1 = 0;
|
|
|
|
i1 = 0;
|
|
|
|
object = new WorldGenTaiga2(true);
|
|
|
|
}
|
|
|
|
break;
|
2012-03-16 07:32:25 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
case 2:
|
|
|
|
treeType = TreeType.BIRCH; // CraftBukkit
|
|
|
|
object = new WorldGenForest(true, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
label93:
|
|
|
|
for (i1 = 0; i1 >= -1; --i1) {
|
|
|
|
for (j1 = 0; j1 >= -1; --j1) {
|
|
|
|
if (this.a(world, i + i1, j, k + j1, 3) && this.a(world, i + i1 + 1, j, k + j1, 3) && this.a(world, i + i1, j, k + j1 + 1, 3) && this.a(world, i + i1 + 1, j, k + j1 + 1, 3)) {
|
|
|
|
treeType = TreeType.JUNGLE; // CraftBukkit
|
|
|
|
object = new WorldGenJungleTree(true, 10, 20, 3, 3);
|
|
|
|
flag = true;
|
|
|
|
break label93;
|
|
|
|
}
|
2012-03-16 07:32:25 +01:00
|
|
|
}
|
2012-03-02 10:50:18 +01:00
|
|
|
}
|
2012-03-16 07:32:25 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (!flag) {
|
2012-03-02 10:50:18 +01:00
|
|
|
j1 = 0;
|
|
|
|
i1 = 0;
|
2013-11-04 14:07:38 +01:00
|
|
|
treeType = TreeType.SMALL_JUNGLE; // CraftBukkit
|
|
|
|
object = new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false);
|
2012-03-02 10:50:18 +01:00
|
|
|
}
|
2013-11-04 14:07:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
treeType = TreeType.ACACIA; // CraftBukkit
|
|
|
|
object = new WorldGenAcaciaTree(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
label108:
|
|
|
|
for (i1 = 0; i1 >= -1; --i1) {
|
|
|
|
for (j1 = 0; j1 >= -1; --j1) {
|
|
|
|
if (this.a(world, i + i1, j, k + j1, 5) && this.a(world, i + i1 + 1, j, k + j1, 5) && this.a(world, i + i1, j, k + j1 + 1, 5) && this.a(world, i + i1 + 1, j, k + j1 + 1, 5)) {
|
|
|
|
object = new WorldGenForestTree(true);
|
|
|
|
treeType = TreeType.DARK_OAK; // CraftBukkit
|
|
|
|
flag = true;
|
|
|
|
break label108;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
return;
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
2011-12-23 00:54:34 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
Block block = Blocks.AIR;
|
|
|
|
|
2012-03-16 07:32:25 +01:00
|
|
|
if (flag) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i + i1, j, k + j1, block, 0, 4);
|
|
|
|
world.setTypeAndData(i + i1 + 1, j, k + j1, block, 0, 4);
|
|
|
|
world.setTypeAndData(i + i1, j, k + j1 + 1, block, 0, 4);
|
|
|
|
world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, block, 0, 4);
|
2012-03-16 07:32:25 +01:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i, j, k, block, 0, 4);
|
2012-03-16 07:32:25 +01:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
grownTree = object.generate(new CraftBlockChangeDelegate(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;
|
|
|
|
}
|
|
|
|
}
|
2013-03-16 14:05:03 +01:00
|
|
|
} else if (bonemeal && itemstack != null) {
|
|
|
|
// We always consume bonemeal when trying to grow
|
|
|
|
--itemstack.count;
|
2011-12-19 17:41:55 +01:00
|
|
|
}
|
2013-11-04 14:07:38 +01:00
|
|
|
// No need to generate the tree again.
|
2011-12-23 00:54:34 +01:00
|
|
|
if (!grownTree) {
|
2013-11-04 14:07:38 +01:00
|
|
|
// CraftBukkit end
|
2012-03-16 07:32:25 +01:00
|
|
|
if (flag) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i + i1, j, k + j1, this, l, 4);
|
|
|
|
world.setTypeAndData(i + i1 + 1, j, k + j1, this, l, 4);
|
|
|
|
world.setTypeAndData(i + i1, j, k + j1 + 1, this, l, 4);
|
|
|
|
world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, this, l, 4);
|
2012-03-02 10:50:18 +01:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i, j, k, this, l, 4);
|
2012-03-02 10:50:18 +01:00
|
|
|
}
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean a(World world, int i, int j, int k, int l) {
|
|
|
|
return world.getType(i, j, k) == this && (world.getData(i, j, k) & 7) == l;
|
2012-03-22 21:39:39 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public int getDropData(int i) {
|
2013-11-04 14:07:38 +01:00
|
|
|
return MathHelper.a(i & 7, 0, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(World world, int i, int j, int k, boolean flag) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(World world, Random random, int i, int j, int k) {
|
|
|
|
return (double) world.random.nextFloat() < 0.45D;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(World world, Random random, int i, int j, int k) {
|
|
|
|
this.grow(world, i, j, k, random, false, null, null); // CraftBukkit - added bonemeal, player and itemstack
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
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);
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean generate(org.bukkit.craftbukkit.CraftBlockChangeDelegate 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
|
|
|
}
|