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.Random;
6
7public class BlockDoor extends Block {
8
9 protected BlockDoor(int i, Material material) {
10 super(i, material);
11 this.textureId = 97;
12 if (material == Material.ORE) {
13 ++this.textureId;
14 }
15
16 float f = 0.5F;
17 float f1 = 1.0F;
18
19 this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
20 }
21
22 public int a(int i, int j) {
23 if (i != 0 && i != 1) {
24 int k = this.d(j);
25
26 if ((k == 0 || k == 2) ^ i <= 3) {
27 return this.textureId;
28 } else {
29 int l = k / 2 + (i & 1 ^ k);
30
31 l += (j & 4) / 4;
32 int i1 = this.textureId - (j & 8) * 2;
33
34 if ((l & 1) != 0) {
35 i1 = -i1;
36 }
37
38 return i1;
39 }
40 } else {
41 return this.textureId;
42 }
43 }
44
45 public boolean a() {
46 return false;
47 }
48
49 public boolean b() {
50 return false;
51 }
52
53 public AxisAlignedBB e(World world, int i, int j, int k) {
54 this.a(world, i, j, k);
55 return super.e(world, i, j, k);
56 }
57
58 public void a(IBlockAccess iblockaccess, int i, int j, int k) {
59 this.c(this.d(iblockaccess.getData(i, j, k)));
60 }
61
62 public void c(int i) {
63 float f = 0.1875F;
64
65 this.a(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
66 if (i == 0) {
67 this.a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
68 }
69
70 if (i == 1) {
71 this.a(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
72 }
73
74 if (i == 2) {
75 this.a(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
76 }
77
78 if (i == 3) {
79 this.a(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
80 }
81 }
82
83 public void b(World world, int i, int j, int k, EntityHuman entityhuman) {
84 this.interact(world, i, j, k, entityhuman);
85 }
86
87 public boolean interact(World world, int i, int j, int k, EntityHuman entityhuman) {
88 if (this.material == Material.ORE) {
89 return true;
90 } else {
91 int l = world.getData(i, j, k);
92
93 if ((l & 8) != 0) {
94 if (world.getTypeId(i, j - 1, k) == this.id) {
95 this.interact(world, i, j - 1, k, entityhuman);
96 }
97
98 return true;
99 } else {
100 if (world.getTypeId(i, j + 1, k) == this.id) {
101 world.setData(i, j + 1, k, (l ^ 4) + 8);
102 }
103
104 world.setData(i, j, k, l ^ 4);
105 world.b(i, j - 1, k, i, j, k);
106 world.a(entityhuman, 1003, i, j, k, 0);
107 return true;
108 }
109 }
110 }
111
112 public void setDoor(World world, int i, int j, int k, boolean flag) {
113 int l = world.getData(i, j, k);
114
115 if ((l & 8) != 0) {
116 if (world.getTypeId(i, j - 1, k) == this.id) {
117 this.setDoor(world, i, j - 1, k, flag);
118 }
119 } else {
120 boolean flag1 = (world.getData(i, j, k) & 4) > 0;
121
122 if (flag1 != flag) {
123 if (world.getTypeId(i, j + 1, k) == this.id) {
124 world.setData(i, j + 1, k, (l ^ 4) + 8);
125 }
126
127 world.setData(i, j, k, l ^ 4);
128 world.b(i, j - 1, k, i, j, k);
129 world.a((EntityHuman) null, 1003, i, j, k, 0);
130 }
131 }
132 }
133
134 public void doPhysics(World world, int i, int j, int k, int l) {
135 int i1 = world.getData(i, j, k);
136
137 if ((i1 & 8) != 0) {
138 if (world.getTypeId(i, j - 1, k) != this.id) {
139 world.setTypeId(i, j, k, 0);
140 }
141
142 if (l > 0 && Block.byId[l].isPowerSource()) {
143 this.doPhysics(world, i, j - 1, k, l);
144 }
145 } else {
146 boolean flag = false;
147
148 if (world.getTypeId(i, j + 1, k) != this.id) {
149 world.setTypeId(i, j, k, 0);
150 flag = true;
151 }
152
153 if (!world.e(i, j - 1, k)) {
154 world.setTypeId(i, j, k, 0);
155 flag = true;
156 if (world.getTypeId(i, j + 1, k) == this.id) {
157 world.setTypeId(i, j + 1, k, 0);
158 }
159 }
160
161 if (flag) {
162 if (!world.isStatic) {
163 this.g(world, i, j, k, i1);
164 }
165 } else if (l > 0 && Block.byId[l].isPowerSource()) {
166 // CraftBukkit start
167 org.bukkit.World bworld = world.getWorld();
168 org.bukkit.block.Block block = bworld.getBlockAt(i, j, k);
169 org.bukkit.block.Block blockTop = bworld.getBlockAt(i, j + 1, k);
170
171 int power = block.getBlockPower();
172 int powerTop = blockTop.getBlockPower();
173 if (powerTop > power) power = powerTop;
174 int oldPower = (world.getData(i, j, k) & 4) > 0 ? 15 : 0;
175
176 if (oldPower == 0 ^ power == 0) {
177 BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, oldPower, power);
178 world.getServer().getPluginManager().callEvent(eventRedstone);
179
180 this.setDoor(world, i, j, k, eventRedstone.getNewCurrent() > 0);
181 }
182 // CraftBukkit end
183 }
184 }
185 }
186
187 public int a(int i, Random random) {
188 return (i & 8) != 0 ? 0 : (this.material == Material.ORE ? Item.IRON_DOOR.id : Item.WOOD_DOOR.id);
189 }
190
191 public MovingObjectPosition a(World world, int i, int j, int k, Vec3D vec3d, Vec3D vec3d1) {
192 this.a(world, i, j, k);
193 return super.a(world, i, j, k, vec3d, vec3d1);
194 }
195
196 public int d(int i) {
197 return (i & 4) == 0 ? i - 1 & 3 : i & 3;
198 }
199
200 public boolean canPlace(World world, int i, int j, int k) {
201 return j >= 127 ? false : world.e(i, j - 1, k) && super.canPlace(world, i, j, k) && super.canPlace(world, i, j + 1, k);
202 }
203
204 public static boolean e(int i) {
205 return (i & 4) != 0;
206 }
207
208 public int e() {
209 return 1;
210 }
211}