2011-01-12 18:40:42 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
2011-01-12 18:40:42 +01:00
|
|
|
import java.util.Random;
|
2011-01-14 14:31:10 +01:00
|
|
|
import java.util.Set;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
// CraftBukkit start
|
2011-01-15 22:40:18 +01:00
|
|
|
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 BlockRedstoneWire extends Block {
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
private boolean a = true;
|
|
|
|
private Set b = new HashSet();
|
2011-01-12 18:40:42 +01:00
|
|
|
|
|
|
|
public BlockRedstoneWire(int i, int j) {
|
2011-01-29 22:50:29 +01:00
|
|
|
super(i, j, Material.ORIENTABLE);
|
|
|
|
this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public int a(int i, int j) {
|
|
|
|
return this.textureId;
|
|
|
|
}
|
|
|
|
|
2011-01-12 18:40:42 +01:00
|
|
|
public AxisAlignedBB d(World world, int i, int j, int k) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean canPlace(World world, int i, int j, int k) {
|
2011-01-12 18:40:42 +01:00
|
|
|
return world.d(i, j - 1, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void g(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
this.a(world, i, j, k, i, j, k);
|
|
|
|
ArrayList arraylist = new ArrayList(this.b);
|
|
|
|
|
|
|
|
this.b.clear();
|
2011-01-14 14:31:10 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
for (int l = 0; l < arraylist.size(); ++l) {
|
|
|
|
ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l);
|
2011-01-14 14:31:10 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
world.applyPhysics(chunkposition.x, chunkposition.y, chunkposition.z, this.id);
|
2011-01-14 14:31:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void a(World world, int i, int j, int k, int l, int i1, int j1) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int k1 = world.getData(i, j, k);
|
2011-01-14 14:31:10 +01:00
|
|
|
int l1 = 0;
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.a = false;
|
2011-04-20 19:05:14 +02:00
|
|
|
boolean flag = world.isBlockIndirectlyPowered(i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.a = true;
|
|
|
|
int i2;
|
|
|
|
int j2;
|
|
|
|
int k2;
|
|
|
|
|
2011-01-12 18:40:42 +01:00
|
|
|
if (flag) {
|
2011-01-14 14:31:10 +01:00
|
|
|
l1 = 15;
|
2011-01-12 18:40:42 +01:00
|
|
|
} else {
|
2011-01-29 22:50:29 +01:00
|
|
|
for (i2 = 0; i2 < 4; ++i2) {
|
|
|
|
j2 = i;
|
|
|
|
k2 = k;
|
2011-01-14 14:31:10 +01:00
|
|
|
if (i2 == 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
j2 = i - 1;
|
2011-01-14 14:31:10 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (i2 == 1) {
|
2011-01-29 22:50:29 +01:00
|
|
|
++j2;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (i2 == 2) {
|
2011-01-29 22:50:29 +01:00
|
|
|
k2 = k - 1;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (i2 == 3) {
|
2011-01-29 22:50:29 +01:00
|
|
|
++k2;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (j2 != l || j != i1 || k2 != j1) {
|
2011-04-20 19:05:14 +02:00
|
|
|
l1 = this.getPower(world, j2, j, k2, l1);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (world.d(j2, j, k2) && !world.d(i, j + 1, k)) {
|
|
|
|
if (j2 != l || j + 1 != i1 || k2 != j1) {
|
2011-04-20 19:05:14 +02:00
|
|
|
l1 = this.getPower(world, j2, j + 1, k2, l1);
|
2011-01-14 14:31:10 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
} else if (!world.d(j2, j, k2) && (j2 != l || j - 1 != i1 || k2 != j1)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
l1 = this.getPower(world, j2, j - 1, k2, l1);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (l1 > 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
--l1;
|
2011-01-12 18:40:42 +01:00
|
|
|
} else {
|
2011-01-14 14:31:10 +01:00
|
|
|
l1 = 0;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit start
|
2011-01-14 14:31:10 +01:00
|
|
|
if (k1 != l1) {
|
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, k1, l1);
|
2011-01-29 22:50:29 +01:00
|
|
|
((WorldServer) world).getServer().getPluginManager().callEvent(event);
|
|
|
|
l1 = event.getNewCurrent();
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit end
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (k1 != l1) {
|
2011-02-23 03:37:56 +01:00
|
|
|
world.h = true;
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setData(i, j, k, l1);
|
2011-01-12 18:40:42 +01:00
|
|
|
world.b(i, j, k, i, j, k);
|
2011-02-23 03:37:56 +01:00
|
|
|
world.h = false;
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
for (i2 = 0; i2 < 4; ++i2) {
|
|
|
|
j2 = i;
|
|
|
|
k2 = k;
|
|
|
|
int l2 = j - 1;
|
|
|
|
|
|
|
|
if (i2 == 0) {
|
|
|
|
j2 = i - 1;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i2 == 1) {
|
|
|
|
++j2;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i2 == 2) {
|
|
|
|
k2 = k - 1;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i2 == 3) {
|
|
|
|
++k2;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (world.d(j2, j, k2)) {
|
|
|
|
l2 += 2;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
boolean flag1 = false;
|
2011-04-20 19:05:14 +02:00
|
|
|
int i3 = this.getPower(world, j2, j, k2, -1);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
l1 = world.getData(i, j, k);
|
2011-01-14 14:31:10 +01:00
|
|
|
if (l1 > 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
--l1;
|
2011-01-14 14:31:10 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i3 >= 0 && i3 != l1) {
|
|
|
|
this.a(world, j2, j, k2, i, j, k);
|
2011-01-14 14:31:10 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
i3 = this.getPower(world, j2, l2, k2, -1);
|
2011-01-29 22:50:29 +01:00
|
|
|
l1 = world.getData(i, j, k);
|
2011-01-14 14:31:10 +01:00
|
|
|
if (l1 > 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
--l1;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i3 >= 0 && i3 != l1) {
|
|
|
|
this.a(world, j2, l2, k2, i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 14:31:10 +01:00
|
|
|
if (k1 == 0 || l1 == 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
this.b.add(new ChunkPosition(i, j, k));
|
|
|
|
this.b.add(new ChunkPosition(i - 1, j, k));
|
|
|
|
this.b.add(new ChunkPosition(i + 1, j, k));
|
|
|
|
this.b.add(new ChunkPosition(i, j - 1, k));
|
|
|
|
this.b.add(new ChunkPosition(i, j + 1, k));
|
|
|
|
this.b.add(new ChunkPosition(i, j, k - 1));
|
|
|
|
this.b.add(new ChunkPosition(i, j, k + 1));
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void h(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.getTypeId(i, j, k) == this.id) {
|
2011-04-20 19:05:14 +02:00
|
|
|
world.applyPhysics(i, j, k, this.id);
|
|
|
|
world.applyPhysics(i - 1, j, k, this.id);
|
|
|
|
world.applyPhysics(i + 1, j, k, this.id);
|
|
|
|
world.applyPhysics(i, j, k - 1, this.id);
|
|
|
|
world.applyPhysics(i, j, k + 1, this.id);
|
|
|
|
world.applyPhysics(i, j - 1, k, this.id);
|
|
|
|
world.applyPhysics(i, j + 1, k, this.id);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void e(World world, int i, int j, int k) {
|
|
|
|
super.e(world, i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!world.isStatic) {
|
|
|
|
this.g(world, i, j, k);
|
2011-04-20 19:05:14 +02:00
|
|
|
world.applyPhysics(i, j + 1, k, this.id);
|
|
|
|
world.applyPhysics(i, j - 1, k, this.id);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.h(world, i - 1, j, k);
|
|
|
|
this.h(world, i + 1, j, k);
|
|
|
|
this.h(world, i, j, k - 1);
|
|
|
|
this.h(world, i, j, k + 1);
|
|
|
|
if (world.d(i - 1, j, k)) {
|
|
|
|
this.h(world, i - 1, j + 1, k);
|
|
|
|
} else {
|
|
|
|
this.h(world, i - 1, j - 1, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.d(i + 1, j, k)) {
|
|
|
|
this.h(world, i + 1, j + 1, k);
|
|
|
|
} else {
|
|
|
|
this.h(world, i + 1, j - 1, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.d(i, j, k - 1)) {
|
|
|
|
this.h(world, i, j + 1, k - 1);
|
|
|
|
} else {
|
|
|
|
this.h(world, i, j - 1, k - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.d(i, j, k + 1)) {
|
|
|
|
this.h(world, i, j + 1, k + 1);
|
|
|
|
} else {
|
|
|
|
this.h(world, i, j - 1, k + 1);
|
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void remove(World world, int i, int j, int k) {
|
|
|
|
super.remove(world, i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!world.isStatic) {
|
2011-04-20 19:05:14 +02:00
|
|
|
world.applyPhysics(i, j + 1, k, this.id);
|
|
|
|
world.applyPhysics(i, j - 1, k, this.id);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.g(world, i, j, k);
|
|
|
|
this.h(world, i - 1, j, k);
|
|
|
|
this.h(world, i + 1, j, k);
|
|
|
|
this.h(world, i, j, k - 1);
|
|
|
|
this.h(world, i, j, k + 1);
|
|
|
|
if (world.d(i - 1, j, k)) {
|
|
|
|
this.h(world, i - 1, j + 1, k);
|
|
|
|
} else {
|
|
|
|
this.h(world, i - 1, j - 1, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.d(i + 1, j, k)) {
|
|
|
|
this.h(world, i + 1, j + 1, k);
|
|
|
|
} else {
|
|
|
|
this.h(world, i + 1, j - 1, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.d(i, j, k - 1)) {
|
|
|
|
this.h(world, i, j + 1, k - 1);
|
|
|
|
} else {
|
|
|
|
this.h(world, i, j - 1, k - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.d(i, j, k + 1)) {
|
|
|
|
this.h(world, i, j + 1, k + 1);
|
|
|
|
} else {
|
|
|
|
this.h(world, i, j - 1, k + 1);
|
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
// Craftbukkit private->public
|
|
|
|
public int getPower(World world, int i, int j, int k, int l) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.getTypeId(i, j, k) != this.id) {
|
2011-01-12 18:40:42 +01:00
|
|
|
return l;
|
|
|
|
} else {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i1 = world.getData(i, j, k);
|
|
|
|
|
|
|
|
return i1 > l ? i1 : l;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void doPhysics(World world, int i, int j, int k, int l) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!world.isStatic) {
|
|
|
|
int i1 = world.getData(i, j, k);
|
2011-04-20 19:05:14 +02:00
|
|
|
boolean flag = this.canPlace(world, i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!flag) {
|
2011-03-31 22:40:00 +02:00
|
|
|
this.a_(world, i, j, k, i1);
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setTypeId(i, j, k, 0);
|
|
|
|
} else {
|
|
|
|
// Craftbukkit
|
|
|
|
if ((Block.byId[l] != null && Block.byId[l].isPowerSource()) || Block.DIODE_OFF.id == l || Block.DIODE_ON.id == l)
|
2011-01-29 22:50:29 +01:00
|
|
|
this.g(world, i, j, k);
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
super.doPhysics(world, i, j, k, l);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int a(int i, Random random) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return Item.REDSTONE.id;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public boolean c(World world, int i, int j, int k, int l) {
|
2011-04-20 19:05:14 +02:00
|
|
|
return !this.a ? false : this.b(world, i, j, k, l);
|
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 if (iblockaccess.getData(i, j, k) == 0) {
|
2011-01-12 18:40:42 +01:00
|
|
|
return false;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else if (l == 1) {
|
2011-01-12 18:40:42 +01:00
|
|
|
return true;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
|
|
|
boolean flag = b(iblockaccess, i - 1, j, k) || !iblockaccess.d(i - 1, j, k) && b(iblockaccess, i - 1, j - 1, k);
|
|
|
|
boolean flag1 = b(iblockaccess, i + 1, j, k) || !iblockaccess.d(i + 1, j, k) && b(iblockaccess, i + 1, j - 1, k);
|
|
|
|
boolean flag2 = b(iblockaccess, i, j, k - 1) || !iblockaccess.d(i, j, k - 1) && b(iblockaccess, i, j - 1, k - 1);
|
|
|
|
boolean flag3 = b(iblockaccess, i, j, k + 1) || !iblockaccess.d(i, j, k + 1) && b(iblockaccess, i, j - 1, k + 1);
|
|
|
|
|
|
|
|
if (!iblockaccess.d(i, j + 1, k)) {
|
|
|
|
if (iblockaccess.d(i - 1, j, k) && b(iblockaccess, i - 1, j + 1, k)) {
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iblockaccess.d(i + 1, j, k) && b(iblockaccess, i + 1, j + 1, k)) {
|
|
|
|
flag1 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iblockaccess.d(i, j, k - 1) && b(iblockaccess, i, j + 1, k - 1)) {
|
|
|
|
flag2 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iblockaccess.d(i, j, k + 1) && b(iblockaccess, i, j + 1, k + 1)) {
|
|
|
|
flag3 = true;
|
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
return !flag2 && !flag1 && !flag && !flag3 && l >= 2 && l <= 5 ? true : (l == 2 && flag2 && !flag && !flag1 ? true : (l == 3 && flag3 && !flag && !flag1 ? true : (l == 4 && flag && !flag2 && !flag3 ? true : l == 5 && flag1 && !flag2 && !flag3)));
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean isPowerSource() {
|
2011-01-29 22:50:29 +01:00
|
|
|
return this.a;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean b(IBlockAccess iblockaccess, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int l = iblockaccess.getTypeId(i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
return l == Block.REDSTONE_WIRE.id ? true : (l == 0 ? false : Block.byId[l].isPowerSource());
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|