add redstone hooks

This commit is contained in:
Tahg 2011-01-12 12:40:42 -05:00
parent 45bac533be
commit be6cd7ed9c
5 changed files with 536 additions and 33 deletions

View File

@ -3,10 +3,12 @@ package net.minecraft.server;
import java.util.Random; import java.util.Random;
// CraftBukkit start // CraftBukkit start
import org.bukkit.BlockFace;
import org.bukkit.craftbukkit.CraftBlock; import org.bukkit.craftbukkit.CraftBlock;
import org.bukkit.craftbukkit.CraftPlayer; import org.bukkit.craftbukkit.CraftPlayer;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockInteractEvent; import org.bukkit.event.block.BlockInteractEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
// CraftBukkit end // CraftBukkit end
public class BlockButton extends Block { public class BlockButton extends Block {
@ -143,9 +145,12 @@ public class BlockButton extends Block {
((WorldServer) world).getServer().getPluginManager().callEvent(bie); ((WorldServer) world).getServer().getPluginManager().callEvent(bie);
if (bie.isCancelled()) return true; if (bie.isCancelled()) {
return true;
}
// CraftBukkit end // CraftBukkit end
if (world.z) { if (world.z) {
return true; return true;
} }
@ -156,22 +161,30 @@ public class BlockButton extends Block {
if (j1 == 0) { if (j1 == 0) {
return true; return true;
} }
world.b(i, j, k, i1 + j1);
world.b(i, j, k, i, j, k); //Allow the lever to change the current
world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.click", 0.3F, 0.6F); int old = (j1 != 8) ? 1 : 0;
world.g(i, j, k, bh); int current = (j1 == 8) ? 1 : 0;
if (i1 == 1) { BlockRedstoneEvent bre = new BlockRedstoneEvent(block, BlockFace.Self, old, current);
world.g(i - 1, j, k, bh); ((WorldServer) world).getServer().getPluginManager().callEvent(bre);
} else if (i1 == 2) { if ((bre.getNewCurrent() > 0) == (k == 8)) {
world.g(i + 1, j, k, bh); world.b(i, j, k, i1 + j1);
} else if (i1 == 3) { world.b(i, j, k, i, j, k);
world.g(i, j, k - 1, bh); world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.click", 0.3F, 0.6F);
} else if (i1 == 4) { world.g(i, j, k, bh);
world.g(i, j, k + 1, bh); if (i1 == 1) {
} else { world.g(i - 1, j, k, bh);
world.g(i, j - 1, k, bh); } else if (i1 == 2) {
world.g(i + 1, j, k, bh);
} else if (i1 == 3) {
world.g(i, j, k - 1, bh);
} else if (i1 == 4) {
world.g(i, j, k + 1, bh);
} else {
world.g(i, j - 1, k, bh);
}
world.h(i, j, k, bh);
} }
world.h(i, j, k, bh);
return true; return true;
} }

View File

@ -1,10 +1,12 @@
package net.minecraft.server; package net.minecraft.server;
// CraftBukkit start // CraftBukkit start
import org.bukkit.BlockFace;
import org.bukkit.craftbukkit.CraftBlock; import org.bukkit.craftbukkit.CraftBlock;
import org.bukkit.craftbukkit.CraftPlayer; import org.bukkit.craftbukkit.CraftPlayer;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockInteractEvent; import org.bukkit.event.block.BlockInteractEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
// CraftBukkit end // CraftBukkit end
public class BlockLever extends Block { public class BlockLever extends Block {
@ -159,20 +161,27 @@ public class BlockLever extends Block {
int i1 = l & 7; int i1 = l & 7;
int j1 = 8 - (l & 8); int j1 = 8 - (l & 8);
world.b(i, j, k, i1 + j1); //Allow the lever to change the current
world.b(i, j, k, i, j, k); int old = (j1 != 8) ? 1 : 0;
world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.click", 0.3F, j1 <= 0 ? 0.5F : 0.6F); int current = (j1 == 8) ? 1 : 0;
world.g(i, j, k, bh); BlockRedstoneEvent bre = new BlockRedstoneEvent(block, BlockFace.Self, old, current);
if (i1 == 1) { ((WorldServer) world).getServer().getPluginManager().callEvent(bre);
world.g(i - 1, j, k, bh); if ((bre.getNewCurrent() > 0) == (k == 8)) {
} else if (i1 == 2) { world.b(i, j, k, i1 + j1);
world.g(i + 1, j, k, bh); world.b(i, j, k, i, j, k);
} else if (i1 == 3) { world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.click", 0.3F, j1 <= 0 ? 0.5F : 0.6F);
world.g(i, j, k - 1, bh); world.g(i, j, k, bh);
} else if (i1 == 4) { if (i1 == 1) {
world.g(i, j, k + 1, bh); world.g(i - 1, j, k, bh);
} else { } else if (i1 == 2) {
world.g(i, j - 1, k, bh); world.g(i + 1, j, k, bh);
} else if (i1 == 3) {
world.g(i, j, k - 1, bh);
} else if (i1 == 4) {
world.g(i, j, k + 1, bh);
} else {
world.g(i, j - 1, k, bh);
}
} }
return true; return true;
} }

View File

@ -4,11 +4,12 @@ import java.util.List;
import java.util.Random; import java.util.Random;
// CraftBukkit start // CraftBukkit start
import org.bukkit.craftbukkit.CraftBlock; import org.bukkit.BlockFace;import org.bukkit.craftbukkit.CraftBlock;
import org.bukkit.craftbukkit.CraftLivingEntity; import org.bukkit.craftbukkit.CraftLivingEntity;
import org.bukkit.craftbukkit.CraftPlayer; import org.bukkit.craftbukkit.CraftPlayer;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockInteractEvent; import org.bukkit.event.block.BlockInteractEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
// CraftBukkit end // CraftBukkit end
public class BlockPressurePlate extends Block { public class BlockPressurePlate extends Block {
@ -40,7 +41,8 @@ public class BlockPressurePlate extends Block {
return world.d(i, j - 1, k); return world.d(i, j - 1, k);
} }
public void e(World world, int i, int j, int k) {} public void e(World world, int i, int j, int k) {
}
public void b(World world, int i, int j, int k, int l) { public void b(World world, int i, int j, int k, int l) {
boolean flag = false; boolean flag = false;
@ -87,7 +89,9 @@ public class BlockPressurePlate extends Block {
((WorldServer) world).getServer().getPluginManager().callEvent(bie); ((WorldServer) world).getServer().getPluginManager().callEvent(bie);
if (bie.isCancelled()) return; if (bie.isCancelled()) {
return;
}
} }
// CraftBukkit end // CraftBukkit end
@ -114,6 +118,10 @@ public class BlockPressurePlate extends Block {
if (list.size() > 0) { if (list.size() > 0) {
flag1 = true; flag1 = true;
} }
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
BlockRedstoneEvent bre = new BlockRedstoneEvent(block, BlockFace.Self, flag ? 15 : 0, flag1 ? 15 : 0);
((WorldServer) world).getServer().getPluginManager().callEvent(bre);
flag1 = bre.getNewCurrent() > 0;
if (flag1 && !flag) { if (flag1 && !flag) {
world.b(i, j, k, 1); world.b(i, j, k, 1);
world.g(i, j, k, bh); world.g(i, j, k, bh);

View File

@ -0,0 +1,160 @@
package net.minecraft.server;
import java.util.*;
import org.bukkit.BlockFace;
import org.bukkit.craftbukkit.CraftBlock;
import org.bukkit.event.block.BlockRedstoneEvent;
public class BlockRedstoneTorch extends BlockTorch {
private boolean a;
private static List b = new ArrayList();
private boolean a(World world, int i, int j, int k, boolean flag) {
if (flag) {
b.add(((new RedstoneUpdateInfo(i, j, k, world.e))));
}
int l = 0;
for (int i1 = 0; i1 < b.size(); i1++) {
RedstoneUpdateInfo redstoneupdateinfo = (RedstoneUpdateInfo) b.get(i1);
if (redstoneupdateinfo.a == i && redstoneupdateinfo.b == j && redstoneupdateinfo.c == k && ++l >= 8) {
return true;
}
}
return false;
}
protected BlockRedstoneTorch(int i, int j, boolean flag) {
super(i, j);
a = false;
a = flag;
a(true);
}
public int b() {
return 2;
}
public void e(World world, int i, int j, int k) {
if (world.b(i, j, k) == 0) {
super.e(world, i, j, k);
}
if (a) {
world.g(i, j - 1, k, bh);
world.g(i, j + 1, k, bh);
world.g(i - 1, j, k, bh);
world.g(i + 1, j, k, bh);
world.g(i, j, k - 1, bh);
world.g(i, j, k + 1, bh);
}
}
public void b(World world, int i, int j, int k) {
if (a) {
world.g(i, j - 1, k, bh);
world.g(i, j + 1, k, bh);
world.g(i - 1, j, k, bh);
world.g(i + 1, j, k, bh);
world.g(i, j, k - 1, bh);
world.g(i, j, k + 1, bh);
}
}
public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
if (!a) {
return false;
}
int i1 = iblockaccess.b(i, j, k);
if (i1 == 5 && l == 1) {
return false;
}
if (i1 == 3 && l == 3) {
return false;
}
if (i1 == 4 && l == 2) {
return false;
}
if (i1 == 1 && l == 5) {
return false;
}
return i1 != 2 || l != 4;
}
private boolean g(World world, int i, int j, int k) {
int l = world.b(i, j, k);
if (l == 5 && world.j(i, j - 1, k, 0)) {
return true;
}
if (l == 3 && world.j(i, j, k - 1, 2)) {
return true;
}
if (l == 4 && world.j(i, j, k + 1, 3)) {
return true;
}
if (l == 1 && world.j(i - 1, j, k, 4)) {
return true;
}
return l == 2 && world.j(i + 1, j, k, 5);
}
public void a(World world, int i, int j, int k, Random random) {
boolean flag = g(world, i, j, k);
for (; b.size() > 0 && world.e - ((RedstoneUpdateInfo) b.get(0)).d > 100L; b.remove(0)) {
;
}
//Added by craftbukkit
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
BlockRedstoneEvent bre = new BlockRedstoneEvent(block, BlockFace.Self, flag ? 15 : 0, flag ? 0 : 15);
((WorldServer) world).getServer().getPluginManager().callEvent(bre);
if ((bre.getNewCurrent() != 0) == flag) {
return;
}
if (a) {
if (flag) {
world.b(i, j, k, Block.aP.bh, world.b(i, j, k));
if (a(world, i, j, k, true)) {
world.a((float) i + 0.5F, (float) j + 0.5F, (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 d1 = (double) i + random.nextDouble() * 0.59999999999999998D + 0.20000000000000001D;
double d2 = (double) j + random.nextDouble() * 0.59999999999999998D + 0.20000000000000001D;
double d3 = (double) k + random.nextDouble() * 0.59999999999999998D + 0.20000000000000001D;
world.a("smoke", d1, d2, d3, 0.0D, 0.0D, 0.0D);
}
}
}
} else if (!flag
&& !a(world, i, j, k,
false)) {
world.b(i, j, k, Block.aQ.bh, world.b(i, j, k));
}
}
public void b(World world, int i, int j, int k, int l) {
super.b(world, i, j, k, l);
world.h(i, j, k, bh);
}
public boolean d(World world, int i, int j, int k, int l) {
if (l == 0) {
return b(((IBlockAccess) (world)), i, j, k, l);
} else {
return false;
}
}
public int a(int i, Random random) {
return Block.aQ.bh;
}
public boolean c() {
return true;
}
}

View File

@ -0,0 +1,313 @@
package net.minecraft.server;
import java.util.Random;
import org.bukkit.BlockFace;
import org.bukkit.craftbukkit.CraftBlock;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.plugin.PluginLoader;
public class BlockRedstoneWire extends Block {
private boolean a;
public BlockRedstoneWire(int i, int j) {
super(i, j, Material.n);
a = true;
a(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
}
public AxisAlignedBB d(World world, int i, int j, int k) {
return null;
}
public boolean a() {
return false;
}
public boolean a(World world, int i, int j, int k) {
return world.d(i, j - 1, k);
}
private void g(World world, int i, int j, int k) {
int l = world.b(i, j, k);
int i1 = 0;
a = false;
boolean flag = world.o(i, j, k);
a = true;
if (flag) {
i1 = 15;
} else {
for (int j1 = 0; j1 < 4; j1++) {
int l1 = i;
int j2 = k;
if (j1 == 0) {
l1--;
}
if (j1 == 1) {
l1++;
}
if (j1 == 2) {
j2--;
}
if (j1 == 3) {
j2++;
}
i1 = f(world, l1, j, j2, i1);
if (world.d(l1, j, j2) && !world.d(i, j + 1, k)) {
i1 = f(world, l1, j + 1, j2, i1);
continue;
}
if (!world.d(l1, j, j2)) {
i1 = f(world, l1, j - 1, j2, i1);
}
}
if (i1 > 0) {
i1--;
} else {
i1 = 0;
}
}
//Allow redstone wire current changes
if (l != i1) {
CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
BlockRedstoneEvent bre = new BlockRedstoneEvent(block, BlockFace.Self, l, i1);
((WorldServer) world).getServer().getPluginManager().callEvent(bre);
i1 = bre.getNewCurrent();
}
if (l != i1) {
world.b(i, j, k, i1);
world.b(i, j, k, i, j, k);
if (i1 > 0) {
i1--;
}
for (int k1 = 0; k1 < 4; k1++) {
int i2 = i;
int k2 = k;
int l2 = j - 1;
if (k1 == 0) {
i2--;
}
if (k1 == 1) {
i2++;
}
if (k1 == 2) {
k2--;
}
if (k1 == 3) {
k2++;
}
if (world.d(i2, j, k2)) {
l2 += 2;
}
int i3 = f(world, i2, j, k2, -1);
if (i3 >= 0 && i3 != i1) {
g(world, i2, j, k2);
}
i3 = f(world, i2, l2, k2, -1);
if (i3 >= 0 && i3 != i1) {
g(world, i2, l2, k2);
}
}
if (l == 0 || i1 == 0) {
world.g(i, j, k, bh);
world.g(i - 1, j, k, bh);
world.g(i + 1, j, k, bh);
world.g(i, j, k - 1, bh);
world.g(i, j, k + 1, bh);
world.g(i, j - 1, k, bh);
world.g(i, j + 1, k, bh);
}
}
}
private void h(World world, int i, int j, int k) {
if (world.a(i, j, k) != bh) {
return;
} else {
world.g(i, j, k, bh);
world.g(i - 1, j, k, bh);
world.g(i + 1, j, k, bh);
world.g(i, j, k - 1, bh);
world.g(i, j, k + 1, bh);
world.g(i, j - 1, k, bh);
world.g(i, j + 1, k, bh);
return;
}
}
public void e(World world, int i, int j, int k) {
super.e(world, i, j, k);
if (world.z) {
return;
}
g(world, i, j, k);
world.g(i, j + 1, k, bh);
world.g(i, j - 1, k, bh);
h(world, i - 1, j, k);
h(world, i + 1, j, k);
h(world, i, j, k - 1);
h(world, i, j, k + 1);
if (world.d(i - 1, j, k)) {
h(world, i - 1, j + 1, k);
} else {
h(world, i - 1, j - 1, k);
}
if (world.d(i + 1, j, k)) {
h(world, i + 1, j + 1, k);
} else {
h(world, i + 1, j - 1, k);
}
if (world.d(i, j, k - 1)) {
h(world, i, j + 1, k - 1);
} else {
h(world, i, j - 1, k - 1);
}
if (world.d(i, j, k + 1)) {
h(world, i, j + 1, k + 1);
} else {
h(world, i, j - 1, k + 1);
}
}
public void b(World world, int i, int j, int k) {
super.b(world, i, j, k);
if (world.z) {
return;
}
world.g(i, j + 1, k, bh);
world.g(i, j - 1, k, bh);
g(world, i, j, k);
h(world, i - 1, j, k);
h(world, i + 1, j, k);
h(world, i, j, k - 1);
h(world, i, j, k + 1);
if (world.d(i - 1, j, k)) {
h(world, i - 1, j + 1, k);
} else {
h(world, i - 1, j - 1, k);
}
if (world.d(i + 1, j, k)) {
h(world, i + 1, j + 1, k);
} else {
h(world, i + 1, j - 1, k);
}
if (world.d(i, j, k - 1)) {
h(world, i, j + 1, k - 1);
} else {
h(world, i, j - 1, k - 1);
}
if (world.d(i, j, k + 1)) {
h(world, i, j + 1, k + 1);
} else {
h(world, i, j - 1, k + 1);
}
}
private int f(World world, int i, int j, int k, int l) {
if (world.a(i, j, k) != bh) {
return l;
}
int i1 = world.b(i, j, k);
if (i1 > l) {
return i1;
} else {
return l;
}
}
public void b(World world, int i, int j, int k, int l) {
if (world.z) {
return;
}
int i1 = world.b(i, j, k);
boolean flag = a(world, i, j, k);
if (!flag) {
a_(world, i, j, k, i1);
world.d(i, j, k, 0);
} else {
g(world, i, j, k);
}
super.b(world, i, j, k, l);
}
public int a(int i, Random random) {
return Item.aA.aW;
}
public boolean d(World world, int i, int j, int k, int l) {
if (!a) {
return false;
} else {
return b(((IBlockAccess) (world)), i, j, k, l);
}
}
public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
if (!a) {
return false;
}
if (iblockaccess.b(i, j, k) == 0) {
return false;
}
if (l == 1) {
return true;
}
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;
}
}
if (!flag2 && !flag1 && !flag && !flag3 && l >= 2 && l <= 5) {
return true;
}
if (l == 2 && flag2 && !flag && !flag1) {
return true;
}
if (l == 3 && flag3 && !flag && !flag1) {
return true;
}
if (l == 4 && flag && !flag2 && !flag3) {
return true;
}
return l == 5 && flag1 && !flag2 && !flag3;
}
public boolean c() {
return a;
}
public static boolean b(IBlockAccess iblockaccess, int i, int j, int k) {
int l = iblockaccess.a(i, j, k);
if (l == Block.av.bh) {
return true;
}
if (l == 0) {
return false;
}
return Block.m[l].c();
}
}