diff options
author | EvilSeph <evilseph@unaligned.org> | 2011-06-17 20:09:55 -0400 |
---|---|---|
committer | EvilSeph <evilseph@unaligned.org> | 2011-06-17 20:11:16 -0400 |
commit | 22f26895eca8e99f795368a9a7167852c1805a1e (patch) | |
tree | 350df1a05503ba0dd7f06f8dd9911ffb233f415c /src | |
parent | b92f54639a241210af1ec74f9a6d6226636f7e83 (diff) | |
download | craftbukkit-22f26895eca8e99f795368a9a7167852c1805a1e.tar craftbukkit-22f26895eca8e99f795368a9a7167852c1805a1e.tar.gz craftbukkit-22f26895eca8e99f795368a9a7167852c1805a1e.tar.lz craftbukkit-22f26895eca8e99f795368a9a7167852c1805a1e.tar.xz craftbukkit-22f26895eca8e99f795368a9a7167852c1805a1e.zip |
Added Redstone event support for detector rails.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/net/minecraft/server/BlockMinecartDetector.java | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/BlockMinecartDetector.java b/src/main/java/net/minecraft/server/BlockMinecartDetector.java new file mode 100644 index 00000000..2df1f388 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockMinecartDetector.java @@ -0,0 +1,101 @@ +package net.minecraft.server; + +import java.util.List; +import java.util.Random; + +// CraftBukkit start +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.Cancellable; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockRedstoneEvent; +// CraftBukkit end + +public class BlockMinecartDetector extends BlockMinecartTrack { + + public BlockMinecartDetector(int i, int j) { + super(i, j, true); + this.a(true); + } + + public int c() { + return 20; + } + + public boolean isPowerSource() { + return true; + } + + public void a(World world, int i, int j, int k, Entity entity) { + if (!world.isStatic) { + int l = world.getData(i, j, k); + + if ((l & 8) == 0) { + this.g(world, i, j, k, l); + } + } + } + + public void a(World world, int i, int j, int k, Random random) { + if (!world.isStatic) { + int l = world.getData(i, j, k); + + if ((l & 8) != 0) { + this.g(world, i, j, k, l); + } + } + } + + public boolean a(IBlockAccess iblockaccess, int i, int j, int k, int l) { + return (iblockaccess.getData(i, j, k) & 8) != 0; + } + + public boolean c(World world, int i, int j, int k, int l) { + return (world.getData(i, j, k) & 8) == 0 ? false : l == 1; + } + + private void g(World world, int i, int j, int k, int l) { + boolean flag = (l & 8) != 0; + boolean flag1 = false; + float f = 0.125F; + List list = world.a(EntityMinecart.class, AxisAlignedBB.b((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) j + 0.25D, (double) ((float) (k + 1) - f))); + + if (list.size() > 0) { + flag1 = true; + } + + // CraftBukkit start + if (flag != flag1) { + CraftServer server = world.getServer(); + CraftWorld craftWorld = world.getWorld(); + CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k); + + BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, flag ? 1 : 0, flag1 ? 1 : 0); + server.getPluginManager().callEvent(eventRedstone); + + flag1 = eventRedstone.getNewCurrent() > 0; + } + // CraftBukkit end + + if (flag1 && !flag) { + world.setData(i, j, k, l | 8); + world.applyPhysics(i, j, k, this.id); + world.applyPhysics(i, j - 1, k, this.id); + world.b(i, j, k, i, j, k); + } + + if (!flag1 && flag) { + world.setData(i, j, k, l & 7); + world.applyPhysics(i, j, k, this.id); + world.applyPhysics(i, j - 1, k, this.id); + world.b(i, j, k, i, j, k); + } + + if (flag1) { + world.c(i, j, k, this.id, this.c()); + } + } +} |