Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 357 lines 11 kB view raw
1package net.minecraft.server; 2 3import org.bukkit.event.block.BlockRedstoneEvent; 4 5import java.util.ArrayList; 6import java.util.HashSet; 7import java.util.Random; 8import java.util.Set; 9 10public class BlockRedstoneWire extends Block { 11 12 private boolean a = true; 13 private Set b = new HashSet(); 14 15 public BlockRedstoneWire(int i, int j) { 16 super(i, j, Material.ORIENTABLE); 17 this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F); 18 } 19 20 public int a(int i, int j) { 21 return this.textureId; 22 } 23 24 public AxisAlignedBB e(World world, int i, int j, int k) { 25 return null; 26 } 27 28 public boolean a() { 29 return false; 30 } 31 32 public boolean b() { 33 return false; 34 } 35 36 public boolean canPlace(World world, int i, int j, int k) { 37 return world.e(i, j - 1, k); 38 } 39 40 private void g(World world, int i, int j, int k) { 41 this.a(world, i, j, k, i, j, k); 42 ArrayList arraylist = new ArrayList(this.b); 43 44 this.b.clear(); 45 46 for (int l = 0; l < arraylist.size(); ++l) { 47 ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l); 48 49 world.applyPhysics(chunkposition.x, chunkposition.y, chunkposition.z, this.id); 50 } 51 } 52 53 private void a(World world, int i, int j, int k, int l, int i1, int j1) { 54 int k1 = world.getData(i, j, k); 55 int l1 = 0; 56 57 this.a = false; 58 boolean flag = world.isBlockIndirectlyPowered(i, j, k); 59 60 this.a = true; 61 int i2; 62 int j2; 63 int k2; 64 65 if (flag) { 66 l1 = 15; 67 } else { 68 for (i2 = 0; i2 < 4; ++i2) { 69 j2 = i; 70 k2 = k; 71 if (i2 == 0) { 72 j2 = i - 1; 73 } 74 75 if (i2 == 1) { 76 ++j2; 77 } 78 79 if (i2 == 2) { 80 k2 = k - 1; 81 } 82 83 if (i2 == 3) { 84 ++k2; 85 } 86 87 if (j2 != l || j != i1 || k2 != j1) { 88 l1 = this.getPower(world, j2, j, k2, l1); 89 } 90 91 if (world.e(j2, j, k2) && !world.e(i, j + 1, k)) { 92 if (j2 != l || j + 1 != i1 || k2 != j1) { 93 l1 = this.getPower(world, j2, j + 1, k2, l1); 94 } 95 } else if (!world.e(j2, j, k2) && (j2 != l || j - 1 != i1 || k2 != j1)) { 96 l1 = this.getPower(world, j2, j - 1, k2, l1); 97 } 98 } 99 100 if (l1 > 0) { 101 --l1; 102 } else { 103 l1 = 0; 104 } 105 } 106 107 // CraftBukkit start 108 if (k1 != l1) { 109 BlockRedstoneEvent event = new BlockRedstoneEvent(world.getWorld().getBlockAt(i, j, k), k1, l1); 110 world.getServer().getPluginManager().callEvent(event); 111 112 l1 = event.getNewCurrent(); 113 } 114 // CraftBukkit end 115 116 if (k1 != l1) { 117 world.suppressPhysics = true; 118 world.setData(i, j, k, l1); 119 world.b(i, j, k, i, j, k); 120 world.suppressPhysics = false; 121 122 for (i2 = 0; i2 < 4; ++i2) { 123 j2 = i; 124 k2 = k; 125 int l2 = j - 1; 126 127 if (i2 == 0) { 128 j2 = i - 1; 129 } 130 131 if (i2 == 1) { 132 ++j2; 133 } 134 135 if (i2 == 2) { 136 k2 = k - 1; 137 } 138 139 if (i2 == 3) { 140 ++k2; 141 } 142 143 if (world.e(j2, j, k2)) { 144 l2 += 2; 145 } 146 147 boolean flag1 = false; 148 int i3 = this.getPower(world, j2, j, k2, -1); 149 150 l1 = world.getData(i, j, k); 151 if (l1 > 0) { 152 --l1; 153 } 154 155 if (i3 >= 0 && i3 != l1) { 156 this.a(world, j2, j, k2, i, j, k); 157 } 158 159 i3 = this.getPower(world, j2, l2, k2, -1); 160 l1 = world.getData(i, j, k); 161 if (l1 > 0) { 162 --l1; 163 } 164 165 if (i3 >= 0 && i3 != l1) { 166 this.a(world, j2, l2, k2, i, j, k); 167 } 168 } 169 170 if (k1 == 0 || l1 == 0) { 171 this.b.add(new ChunkPosition(i, j, k)); 172 this.b.add(new ChunkPosition(i - 1, j, k)); 173 this.b.add(new ChunkPosition(i + 1, j, k)); 174 this.b.add(new ChunkPosition(i, j - 1, k)); 175 this.b.add(new ChunkPosition(i, j + 1, k)); 176 this.b.add(new ChunkPosition(i, j, k - 1)); 177 this.b.add(new ChunkPosition(i, j, k + 1)); 178 } 179 } 180 } 181 182 private void h(World world, int i, int j, int k) { 183 if (world.getTypeId(i, j, k) == this.id) { 184 world.applyPhysics(i, j, k, this.id); 185 world.applyPhysics(i - 1, j, k, this.id); 186 world.applyPhysics(i + 1, j, k, this.id); 187 world.applyPhysics(i, j, k - 1, this.id); 188 world.applyPhysics(i, j, k + 1, this.id); 189 world.applyPhysics(i, j - 1, k, this.id); 190 world.applyPhysics(i, j + 1, k, this.id); 191 } 192 } 193 194 public void c(World world, int i, int j, int k) { 195 super.c(world, i, j, k); 196 if (!world.isStatic) { 197 this.g(world, i, j, k); 198 world.applyPhysics(i, j + 1, k, this.id); 199 world.applyPhysics(i, j - 1, k, this.id); 200 this.h(world, i - 1, j, k); 201 this.h(world, i + 1, j, k); 202 this.h(world, i, j, k - 1); 203 this.h(world, i, j, k + 1); 204 if (world.e(i - 1, j, k)) { 205 this.h(world, i - 1, j + 1, k); 206 } else { 207 this.h(world, i - 1, j - 1, k); 208 } 209 210 if (world.e(i + 1, j, k)) { 211 this.h(world, i + 1, j + 1, k); 212 } else { 213 this.h(world, i + 1, j - 1, k); 214 } 215 216 if (world.e(i, j, k - 1)) { 217 this.h(world, i, j + 1, k - 1); 218 } else { 219 this.h(world, i, j - 1, k - 1); 220 } 221 222 if (world.e(i, j, k + 1)) { 223 this.h(world, i, j + 1, k + 1); 224 } else { 225 this.h(world, i, j - 1, k + 1); 226 } 227 } 228 } 229 230 public void remove(World world, int i, int j, int k) { 231 super.remove(world, i, j, k); 232 if (!world.isStatic) { 233 world.applyPhysics(i, j + 1, k, this.id); 234 world.applyPhysics(i, j - 1, k, this.id); 235 this.g(world, i, j, k); 236 this.h(world, i - 1, j, k); 237 this.h(world, i + 1, j, k); 238 this.h(world, i, j, k - 1); 239 this.h(world, i, j, k + 1); 240 if (world.e(i - 1, j, k)) { 241 this.h(world, i - 1, j + 1, k); 242 } else { 243 this.h(world, i - 1, j - 1, k); 244 } 245 246 if (world.e(i + 1, j, k)) { 247 this.h(world, i + 1, j + 1, k); 248 } else { 249 this.h(world, i + 1, j - 1, k); 250 } 251 252 if (world.e(i, j, k - 1)) { 253 this.h(world, i, j + 1, k - 1); 254 } else { 255 this.h(world, i, j - 1, k - 1); 256 } 257 258 if (world.e(i, j, k + 1)) { 259 this.h(world, i, j + 1, k + 1); 260 } else { 261 this.h(world, i, j - 1, k + 1); 262 } 263 } 264 } 265 266 // CraftBukkit - private -> public 267 public int getPower(World world, int i, int j, int k, int l) { 268 if (world.getTypeId(i, j, k) != this.id) { 269 return l; 270 } else { 271 int i1 = world.getData(i, j, k); 272 273 return i1 > l ? i1 : l; 274 } 275 } 276 277 public void doPhysics(World world, int i, int j, int k, int l) { 278 if (!world.isStatic) { 279 int i1 = world.getData(i, j, k); 280 boolean flag = this.canPlace(world, i, j, k); 281 282 if (!flag) { 283 this.g(world, i, j, k, i1); 284 world.setTypeId(i, j, k, 0); 285 } else { 286 this.g(world, i, j, k); 287 } 288 289 super.doPhysics(world, i, j, k, l); 290 } 291 } 292 293 public int a(int i, Random random) { 294 return Item.REDSTONE.id; 295 } 296 297 public boolean d(World world, int i, int j, int k, int l) { 298 return !this.a ? false : this.a(world, i, j, k, l); 299 } 300 301 public boolean a(IBlockAccess iblockaccess, int i, int j, int k, int l) { 302 if (!this.a) { 303 return false; 304 } else if (iblockaccess.getData(i, j, k) == 0) { 305 return false; 306 } else if (l == 1) { 307 return true; 308 } else { 309 boolean flag = c(iblockaccess, i - 1, j, k, 1) || !iblockaccess.e(i - 1, j, k) && c(iblockaccess, i - 1, j - 1, k, -1); 310 boolean flag1 = c(iblockaccess, i + 1, j, k, 3) || !iblockaccess.e(i + 1, j, k) && c(iblockaccess, i + 1, j - 1, k, -1); 311 boolean flag2 = c(iblockaccess, i, j, k - 1, 2) || !iblockaccess.e(i, j, k - 1) && c(iblockaccess, i, j - 1, k - 1, -1); 312 boolean flag3 = c(iblockaccess, i, j, k + 1, 0) || !iblockaccess.e(i, j, k + 1) && c(iblockaccess, i, j - 1, k + 1, -1); 313 314 if (!iblockaccess.e(i, j + 1, k)) { 315 if (iblockaccess.e(i - 1, j, k) && c(iblockaccess, i - 1, j + 1, k, -1)) { 316 flag = true; 317 } 318 319 if (iblockaccess.e(i + 1, j, k) && c(iblockaccess, i + 1, j + 1, k, -1)) { 320 flag1 = true; 321 } 322 323 if (iblockaccess.e(i, j, k - 1) && c(iblockaccess, i, j + 1, k - 1, -1)) { 324 flag2 = true; 325 } 326 327 if (iblockaccess.e(i, j, k + 1) && c(iblockaccess, i, j + 1, k + 1, -1)) { 328 flag3 = true; 329 } 330 } 331 332 return !flag2 && !flag1 && !flag && !flag3 && l >= 2 && l <= 5 ? true : (l == 2 && flag2 && !flag && !flag1 ? true : (l == 3 && flag3 && !flag && !flag1 ? true : (l == 4 && flag && !flag2 && !flag3 ? true : l == 5 && flag1 && !flag2 && !flag3))); 333 } 334 } 335 336 public boolean isPowerSource() { 337 return this.a; 338 } 339 340 public static boolean c(IBlockAccess iblockaccess, int i, int j, int k, int l) { 341 int i1 = iblockaccess.getTypeId(i, j, k); 342 343 if (i1 == Block.REDSTONE_WIRE.id) { 344 return true; 345 } else if (i1 == 0) { 346 return false; 347 } else if (Block.byId[i1].isPowerSource()) { 348 return true; 349 } else if (i1 != Block.DIODE_OFF.id && i1 != Block.DIODE_ON.id) { 350 return false; 351 } else { 352 int j1 = iblockaccess.getData(i, j, k); 353 354 return l == BedBlockTextures.b[j1 & 3]; 355 } 356 } 357}