Paper/src/main/java/net/minecraft/server/BlockLeaves.java

204 Zeilen
7.0 KiB
Java

2011-01-04 23:09:40 +01:00
package net.minecraft.server;
import java.util.Random;
import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit
2011-01-04 23:09:40 +01:00
2013-11-04 14:07:38 +01:00
public abstract class BlockLeaves extends BlockTransparent {
2011-01-04 23:09:40 +01:00
2013-11-04 14:07:38 +01:00
int[] a;
protected IIcon[][] M = new IIcon[2][];
2011-01-04 23:09:40 +01:00
2013-11-04 14:07:38 +01:00
public BlockLeaves() {
super(Material.LEAVES, false);
this.a(true);
2012-07-29 09:33:13 +02:00
this.a(CreativeModeTab.c);
2013-11-04 14:07:38 +01:00
this.c(0.2F);
this.g(1);
this.a(h);
2011-01-04 23:09:40 +01:00
}
2013-11-04 14:07:38 +01:00
public void remove(World world, int i, int j, int k, Block block, int l) {
2011-01-29 22:50:29 +01:00
byte b0 = 1;
2013-11-04 14:07:38 +01:00
int i1 = b0 + 1;
2011-01-04 23:09:40 +01:00
2013-11-04 14:07:38 +01:00
if (world.b(i - i1, j - i1, k - i1, i + i1, j + i1, k + i1)) {
for (int j1 = -b0; j1 <= b0; ++j1) {
for (int k1 = -b0; k1 <= b0; ++k1) {
for (int l1 = -b0; l1 <= b0; ++l1) {
if (world.getType(i + j1, j + k1, k + l1).getMaterial() == Material.LEAVES) {
int i2 = world.getData(i + j1, j + k1, k + l1);
2011-01-04 23:09:40 +01:00
2013-11-04 14:07:38 +01:00
world.setData(i + j1, j + k1, k + l1, i2 | 8, 4);
2011-01-04 23:09:40 +01:00
}
}
}
}
}
}
2013-03-13 23:33:27 +01:00
public void a(World world, int i, int j, int k, Random random) {
2011-01-29 22:50:29 +01:00
if (!world.isStatic) {
int l = world.getData(i, j, k);
2011-09-15 02:23:52 +02:00
if ((l & 8) != 0 && (l & 4) == 0) {
2011-01-29 22:50:29 +01:00
byte b0 = 4;
int i1 = b0 + 1;
byte b1 = 32;
int j1 = b1 * b1;
int k1 = b1 / 2;
2013-11-04 14:07:38 +01:00
if (this.a == null) {
this.a = new int[b1 * b1 * b1];
2011-01-29 22:50:29 +01:00
}
2011-01-04 23:09:40 +01:00
2011-01-29 22:50:29 +01:00
int l1;
2013-11-04 14:07:38 +01:00
if (world.b(i - i1, j - i1, k - i1, i + i1, j + i1, k + i1)) {
2011-01-29 22:50:29 +01:00
int i2;
int j2;
for (l1 = -b0; l1 <= b0; ++l1) {
for (i2 = -b0; i2 <= b0; ++i2) {
for (j2 = -b0; j2 <= b0; ++j2) {
2013-11-04 14:07:38 +01:00
Block block = world.getType(i + l1, j + i2, k + j2);
if (block != Blocks.LOG && block != Blocks.LOG2) {
if (block.getMaterial() == Material.LEAVES) {
this.a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
} else {
this.a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
}
2011-01-29 22:50:29 +01:00
} else {
2013-11-04 14:07:38 +01:00
this.a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;
2011-01-29 22:50:29 +01:00
}
2011-01-04 23:09:40 +01:00
}
}
}
2011-01-29 22:50:29 +01:00
for (l1 = 1; l1 <= 4; ++l1) {
for (i2 = -b0; i2 <= b0; ++i2) {
for (j2 = -b0; j2 <= b0; ++j2) {
2013-11-04 14:07:38 +01:00
for (int k2 = -b0; k2 <= b0; ++k2) {
if (this.a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1) {
if (this.a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
this.a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
this.a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2) {
this.a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2) {
this.a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2) {
this.a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
2011-01-29 22:50:29 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2) {
this.a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;
2011-01-29 22:50:29 +01:00
}
}
2011-01-04 23:09:40 +01:00
}
}
}
}
}
2013-11-04 14:07:38 +01:00
l1 = this.a[k1 * j1 + k1 * b1 + k1];
2011-01-29 22:50:29 +01:00
if (l1 >= 0) {
2013-03-13 23:33:27 +01:00
world.setData(i, j, k, l & -9, 4);
2011-01-29 22:50:29 +01:00
} else {
2013-11-04 14:07:38 +01:00
this.e(world, i, j, k);
2011-01-29 22:50:29 +01:00
}
2011-01-04 23:09:40 +01:00
}
}
}
2013-11-04 14:07:38 +01:00
private void e(World world, int i, int j, int k) {
// CraftBukkit start
LeavesDecayEvent event = new LeavesDecayEvent(world.getWorld().getBlockAt(i, j, k));
world.getServer().getPluginManager().callEvent(event);
2012-07-29 09:33:13 +02:00
if (event.isCancelled()) {
return;
}
// CraftBukkit end
2011-01-04 23:09:40 +01:00
2013-11-04 14:07:38 +01:00
this.b(world, i, j, k, world.getData(i, j, k), 0);
2013-03-13 23:33:27 +01:00
world.setAir(i, j, k);
2011-01-04 23:09:40 +01:00
}
public int a(Random random) {
2011-04-20 22:47:26 +02:00
return random.nextInt(20) == 0 ? 1 : 0;
2011-01-04 23:09:40 +01:00
}
2013-11-04 14:07:38 +01:00
public Item getDropType(int i, Random random, int j) {
return Item.getItemOf(Blocks.SAPLING);
2011-01-04 23:09:40 +01:00
}
2012-01-12 23:10:13 +01:00
public void dropNaturally(World world, int i, int j, int k, int l, float f, int i1) {
2012-03-01 11:49:23 +01:00
if (!world.isStatic) {
2013-11-04 14:07:38 +01:00
int j1 = this.b(l);
2012-03-01 11:49:23 +01:00
2013-03-13 23:33:27 +01:00
if (i1 > 0) {
j1 -= 2 << i1;
if (j1 < 10) {
j1 = 10;
}
}
if (world.random.nextInt(j1) == 0) {
2013-11-04 14:07:38 +01:00
Item item = this.getDropType(l, world.random, i1);
2013-03-13 23:33:27 +01:00
2013-11-04 14:07:38 +01:00
this.a(world, i, j, k, new ItemStack(item, 1, this.getDropData(l)));
2013-03-13 23:33:27 +01:00
}
2012-03-01 11:49:23 +01:00
2013-03-13 23:33:27 +01:00
j1 = 200;
if (i1 > 0) {
j1 -= 10 << i1;
if (j1 < 40) {
j1 = 40;
}
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
this.c(world, i, j, k, l, j1);
2012-01-12 23:10:13 +01:00
}
}
2013-11-04 14:07:38 +01:00
protected void c(World world, int i, int j, int k, int l, int i1) {}
protected int b(int i) {
return 20;
}
2011-06-30 00:02:25 +02:00
public void a(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
2013-11-04 14:07:38 +01:00
if (!world.isStatic && entityhuman.bD() != null && entityhuman.bD().getItem() == Items.SHEARS) {
entityhuman.a(StatisticList.C[Block.b((Block) this)], 1);
this.a(world, i, j, k, new ItemStack(Item.getItemOf(this), 1, l & 3));
2011-06-30 00:02:25 +02:00
} else {
super.a(world, entityhuman, i, j, k, l);
}
}
public int getDropData(int i) {
2011-04-20 22:47:26 +02:00
return i & 3;
}
public boolean c() {
2013-11-04 14:07:38 +01:00
return !this.P;
2011-01-04 23:09:40 +01:00
}
2012-12-20 05:03:52 +01:00
2013-11-04 14:07:38 +01:00
protected ItemStack j(int i) {
return new ItemStack(Item.getItemOf(this), 1, i & 3);
2012-12-20 05:03:52 +01:00
}
2013-11-04 14:07:38 +01:00
public abstract String[] e();
2011-01-04 23:09:40 +01:00
}