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
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
|
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;
|
2013-03-13 23:33:27 +01:00
|
|
|
private Set b = new HashSet();
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public BlockRedstoneWire() {
|
|
|
|
super(Material.ORIENTABLE);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public AxisAlignedBB a(World world, int i, int j, int k) {
|
2011-01-12 18:40:42 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean c() {
|
2011-01-12 18:40:42 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean d() {
|
2011-05-26 14:48:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public int b() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean canPlace(World world, int i, int j, int k) {
|
2013-11-04 14:07:38 +01:00
|
|
|
return World.a((IBlockAccess) world, i, j - 1, k) || world.getType(i, j - 1, k) == Blocks.GLOWSTONE;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
private void e(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
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
for (int l = 0; l < arraylist.size(); ++l) {
|
|
|
|
ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l);
|
2011-01-14 14:31:10 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
world.applyPhysics(chunkposition.x, chunkposition.y, chunkposition.z, this);
|
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);
|
2013-03-13 23:33:27 +01:00
|
|
|
byte b0 = 0;
|
|
|
|
int l1 = this.getPower(world, l, i1, j1, b0);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.a = false;
|
2013-03-13 23:33:27 +01:00
|
|
|
int i2 = world.getHighestNeighborSignal(i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.a = true;
|
2013-03-13 23:33:27 +01:00
|
|
|
if (i2 > 0 && i2 > l1 - 1) {
|
|
|
|
l1 = i2;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
int j2 = 0;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
for (int k2 = 0; k2 < 4; ++k2) {
|
|
|
|
int l2 = i;
|
|
|
|
int i3 = k;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (k2 == 0) {
|
|
|
|
l2 = i - 1;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (k2 == 1) {
|
|
|
|
++l2;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (k2 == 2) {
|
|
|
|
i3 = k - 1;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (k2 == 3) {
|
|
|
|
++i3;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (l2 != l || i3 != j1) {
|
|
|
|
j2 = this.getPower(world, l2, j, i3, j2);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(l2, j, i3).r() && !world.getType(i, j + 1, k).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
if ((l2 != l || i3 != j1) && j >= i1) {
|
|
|
|
j2 = this.getPower(world, l2, j + 1, i3, j2);
|
|
|
|
}
|
2013-11-04 14:07:38 +01:00
|
|
|
} else if (!world.getType(l2, j, i3).r() && (l2 != l || i3 != j1) && j <= i1) {
|
2013-03-13 23:33:27 +01:00
|
|
|
j2 = this.getPower(world, l2, j - 1, i3, j2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j2 > l1) {
|
|
|
|
l1 = j2 - 1;
|
|
|
|
} else if (l1 > 0) {
|
|
|
|
--l1;
|
|
|
|
} else {
|
|
|
|
l1 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 > l1 - 1) {
|
|
|
|
l1 = i2;
|
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-06-27 00:25:01 +02:00
|
|
|
BlockRedstoneEvent event = new BlockRedstoneEvent(world.getWorld().getBlockAt(i, j, k), k1, l1);
|
|
|
|
world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
l1 = event.getNewCurrent();
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit end
|
2011-01-14 14:31:10 +01:00
|
|
|
if (k1 != l1) {
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setData(i, j, k, l1, 2);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
private void m(World world, int i, int j, int k) {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i, j, k) == this) {
|
|
|
|
world.applyPhysics(i, j, k, this);
|
|
|
|
world.applyPhysics(i - 1, j, k, this);
|
|
|
|
world.applyPhysics(i + 1, j, k, this);
|
|
|
|
world.applyPhysics(i, j, k - 1, this);
|
|
|
|
world.applyPhysics(i, j, k + 1, this);
|
|
|
|
world.applyPhysics(i, j - 1, k, this);
|
|
|
|
world.applyPhysics(i, j + 1, k, this);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 07:59:59 +01:00
|
|
|
public void onPlace(World world, int i, int j, int k) {
|
|
|
|
super.onPlace(world, i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!world.isStatic) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.e(world, i, j, k);
|
|
|
|
world.applyPhysics(i, j + 1, k, this);
|
|
|
|
world.applyPhysics(i, j - 1, k, this);
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i - 1, j, k);
|
|
|
|
this.m(world, i + 1, j, k);
|
|
|
|
this.m(world, i, j, k - 1);
|
|
|
|
this.m(world, i, j, k + 1);
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i - 1, j, k).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i - 1, j + 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i - 1, j - 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i + 1, j, k).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i + 1, j + 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i + 1, j - 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i, j, k - 1).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j + 1, k - 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j - 1, k - 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i, j, k + 1).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j + 1, k + 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j - 1, k + 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-12 18:40:42 +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) {
|
|
|
|
super.remove(world, i, j, k, block, l);
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!world.isStatic) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.applyPhysics(i, j + 1, k, this);
|
|
|
|
world.applyPhysics(i, j - 1, k, this);
|
|
|
|
world.applyPhysics(i + 1, j, k, this);
|
|
|
|
world.applyPhysics(i - 1, j, k, this);
|
|
|
|
world.applyPhysics(i, j, k + 1, this);
|
|
|
|
world.applyPhysics(i, j, k - 1, this);
|
|
|
|
this.e(world, i, j, k);
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i - 1, j, k);
|
|
|
|
this.m(world, i + 1, j, k);
|
|
|
|
this.m(world, i, j, k - 1);
|
|
|
|
this.m(world, i, j, k + 1);
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i - 1, j, k).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i - 1, j + 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i - 1, j - 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i + 1, j, k).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i + 1, j + 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i + 1, j - 1, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i, j, k - 1).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j + 1, k - 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j - 1, k - 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i, j, k + 1).r()) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j + 1, k + 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.m(world, i, j - 1, k + 1);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - private -> public
|
2011-04-20 19:05:14 +02:00
|
|
|
public int getPower(World world, int i, int j, int k, int l) {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i, j, k) != this) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void doPhysics(World world, int i, int j, int k, Block block) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!world.isStatic) {
|
2011-04-20 19:05:14 +02:00
|
|
|
boolean flag = this.canPlace(world, i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (flag) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.e(world, i, j, k);
|
2011-04-20 19:05:14 +02:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.b(world, i, j, k, 0, 0);
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setAir(i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
super.doPhysics(world, i, j, k, block);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public Item getDropType(int i, Random random, int j) {
|
|
|
|
return Items.REDSTONE;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int c(IBlockAccess iblockaccess, int i, int j, int k, int l) {
|
|
|
|
return !this.a ? 0 : this.b(iblockaccess, i, j, k, l);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!this.a) {
|
2013-03-13 23:33:27 +01:00
|
|
|
return 0;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
int i1 = iblockaccess.getData(i, j, k);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (i1 == 0) {
|
|
|
|
return 0;
|
|
|
|
} else if (l == 1) {
|
|
|
|
return i1;
|
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
boolean flag = g(iblockaccess, i - 1, j, k, 1) || !iblockaccess.getType(i - 1, j, k).r() && g(iblockaccess, i - 1, j - 1, k, -1);
|
|
|
|
boolean flag1 = g(iblockaccess, i + 1, j, k, 3) || !iblockaccess.getType(i + 1, j, k).r() && g(iblockaccess, i + 1, j - 1, k, -1);
|
|
|
|
boolean flag2 = g(iblockaccess, i, j, k - 1, 2) || !iblockaccess.getType(i, j, k - 1).r() && g(iblockaccess, i, j - 1, k - 1, -1);
|
|
|
|
boolean flag3 = g(iblockaccess, i, j, k + 1, 0) || !iblockaccess.getType(i, j, k + 1).r() && g(iblockaccess, i, j - 1, k + 1, -1);
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (!iblockaccess.getType(i, j + 1, k).r()) {
|
|
|
|
if (iblockaccess.getType(i - 1, j, k).r() && g(iblockaccess, i - 1, j + 1, k, -1)) {
|
2013-03-13 23:33:27 +01:00
|
|
|
flag = true;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (iblockaccess.getType(i + 1, j, k).r() && g(iblockaccess, i + 1, j + 1, k, -1)) {
|
2013-03-13 23:33:27 +01:00
|
|
|
flag1 = true;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (iblockaccess.getType(i, j, k - 1).r() && g(iblockaccess, i, j + 1, k - 1, -1)) {
|
2013-03-13 23:33:27 +01:00
|
|
|
flag2 = true;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (iblockaccess.getType(i, j, k + 1).r() && g(iblockaccess, i, j + 1, k + 1, -1)) {
|
2013-03-13 23:33:27 +01:00
|
|
|
flag3 = true;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
return !flag2 && !flag1 && !flag && !flag3 && l >= 2 && l <= 5 ? i1 : (l == 2 && flag2 && !flag && !flag1 ? i1 : (l == 3 && flag3 && !flag && !flag1 ? i1 : (l == 4 && flag && !flag2 && !flag3 ? i1 : (l == 5 && flag1 && !flag2 && !flag3 ? i1 : 0))));
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public static boolean f(IBlockAccess iblockaccess, int i, int j, int k, int l) {
|
2013-11-04 14:07:38 +01:00
|
|
|
Block block = iblockaccess.getType(i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (block == Blocks.REDSTONE_WIRE) {
|
2011-06-30 00:02:25 +02:00
|
|
|
return true;
|
2013-11-04 14:07:38 +01:00
|
|
|
} else if (!Blocks.DIODE_OFF.e(block)) {
|
|
|
|
return block.isPowerSource() && l != -1;
|
2011-06-30 00:02:25 +02:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
int i1 = iblockaccess.getData(i, j, k);
|
2011-06-30 00:02:25 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
return l == (i1 & 3) || l == Direction.f[i1 & 3];
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public static boolean g(IBlockAccess iblockaccess, int i, int j, int k, int l) {
|
|
|
|
if (f(iblockaccess, i, j, k, l)) {
|
2011-11-20 09:01:14 +01:00
|
|
|
return true;
|
2013-11-04 14:07:38 +01:00
|
|
|
} else if (iblockaccess.getType(i, j, k) == Blocks.DIODE_ON) {
|
|
|
|
int i1 = iblockaccess.getData(i, j, k);
|
2011-11-20 09:01:14 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
return l == (i1 & 3);
|
|
|
|
} else {
|
|
|
|
return false;
|
2011-06-30 00:02:25 +02:00
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|