2011-05-16 05:52:11 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-12-09 17:11:56 +01:00
|
|
|
import java.util.ArrayList;
|
2011-05-16 05:52:11 +02:00
|
|
|
import java.util.Random;
|
2011-12-09 17:11:56 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.BlockChangeDelegate;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.TreeType;
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
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 {
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(World world, int i, int j, int k, Random random) {
|
2011-05-26 14:48:22 +02:00
|
|
|
if (!world.isStatic) {
|
|
|
|
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) {
|
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-12 12:02:39 +01:00
|
|
|
this.b(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;
|
|
|
|
return j == 1 ? 63 : (j == 2 ? 79 : super.a(i, j));
|
|
|
|
}
|
|
|
|
|
2011-12-09 17:11:56 +01:00
|
|
|
// CraftBukkit - added bonemeal, player and itemstack
|
|
|
|
public void b(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
|
2011-05-16 05:52:11 +02:00
|
|
|
int l = world.getData(i, j, k) & 3;
|
|
|
|
|
|
|
|
world.setRawTypeId(i, j, k, 0);
|
|
|
|
|
|
|
|
// CraftBukkit start - fixes client updates on recently grown trees
|
|
|
|
boolean grownTree;
|
|
|
|
BlockChangeWithNotify delegate = new BlockChangeWithNotify(world);
|
2011-12-09 17:11:56 +01:00
|
|
|
StructureGrowEvent event = null;
|
|
|
|
Location location = new Location(world.getWorld(), i, j, k);
|
2011-11-20 09:01:14 +01:00
|
|
|
// All of these are 'false' because we need the 'raw' calls so the block-delegate works
|
2011-05-16 05:52:11 +02:00
|
|
|
if (l == 1) {
|
2011-12-09 17:11:56 +01:00
|
|
|
event = new StructureGrowEvent(location, TreeType.REDWOOD, bonemeal, player, new ArrayList<BlockState>());
|
|
|
|
grownTree = new WorldGenTaiga2(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
2011-05-16 05:52:11 +02:00
|
|
|
} else if (l == 2) {
|
2011-12-09 17:11:56 +01:00
|
|
|
event = new StructureGrowEvent(location, TreeType.BIRCH, bonemeal, player, new ArrayList<BlockState>());
|
|
|
|
grownTree = new WorldGenForest(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
2011-05-16 05:52:11 +02:00
|
|
|
} else {
|
|
|
|
if (random.nextInt(10) == 0) {
|
2011-12-09 17:11:56 +01:00
|
|
|
event = new StructureGrowEvent(location, TreeType.BIG_TREE, bonemeal, player, new ArrayList<BlockState>());
|
|
|
|
grownTree = new WorldGenBigTree(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
2011-05-16 05:52:11 +02:00
|
|
|
} else {
|
2011-12-09 17:11:56 +01:00
|
|
|
event = new StructureGrowEvent(location, TreeType.TREE, bonemeal, player, new ArrayList<BlockState>());
|
|
|
|
grownTree = new WorldGenTrees(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 17:11:56 +01:00
|
|
|
if (event == null) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-19 17:41:55 +01:00
|
|
|
if (event.isFromBonemeal() && itemstack != null) {
|
|
|
|
--itemstack.count;
|
|
|
|
}
|
2011-12-09 17:11:56 +01:00
|
|
|
if (!grownTree || event.isCancelled()) {
|
2011-05-16 05:52:11 +02:00
|
|
|
world.setRawTypeIdAndData(i, j, k, this.id, l);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
protected int getDropData(int i) {
|
2011-05-16 05:52:11 +02:00
|
|
|
return i & 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
private class BlockChangeWithNotify implements BlockChangeDelegate {
|
2011-12-19 17:41:55 +01:00
|
|
|
|
2011-05-16 05:52:11 +02:00
|
|
|
World world;
|
|
|
|
|
2011-12-09 17:11:56 +01:00
|
|
|
BlockChangeWithNotify(World world) {
|
|
|
|
this.world = world;
|
|
|
|
}
|
2011-05-16 05:52:11 +02:00
|
|
|
|
|
|
|
public boolean setRawTypeId(int x, int y, int z, int type) {
|
2011-06-27 00:25:01 +02:00
|
|
|
return this.world.setTypeId(x, y, z, type);
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean setRawTypeIdAndData(int x, int y, int z, int type, int data) {
|
2011-06-27 00:25:01 +02:00
|
|
|
return this.world.setTypeIdAndData(x, y, z, type, data);
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getTypeId(int x, int y, int z) {
|
2011-06-27 00:25:01 +02:00
|
|
|
return this.world.getTypeId(x, y, z);
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
2011-09-25 00:14:13 +02:00
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
return world.height;
|
|
|
|
}
|
2011-05-16 05:52:11 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|