Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 374 lines 14 kB view raw
1package net.minecraft.server; 2 3import com.legacyminecraft.poseidon.PoseidonConfig; 4import org.bukkit.event.block.BlockPistonExtendEvent; 5import org.bukkit.event.block.BlockPistonRetractEvent; 6 7import java.util.ArrayList; 8 9// CraftBukkit start 10// CraftBukkit end 11 12public class BlockPiston extends Block { 13 14 private boolean a; 15 private boolean b; 16 17 public BlockPiston(int i, int j, boolean flag) { 18 super(i, j, Material.PISTON); 19 this.a = flag; 20 this.a(h); 21 this.c(0.5F); 22 } 23 24 public int a(int i, int j) { 25 int k = c(j); 26 27 return k > 5 ? this.textureId : (i == k ? (!d(j) && this.minX <= 0.0D && this.minY <= 0.0D && this.minZ <= 0.0D && this.maxX >= 1.0D && this.maxY >= 1.0D && this.maxZ >= 1.0D ? this.textureId : 110) : (i == PistonBlockTextures.a[k] ? 109 : 108)); 28 } 29 30 public boolean a() { 31 return false; 32 } 33 34 public boolean interact(World world, int i, int j, int k, EntityHuman entityhuman) { 35 return false; 36 } 37 38 public void postPlace(World world, int i, int j, int k, EntityLiving entityliving) { 39 int l = c(world, i, j, k, (EntityHuman) entityliving); 40 41 world.setData(i, j, k, l); 42 if (!world.isStatic) { 43 this.g(world, i, j, k); 44 } 45 } 46 47 public void doPhysics(World world, int i, int j, int k, int l) { 48 if (!world.isStatic && !this.b) { 49 this.g(world, i, j, k); 50 } 51 } 52 53 public void c(World world, int i, int j, int k) { 54 if (!world.isStatic && world.getTileEntity(i, j, k) == null) { 55 this.g(world, i, j, k); 56 } 57 } 58 59 private void g(World world, int i, int j, int k) { 60 int l = world.getData(i, j, k); 61 int i1 = c(l); 62 boolean flag = this.f(world, i, j, k, i1); 63 64 if (l != 7) { 65 if (flag && !d(l)) { 66 // CraftBukkit start 67 int length; 68 try { 69 length = h(world, i, j, k, i1); 70 } catch (RuntimeException exception) { 71 System.out.println("[Poseidon] A piston crash attempt occurred at " + i + " " + j + " " + k + " in " + world.getWorld().getName()); 72 return; 73 } 74 if (length >= 0) { 75 org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k); 76 77 BlockPistonExtendEvent event = new BlockPistonExtendEvent(block, length); 78 world.getServer().getPluginManager().callEvent(event); 79 80 if (event.isCancelled()) { 81 return; 82 } 83 // CraftBukkit end 84 85 world.setRawData(i, j, k, i1 | 8); 86 world.playNote(i, j, k, 0, i1); 87 } 88 } else if (!flag && d(l)) { 89 // CraftBukkit start 90 org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k); 91 92 BlockPistonRetractEvent event = new BlockPistonRetractEvent(block); 93 world.getServer().getPluginManager().callEvent(event); 94 95 if (event.isCancelled()) { 96 return; 97 } 98 // CraftBukkit end 99 100 world.setRawData(i, j, k, i1); 101 world.playNote(i, j, k, 1, i1); 102 } 103 } 104 } 105 106 private boolean f(World world, int i, int j, int k, int l) { 107 return l != 0 && world.isBlockFaceIndirectlyPowered(i, j - 1, k, 0) ? true : (l != 1 && world.isBlockFaceIndirectlyPowered(i, j + 1, k, 1) ? true : (l != 2 && world.isBlockFaceIndirectlyPowered(i, j, k - 1, 2) ? true : (l != 3 && world.isBlockFaceIndirectlyPowered(i, j, k + 1, 3) ? true : (l != 5 && world.isBlockFaceIndirectlyPowered(i + 1, j, k, 5) ? true : (l != 4 && world.isBlockFaceIndirectlyPowered(i - 1, j, k, 4) ? true : (world.isBlockFaceIndirectlyPowered(i, j, k, 0) ? true : (world.isBlockFaceIndirectlyPowered(i, j + 2, k, 1) ? true : (world.isBlockFaceIndirectlyPowered(i, j + 1, k - 1, 2) ? true : (world.isBlockFaceIndirectlyPowered(i, j + 1, k + 1, 3) ? true : (world.isBlockFaceIndirectlyPowered(i - 1, j + 1, k, 4) ? true : world.isBlockFaceIndirectlyPowered(i + 1, j + 1, k, 5))))))))))); 108 } 109 110 public void a(World world, int i, int j, int k, int l, int i1) { 111 this.b = true; 112 if (l == 0) { 113 if (this.i(world, i, j, k, i1)) { 114 world.setData(i, j, k, i1 | 8); 115 world.makeSound((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "tile.piston.out", 0.5F, world.random.nextFloat() * 0.25F + 0.6F); 116 } 117 } else if (l == 1) { 118 TileEntity tileentity = world.getTileEntity(i + PistonBlockTextures.b[i1], j + PistonBlockTextures.c[i1], k + PistonBlockTextures.d[i1]); 119 120 if (tileentity != null && tileentity instanceof TileEntityPiston) { 121 ((TileEntityPiston) tileentity).k(); 122 } 123 124 world.setRawTypeIdAndData(i, j, k, Block.PISTON_MOVING.id, i1); 125 world.setTileEntity(i, j, k, BlockPistonMoving.a(this.id, i1, i1, false, true)); 126 if (this.a) { 127 int j1 = i + PistonBlockTextures.b[i1] * 2; 128 int k1 = j + PistonBlockTextures.c[i1] * 2; 129 int l1 = k + PistonBlockTextures.d[i1] * 2; 130 int i2 = world.getTypeId(j1, k1, l1); 131 int j2 = world.getData(j1, k1, l1); 132 boolean flag = false; 133 134 if (i2 == Block.PISTON_MOVING.id) { 135 TileEntity tileentity1 = world.getTileEntity(j1, k1, l1); 136 137 if (tileentity1 != null && tileentity1 instanceof TileEntityPiston) { 138 TileEntityPiston tileentitypiston = (TileEntityPiston) tileentity1; 139 140 if (tileentitypiston.d() == i1 && tileentitypiston.c()) { 141 tileentitypiston.k(); 142 i2 = tileentitypiston.a(); 143 j2 = tileentitypiston.e(); 144 flag = true; 145 } 146 } 147 } 148 149 if (!flag && i2 > 0 && a(i2, world, j1, k1, l1, false) && (Block.byId[i2].e() == 0 || i2 == Block.PISTON.id || i2 == Block.PISTON_STICKY.id)) { 150 this.b = false; 151 world.setTypeId(j1, k1, l1, 0); 152 this.b = true; 153 i += PistonBlockTextures.b[i1]; 154 j += PistonBlockTextures.c[i1]; 155 k += PistonBlockTextures.d[i1]; 156 world.setRawTypeIdAndData(i, j, k, Block.PISTON_MOVING.id, j2); 157 world.setTileEntity(i, j, k, BlockPistonMoving.a(i2, j2, i1, false, false)); 158 } else if (!flag) { 159 this.b = false; 160 world.setTypeId(i + PistonBlockTextures.b[i1], j + PistonBlockTextures.c[i1], k + PistonBlockTextures.d[i1], 0); 161 this.b = true; 162 } 163 } else { 164 this.b = false; 165 world.setTypeId(i + PistonBlockTextures.b[i1], j + PistonBlockTextures.c[i1], k + PistonBlockTextures.d[i1], 0); 166 this.b = true; 167 } 168 169 world.makeSound((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "tile.piston.in", 0.5F, world.random.nextFloat() * 0.15F + 0.6F); 170 } 171 172 this.b = false; 173 } 174 175 public void a(IBlockAccess iblockaccess, int i, int j, int k) { 176 int l = iblockaccess.getData(i, j, k); 177 178 if (d(l)) { 179 switch (c(l)) { 180 case 0: 181 this.a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F); 182 break; 183 184 case 1: 185 this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F); 186 break; 187 188 case 2: 189 this.a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F); 190 break; 191 192 case 3: 193 this.a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F); 194 break; 195 196 case 4: 197 this.a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 198 break; 199 200 case 5: 201 this.a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F); 202 } 203 } else { 204 this.a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 205 } 206 } 207 208 public void a(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, ArrayList arraylist) { 209 this.a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 210 super.a(world, i, j, k, axisalignedbb, arraylist); 211 } 212 213 public boolean b() { 214 return false; 215 } 216 217 public static int c(int i) { 218 return i & 7; 219 } 220 221 public static boolean d(int i) { 222 return (i & 8) != 0; 223 } 224 225 private static int c(World world, int i, int j, int k, EntityHuman entityhuman) { 226 if (MathHelper.abs((float) entityhuman.locX - (float) i) < 2.0F && MathHelper.abs((float) entityhuman.locZ - (float) k) < 2.0F) { 227 double d0 = entityhuman.locY + 1.82D - (double) entityhuman.height; 228 229 if (d0 - (double) j > 2.0D) { 230 return 1; 231 } 232 233 if ((double) j - d0 > 0.0D) { 234 return 0; 235 } 236 } 237 238 int l = MathHelper.floor((double) (entityhuman.yaw * 4.0F / 360.0F) + 0.5D) & 3; 239 240 return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0))); 241 } 242 243 private static boolean a(int i, World world, int j, int k, int l, boolean flag) { 244 if (i == Block.OBSIDIAN.id) { 245 return false; 246 } else if ((i == Block.FURNACE.id || i == Block.BURNING_FURNACE.id) && PoseidonConfig.getInstance().getBoolean("world.settings.block-pistons-pushing-furnaces.enabled", true)) { 247// System.out.println("Blocking a piston from being pushed."); 248 return false; 249 } else { 250 if (i != Block.PISTON.id && i != Block.PISTON_STICKY.id) { 251 if (Block.byId[i].j() == -1.0F) { 252 return false; 253 } 254 255 if (Block.byId[i].e() == 2) { 256 return false; 257 } 258 259 if (!flag && Block.byId[i].e() == 1) { 260 return false; 261 } 262 } else if (d(world.getData(j, k, l))) { 263 return false; 264 } 265 266 TileEntity tileentity = world.getTileEntity(j, k, l); 267 268 return tileentity == null; 269 } 270 } 271 272 // CraftBukkkit boolean -> int 273 private static int h(World world, int i, int j, int k, int l) { 274 int i1 = i + PistonBlockTextures.b[l]; 275 int j1 = j + PistonBlockTextures.c[l]; 276 int k1 = k + PistonBlockTextures.d[l]; 277 int l1 = 0; 278 279 while (true) { 280 if (l1 < 13) { 281 if (j1 <= 0 || j1 >= 127) { 282 return -1; // CraftBukkit 283 } 284 285 int i2 = world.getTypeId(i1, j1, k1); 286 287 if (i2 != 0) { 288 if (!a(i2, world, i1, j1, k1, true)) { 289 return -1; // CraftBukkit 290 } 291 292 if (Block.byId[i2].e() != 1) { 293 if (l1 == 12) { 294 return -1; // CraftBukkit 295 } 296 297 i1 += PistonBlockTextures.b[l]; 298 j1 += PistonBlockTextures.c[l]; 299 k1 += PistonBlockTextures.d[l]; 300 ++l1; 301 continue; 302 } 303 } 304 } 305 306 return l1; // CraftBukkit 307 } 308 } 309 310 private boolean i(World world, int i, int j, int k, int l) { 311 int i1 = i + PistonBlockTextures.b[l]; 312 int j1 = j + PistonBlockTextures.c[l]; 313 int k1 = k + PistonBlockTextures.d[l]; 314 int l1 = 0; 315 316 while (true) { 317 int i2; 318 319 if (l1 < 13) { 320 if (j1 <= 0 || j1 >= 127) { 321 return false; 322 } 323 324 i2 = world.getTypeId(i1, j1, k1); 325 if (i2 != 0) { 326 if (!a(i2, world, i1, j1, k1, true)) { 327 return false; 328 } 329 330 if (Block.byId[i2].e() != 1) { 331 if (l1 == 12) { 332 return false; 333 } 334 335 i1 += PistonBlockTextures.b[l]; 336 j1 += PistonBlockTextures.c[l]; 337 k1 += PistonBlockTextures.d[l]; 338 ++l1; 339 continue; 340 } 341 342 Block.byId[i2].g(world, i1, j1, k1, world.getData(i1, j1, k1)); 343 if (PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.other-fixes.enabled", true)) { 344 world.setRawTypeId(i1, j1, k1, 0); 345 } else { 346 world.setTypeId(i1, j1, k1, 0); 347 } 348 } 349 } 350 351 while (i1 != i || j1 != j || k1 != k) { 352 l1 = i1 - PistonBlockTextures.b[l]; 353 i2 = j1 - PistonBlockTextures.c[l]; 354 int j2 = k1 - PistonBlockTextures.d[l]; 355 int k2 = world.getTypeId(l1, i2, j2); 356 int l2 = world.getData(l1, i2, j2); 357 358 if (k2 == this.id && l1 == i && i2 == j && j2 == k) { 359 world.setRawTypeIdAndData(i1, j1, k1, Block.PISTON_MOVING.id, l | (this.a ? 8 : 0)); 360 world.setTileEntity(i1, j1, k1, BlockPistonMoving.a(Block.PISTON_EXTENSION.id, l | (this.a ? 8 : 0), l, true, false)); 361 } else { 362 world.setRawTypeIdAndData(i1, j1, k1, Block.PISTON_MOVING.id, l2); 363 world.setTileEntity(i1, j1, k1, BlockPistonMoving.a(k2, l2, l, true, false)); 364 } 365 366 i1 = l1; 367 j1 = i2; 368 k1 = j2; 369 } 370 371 return true; 372 } 373 } 374}