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

143 Zeilen
4.6 KiB
Java

2011-01-12 18:40:42 +01:00
package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
// CraftBukkit start
import org.bukkit.craftbukkit.block.CraftBlock;
2011-01-12 18:40:42 +01:00
import org.bukkit.event.block.BlockRedstoneEvent;
2011-01-29 22:50:29 +01:00
// CraftBukkit end
2011-01-12 18:40:42 +01:00
public class BlockRedstoneTorch extends BlockTorch {
2011-01-29 22:50:29 +01:00
private boolean a = false;
2011-01-12 18:40:42 +01:00
private static List b = new ArrayList();
private boolean a(World world, int i, int j, int k, boolean flag) {
if (flag) {
2011-01-29 22:50:29 +01:00
b.add(new RedstoneUpdateInfo(i, j, k, world.e));
2011-01-12 18:40:42 +01:00
}
2011-01-29 22:50:29 +01:00
2011-01-12 18:40:42 +01:00
int l = 0;
2011-01-29 22:50:29 +01:00
for (int i1 = 0; i1 < b.size(); ++i1) {
2011-01-12 18:40:42 +01:00
RedstoneUpdateInfo redstoneupdateinfo = (RedstoneUpdateInfo) b.get(i1);
2011-01-29 22:50:29 +01:00
if (redstoneupdateinfo.a == i && redstoneupdateinfo.b == j && redstoneupdateinfo.c == k) {
++l;
if (l >= 8) {
return true;
}
2011-01-12 18:40:42 +01:00
}
}
return false;
}
protected BlockRedstoneTorch(int i, int j, boolean flag) {
super(i, j);
2011-01-29 22:50:29 +01:00
this.a = flag;
this.a(true);
2011-01-12 18:40:42 +01:00
}
public int b() {
return 2;
}
public void e(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
if (world.getData(i, j, k) == 0) {
2011-01-12 18:40:42 +01:00
super.e(world, i, j, k);
}
2011-01-29 22:50:29 +01:00
if (this.a) {
world.h(i, j - 1, k, this.id);
world.h(i, j + 1, k, this.id);
world.h(i - 1, j, k, this.id);
world.h(i + 1, j, k, this.id);
world.h(i, j, k - 1, this.id);
world.h(i, j, k + 1, this.id);
2011-01-12 18:40:42 +01:00
}
}
public void b(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
if (this.a) {
world.h(i, j - 1, k, this.id);
world.h(i, j + 1, k, this.id);
world.h(i - 1, j, k, this.id);
world.h(i + 1, j, k, this.id);
world.h(i, j, k - 1, this.id);
world.h(i, j, k + 1, this.id);
2011-01-12 18:40:42 +01:00
}
}
public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
2011-01-29 22:50:29 +01:00
if (!this.a) {
2011-01-12 18:40:42 +01:00
return false;
2011-01-29 22:50:29 +01:00
} else {
int i1 = iblockaccess.getData(i, j, k);
2011-01-12 18:40:42 +01:00
2011-01-29 22:50:29 +01:00
return i1 == 5 && l == 1 ? false : (i1 == 3 && l == 3 ? false : (i1 == 4 && l == 2 ? false : (i1 == 1 && l == 5 ? false : i1 != 2 || l != 4)));
2011-01-12 18:40:42 +01:00
}
}
private boolean g(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
int l = world.getData(i, j, k);
2011-01-12 18:40:42 +01:00
2011-01-29 22:50:29 +01:00
return l == 5 && world.k(i, j - 1, k, 0) ? true : (l == 3 && world.k(i, j, k - 1, 2) ? true : (l == 4 && world.k(i, j, k + 1, 3) ? true : (l == 1 && world.k(i - 1, j, k, 4) ? true : l == 2 && world.k(i + 1, j, k, 5))));
2011-01-12 18:40:42 +01:00
}
public void a(World world, int i, int j, int k, Random random) {
2011-01-29 22:50:29 +01:00
boolean flag = this.g(world, i, j, k);
2011-01-12 18:40:42 +01:00
2011-01-29 22:50:29 +01:00
while (b.size() > 0 && world.e - ((RedstoneUpdateInfo) b.get(0)).d > 100L) {
b.remove(0);
2011-01-12 18:40:42 +01:00
}
2011-01-29 22:50:29 +01:00
2011-01-14 14:31:10 +01:00
// Craftbukkit start
2011-01-12 18:40:42 +01:00
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
2011-02-08 13:54:28 +01:00
BlockRedstoneEvent event = new BlockRedstoneEvent(block, flag ? 15 : 0, flag ? 0 : 15);
2011-01-29 22:50:29 +01:00
((WorldServer) world).getServer().getPluginManager().callEvent(event);
if ((event.getNewCurrent() != 0) == flag) {
2011-01-12 18:40:42 +01:00
return;
}
2011-01-14 14:31:10 +01:00
// Craftbukkit end
2011-01-29 22:50:29 +01:00
if (this.a) {
2011-01-12 18:40:42 +01:00
if (flag) {
2011-01-29 22:50:29 +01:00
world.b(i, j, k, Block.REDSTONE_TORCH_OFF.id, world.getData(i, j, k));
if (this.a(world, i, j, k, true)) {
world.a((double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), "random.fizz", 0.5F, 2.6F + (world.l.nextFloat() - world.l.nextFloat()) * 0.8F);
for (int l = 0; l < 5; ++l) {
double d0 = (double) i + random.nextDouble() * 0.6D + 0.2D;
double d1 = (double) j + random.nextDouble() * 0.6D + 0.2D;
double d2 = (double) k + random.nextDouble() * 0.6D + 0.2D;
world.a("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
2011-01-12 18:40:42 +01:00
}
}
}
2011-01-29 22:50:29 +01:00
} else if (!flag && !this.a(world, i, j, k, false)) {
world.b(i, j, k, Block.REDSTONE_TORCH_ON.id, world.getData(i, j, k));
2011-01-12 18:40:42 +01:00
}
}
public void b(World world, int i, int j, int k, int l) {
super.b(world, i, j, k, l);
2011-01-29 22:50:29 +01:00
world.i(i, j, k, this.id);
2011-01-12 18:40:42 +01:00
}
public boolean d(World world, int i, int j, int k, int l) {
2011-01-29 22:50:29 +01:00
return l == 0 ? this.b((IBlockAccess) world, i, j, k, l) : false;
2011-01-12 18:40:42 +01:00
}
public int a(int i, Random random) {
2011-01-29 22:50:29 +01:00
return Block.REDSTONE_TORCH_ON.id;
2011-01-12 18:40:42 +01:00
}
public boolean c() {
return true;
}
}