Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import org.bukkit.event.block.BlockRedstoneEvent;
4
5import java.util.List;
6import java.util.Random;
7
8public class BlockMinecartDetector extends BlockMinecartTrack {
9
10 public BlockMinecartDetector(int i, int j) {
11 super(i, j, true);
12 this.a(true);
13 }
14
15 public int c() {
16 return 20;
17 }
18
19 public boolean isPowerSource() {
20 return true;
21 }
22
23 public void a(World world, int i, int j, int k, Entity entity) {
24 if (!world.isStatic) {
25 int l = world.getData(i, j, k);
26
27 if ((l & 8) == 0) {
28 this.f(world, i, j, k, l);
29 }
30 }
31 }
32
33 public void a(World world, int i, int j, int k, Random random) {
34 if (!world.isStatic) {
35 int l = world.getData(i, j, k);
36
37 if ((l & 8) != 0) {
38 this.f(world, i, j, k, l);
39 }
40 }
41 }
42
43 public boolean a(IBlockAccess iblockaccess, int i, int j, int k, int l) {
44 return (iblockaccess.getData(i, j, k) & 8) != 0;
45 }
46
47 public boolean d(World world, int i, int j, int k, int l) {
48 return (world.getData(i, j, k) & 8) == 0 ? false : l == 1;
49 }
50
51 private void f(World world, int i, int j, int k, int l) {
52 boolean flag = (l & 8) != 0;
53 boolean flag1 = false;
54 float f = 0.125F;
55 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)));
56
57 if (list.size() > 0) {
58 flag1 = true;
59 }
60
61 // CraftBukkit start
62 if (flag != flag1) {
63 org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k);
64
65 BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, flag ? 1 : 0, flag1 ? 1 : 0);
66 world.getServer().getPluginManager().callEvent(eventRedstone);
67
68 flag1 = eventRedstone.getNewCurrent() > 0;
69 }
70 // CraftBukkit end
71
72 if (flag1 && !flag) {
73 world.setData(i, j, k, l | 8);
74 world.applyPhysics(i, j, k, this.id);
75 world.applyPhysics(i, j - 1, k, this.id);
76 world.b(i, j, k, i, j, k);
77 }
78
79 if (!flag1 && flag) {
80 world.setData(i, j, k, l & 7);
81 world.applyPhysics(i, j, k, this.id);
82 world.applyPhysics(i, j - 1, k, this.id);
83 world.b(i, j, k, i, j, k);
84 }
85
86 if (flag1) {
87 world.c(i, j, k, this.id, this.c());
88 }
89 }
90}