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

186 Zeilen
6.7 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
public class BlockLeaves extends BlockTransparant {
2011-01-04 23:09:40 +01:00
private int cD;
2012-07-29 09:33:13 +02:00
public static final String[] a = new String[] { "oak", "spruce", "birch", "jungle"};
int[] b;
2011-01-04 23:09:40 +01:00
protected BlockLeaves(int i, int j) {
2011-01-29 22:50:29 +01:00
super(i, j, Material.LEAVES, false);
this.cD = j;
2012-07-29 09:33:13 +02:00
this.b(true);
this.a(CreativeModeTab.c);
2011-01-04 23:09:40 +01:00
}
2012-07-29 09:33:13 +02:00
public void remove(World world, int i, int j, int k, int l, int i1) {
2011-01-29 22:50:29 +01:00
byte b0 = 1;
2012-07-29 09:33:13 +02:00
int j1 = b0 + 1;
2011-01-04 23:09:40 +01:00
if (world.d(i - j1, j - j1, k - j1, i + j1, j + j1, k + j1)) {
2012-07-29 09:33:13 +02:00
for (int k1 = -b0; k1 <= b0; ++k1) {
for (int l1 = -b0; l1 <= b0; ++l1) {
for (int i2 = -b0; i2 <= b0; ++i2) {
int j2 = world.getTypeId(i + k1, j + l1, k + i2);
2011-01-04 23:09:40 +01:00
2012-07-29 09:33:13 +02:00
if (j2 == Block.LEAVES.id) {
int k2 = world.getData(i + k1, j + l1, k + i2);
2011-01-14 14:31:10 +01:00
2012-07-29 09:33:13 +02:00
world.setRawData(i + k1, j + l1, k + i2, k2 | 8);
2011-01-04 23:09:40 +01:00
}
}
}
}
}
}
2012-07-29 09:33:13 +02:00
public void b(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;
2012-07-29 09:33:13 +02:00
if (this.b == null) {
this.b = 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;
if (world.d(i - i1, j - i1, k - i1, i + i1, j + i1, k + i1)) {
2011-01-29 22:50:29 +01:00
int i2;
int j2;
int k2;
for (l1 = -b0; l1 <= b0; ++l1) {
for (i2 = -b0; i2 <= b0; ++i2) {
for (j2 = -b0; j2 <= b0; ++j2) {
k2 = world.getTypeId(i + l1, j + i2, k + j2);
if (k2 == Block.LOG.id) {
2012-07-29 09:33:13 +02:00
this.b[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;
2011-01-29 22:50:29 +01:00
} else if (k2 == Block.LEAVES.id) {
2012-07-29 09:33:13 +02:00
this.b[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
2011-01-29 22:50:29 +01:00
} else {
2012-07-29 09:33:13 +02:00
this.b[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
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) {
for (k2 = -b0; k2 <= b0; ++k2) {
2012-07-29 09:33:13 +02:00
if (this.b[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1) {
if (this.b[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
this.b[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2012-07-29 09:33:13 +02:00
if (this.b[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
this.b[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2012-07-29 09:33:13 +02:00
if (this.b[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2) {
this.b[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2012-07-29 09:33:13 +02:00
if (this.b[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2) {
this.b[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
2011-01-29 22:50:29 +01:00
}
2012-07-29 09:33:13 +02:00
if (this.b[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2) {
this.b[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
2011-01-29 22:50:29 +01:00
}
2012-07-29 09:33:13 +02:00
if (this.b[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2) {
this.b[(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
}
}
}
}
}
2012-07-29 09:33:13 +02:00
l1 = this.b[k1 * j1 + k1 * b1 + k1];
2011-01-29 22:50:29 +01:00
if (l1 >= 0) {
2011-05-26 14:48:22 +02:00
world.setRawData(i, j, k, l & -9);
2011-01-29 22:50:29 +01:00
} else {
2012-07-29 09:33:13 +02:00
this.l(world, i, j, k);
2011-01-29 22:50:29 +01:00
}
2011-01-04 23:09:40 +01:00
}
}
}
2012-07-29 09:33:13 +02:00
private void l(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
2012-07-29 09:33:13 +02:00
this.c(world, i, j, k, world.getData(i, j, k), 0);
world.setTypeId(i, j, k, 0);
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
}
public int getDropType(int i, Random random, int j) {
2011-01-29 22:50:29 +01:00
return Block.SAPLING.id;
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) {
byte b0 = 20;
if ((l & 3) == 3) {
b0 = 40;
}
if (world.random.nextInt(b0) == 0) {
int j1 = this.getDropType(l, world.random, i1);
2012-11-06 13:05:28 +01:00
this.b(world, i, j, k, new ItemStack(j1, 1, this.getDropData(l)));
2012-03-01 11:49:23 +01:00
}
if ((l & 3) == 0 && world.random.nextInt(200) == 0) {
2012-11-06 13:05:28 +01:00
this.b(world, i, j, k, new ItemStack(Item.APPLE, 1, 0));
2012-03-01 11:49:23 +01:00
}
2012-01-12 23:10:13 +01:00
}
}
2011-06-30 00:02:25 +02:00
public void a(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
2012-11-06 13:05:28 +01:00
if (!world.isStatic && entityhuman.bT() != null && entityhuman.bT().id == Item.SHEARS.id) {
2011-06-30 00:02:25 +02:00
entityhuman.a(StatisticList.C[this.id], 1);
2012-11-06 13:05:28 +01:00
this.b(world, i, j, k, new ItemStack(Block.LEAVES.id, 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() {
2012-07-29 09:33:13 +02:00
return !this.c;
2011-02-23 03:37:56 +01:00
}
public int a(int i, int j) {
2012-03-01 11:49:23 +01:00
return (j & 3) == 1 ? this.textureId + 80 : ((j & 3) == 3 ? this.textureId + 144 : this.textureId);
2011-01-04 23:09:40 +01:00
}
}