Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 336 lines 14 kB view raw
1package net.minecraft.server; 2 3import java.util.Random; 4 5import org.bukkit.event.block.BlockBurnEvent; 6import org.bukkit.event.block.BlockIgniteEvent; 7import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; 8import org.bukkit.event.block.BlockSpreadEvent; 9import org.bukkit.material.MaterialData; 10 11import uk.betacraft.uberbukkit.Uberbukkit; 12import uk.betacraft.uberbukkit.UberbukkitConfig; 13 14// CraftBukkit start 15// CraftBukkit end 16 17public class BlockFire extends Block { 18 19 private int[] a = new int[256]; 20 private int[] b = new int[256]; 21 22 protected BlockFire(int i, int j) { 23 super(i, j, Material.FIRE); 24 this.a(true); 25 } 26 27 public void h() { 28 this.a(Block.WOOD.id, 5, 20); 29 this.a(Block.LOG.id, 5, 5); 30 this.a(Block.LEAVES.id, 30, 60); 31 this.a(Block.BOOKSHELF.id, 30, 20); 32 this.a(Block.TNT.id, 15, 100); 33 this.a(Block.LONG_GRASS.id, 60, 100); 34 this.a(Block.WOOL.id, 30, 60); 35 36 // uberbukkit 37 if (UberbukkitConfig.getInstance().getBoolean("mechanics.flammable_fences_stairs", true)) { 38 this.a(Block.FENCE.id, 5, 20); 39 this.a(Block.WOOD_STAIRS.id, 5, 20); 40 } 41 } 42 43 private void a(int i, int j, int k) { 44 this.a[i] = j; 45 this.b[i] = k; 46 } 47 48 public AxisAlignedBB e(World world, int i, int j, int k) { 49 return null; 50 } 51 52 public boolean a() { 53 return false; 54 } 55 56 public boolean b() { 57 return false; 58 } 59 60 public int a(Random random) { 61 return 0; 62 } 63 64 public int c() { 65 // uberbukkit 66 return UberbukkitConfig.getInstance().getBoolean("mechanics.pre_1_6_fire", false) ? 10 : 40; 67 } 68 69 public void a(World world, int i, int j, int k, Random random) { 70 boolean flag = world.getTypeId(i, j - 1, k) == Block.NETHERRACK.id; 71 boolean oldFire = UberbukkitConfig.getInstance().getBoolean("mechanics.pre_1_6_fire", false); 72 73 // uberbukkit 74 if (!oldFire && !this.canPlace(world, i, j, k)) { 75 world.setTypeId(i, j, k, 0); 76 } 77 78 if (!flag && world.v() && (world.s(i, j, k) || world.s(i - 1, j, k) || world.s(i + 1, j, k) || world.s(i, j, k - 1) || world.s(i, j, k + 1))) { 79 world.setTypeId(i, j, k, 0); 80 } else { 81 int l = world.getData(i, j, k); 82 83 // uberbukkit - fire 84 if (oldFire) { 85 if (l < 15) { 86 world.setData(i, j, k, l + 1); 87 world.c(i, j, k, this.id, this.c()); 88 } 89 } else { 90 if (l < 15) { 91 world.setRawData(i, j, k, l + random.nextInt(3) / 2); 92 } 93 94 world.c(i, j, k, this.id, this.c()); 95 } 96 97 if (!flag && !this.g(world, i, j, k)) { 98 if (!world.e(i, j - 1, k) || l > 3) { 99 world.setTypeId(i, j, k, 0); 100 } 101 } else if (!flag && !this.b(world, i, j - 1, k) && l == 15 && random.nextInt(4) == 0) { 102 world.setTypeId(i, j, k, 0); 103 } else { 104 105 // CraftBukkit start - Call to stop spread of fire. 106 org.bukkit.Server server = world.getServer(); 107 org.bukkit.World bworld = world.getWorld(); 108 109 IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SPREAD; 110 org.bukkit.block.Block fromBlock = bworld.getBlockAt(i, j, k); 111 // CraftBukkit end 112 113 // uberbukkit 114 if (oldFire) { 115 if (l % 2 == 0 && l > 2) { 116 this.a(world, i + 1, j, k, 300, random, l); 117 this.a(world, i - 1, j, k, 300, random, l); 118 this.a(world, i, j - 1, k, 250, random, l); 119 this.a(world, i, j + 1, k, 250, random, l); 120 this.a(world, i, j, k - 1, 300, random, l); 121 this.a(world, i, j, k + 1, 300, random, l); 122 123 for (int i1 = i - 1; i1 <= i + 1; ++i1) { 124 for (int j1 = k - 1; j1 <= k + 1; ++j1) { 125 for (int k1 = j - 1; k1 <= j + 4; ++k1) { 126 if (i1 != i || k1 != j || j1 != k) { 127 int l1 = 100; 128 129 if (k1 > j + 1) { 130 l1 += (k1 - (j + 1)) * 100; 131 } 132 int i2 = this.h(world, i1, k1, j1); 133 if (i2 > 0 && random.nextInt(l1) <= i2 && (!world.v() || !world.s(i1, k1, j1)) && !world.s(i1 - 1, k1, k) && !world.s(i1 + 1, k1, j1) && !world.s(i1, k1, j1 - 1) && !world.s(i1, k1, j1 + 1)) { 134 // CraftBukkit start - Call to stop spread of fire. 135 org.bukkit.block.Block block = bworld.getBlockAt(i1, k1, j1); 136 137 if (block.getTypeId() != Block.FIRE.id) { 138 BlockIgniteEvent event = new BlockIgniteEvent(block, igniteCause, null); 139 server.getPluginManager().callEvent(event); 140 141 if (event.isCancelled()) { 142 continue; 143 } 144 145 org.bukkit.block.BlockState blockState = bworld.getBlockAt(i1, k1, j1).getState(); 146 blockState.setTypeId(this.id); 147 blockState.setData(new MaterialData(this.id)); 148 149 BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), fromBlock, blockState); 150 server.getPluginManager().callEvent(spreadEvent); 151 152 if (!spreadEvent.isCancelled()) { 153 blockState.update(true); 154 } 155 } 156 // CraftBukkit end 157 } 158 } 159 } 160 } 161 } 162 } 163 } else { 164 this.a(world, i + 1, j, k, 300, random, l); 165 this.a(world, i - 1, j, k, 300, random, l); 166 this.a(world, i, j - 1, k, 250, random, l); 167 this.a(world, i, j + 1, k, 250, random, l); 168 this.a(world, i, j, k - 1, 300, random, l); 169 this.a(world, i, j, k + 1, 300, random, l); 170 171 for (int i1 = i - 1; i1 <= i + 1; ++i1) { 172 for (int j1 = k - 1; j1 <= k + 1; ++j1) { 173 for (int k1 = j - 1; k1 <= j + 4; ++k1) { 174 if (i1 != i || k1 != j || j1 != k) { 175 int l1 = 100; 176 177 if (k1 > j + 1) { 178 l1 += (k1 - (j + 1)) * 100; 179 } 180 181 int i2 = this.h(world, i1, k1, j1); 182 183 if (i2 > 0) { 184 int j2 = (i2 + 40) / (l + 30); 185 186 if (j2 > 0 && random.nextInt(l1) <= j2 && (!world.v() || !world.s(i1, k1, j1)) && !world.s(i1 - 1, k1, k) && !world.s(i1 + 1, k1, j1) && !world.s(i1, k1, j1 - 1) && !world.s(i1, k1, j1 + 1)) { 187 int k2 = l + random.nextInt(5) / 4; 188 189 if (k2 > 15) { 190 k2 = 15; 191 } 192 // CraftBukkit start - Call to stop spread of fire. 193 org.bukkit.block.Block block = bworld.getBlockAt(i1, k1, j1); 194 195 if (block.getTypeId() != Block.FIRE.id) { 196 BlockIgniteEvent event = new BlockIgniteEvent(block, igniteCause, null); 197 server.getPluginManager().callEvent(event); 198 199 if (event.isCancelled()) { 200 continue; 201 } 202 203 org.bukkit.block.BlockState blockState = bworld.getBlockAt(i1, k1, j1).getState(); 204 blockState.setTypeId(this.id); 205 blockState.setData(new MaterialData(this.id, (byte) k2)); 206 207 BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), fromBlock, blockState); 208 server.getPluginManager().callEvent(spreadEvent); 209 210 if (!spreadEvent.isCancelled()) { 211 blockState.update(true); 212 } 213 } 214 // CraftBukkit end 215 } 216 } 217 } 218 } 219 } 220 } 221 } 222 223 if (oldFire && l == 15) { 224 this.a(world, i + 1, j, k, 1, random, 0); 225 this.a(world, i - 1, j, k, 1, random, 0); 226 this.a(world, i, j - 1, k, 1, random, 0); 227 this.a(world, i, j + 1, k, 1, random, 0); 228 this.a(world, i, j, k - 1, 1, random, 0); 229 this.a(world, i, j, k + 1, 1, random, 0); 230 } 231 } 232 } 233 } 234 235 private void a(World world, int i, int j, int k, int l, Random random, int i1) { 236 int j1 = this.b[world.getTypeId(i, j, k)]; 237 238 if (random.nextInt(l) < j1) { 239 boolean flag = world.getTypeId(i, j, k) == Block.TNT.id; 240 // CraftBukkit start 241 org.bukkit.block.Block theBlock = world.getWorld().getBlockAt(i, j, k); 242 243 BlockBurnEvent event = new BlockBurnEvent(theBlock); 244 world.getServer().getPluginManager().callEvent(event); 245 246 if (event.isCancelled()) { 247 return; 248 } 249 // CraftBukkit end 250 251 // uberbukkit 252 if (!UberbukkitConfig.getInstance().getBoolean("mechanics.pre_1_6_fire", false)) { 253 if (random.nextInt(i1 + 10) < 5 && !world.s(i, j, k)) { 254 int k1 = i1 + random.nextInt(5) / 4; 255 256 if (k1 > 15) { 257 k1 = 15; 258 } 259 260 world.setTypeIdAndData(i, j, k, this.id, k1); 261 } else { 262 world.setTypeId(i, j, k, 0); 263 } 264 } else { 265 if (random.nextInt(2) == 0 && !world.s(i, j, k)) { 266 world.setTypeId(i, j, k, this.id); 267 } else { 268 world.setTypeId(i, j, k, 0); 269 } 270 } 271 272 273 if (flag) { 274 Block.TNT.postBreak(world, i, j, k, 1); 275 } 276 } 277 } 278 279 private boolean g(World world, int i, int j, int k) { 280 return this.b(world, i + 1, j, k) ? true : (this.b(world, i - 1, j, k) ? true : (this.b(world, i, j - 1, k) ? true : (this.b(world, i, j + 1, k) ? true : (this.b(world, i, j, k - 1) ? true : this.b(world, i, j, k + 1))))); 281 } 282 283 private int h(World world, int i, int j, int k) { 284 byte b0 = 0; 285 286 if (!world.isEmpty(i, j, k)) { 287 return 0; 288 } else { 289 int l = this.f(world, i + 1, j, k, b0); 290 291 l = this.f(world, i - 1, j, k, l); 292 l = this.f(world, i, j - 1, k, l); 293 l = this.f(world, i, j + 1, k, l); 294 l = this.f(world, i, j, k - 1, l); 295 l = this.f(world, i, j, k + 1, l); 296 return l; 297 } 298 } 299 300 public boolean k_() { 301 return false; 302 } 303 304 public boolean b(IBlockAccess iblockaccess, int i, int j, int k) { 305 return this.a[iblockaccess.getTypeId(i, j, k)] > 0; 306 } 307 308 public int f(World world, int i, int j, int k, int l) { 309 int i1 = this.a[world.getTypeId(i, j, k)]; 310 311 return i1 > l ? i1 : l; 312 } 313 314 public boolean canPlace(World world, int i, int j, int k) { 315 return world.e(i, j - 1, k) || this.g(world, i, j, k); 316 } 317 318 public void doPhysics(World world, int i, int j, int k, int l) { 319 if (!world.e(i, j - 1, k) && !this.g(world, i, j, k)) { 320 world.setTypeId(i, j, k, 0); 321 } 322 } 323 324 public void c(World world, int i, int j, int k) { 325 // uberbukkit - disable nether portals for target version a1.1.2_01 326 if (Uberbukkit.getTargetPVN() <= 2) return; 327 328 if (world.getTypeId(i, j - 1, k) != Block.OBSIDIAN.id || !Block.PORTAL.a_(world, i, j, k)) { 329 if (!world.e(i, j - 1, k) && !this.g(world, i, j, k)) { 330 world.setTypeId(i, j, k, 0); 331 } else { 332 world.c(i, j, k, this.id, this.c()); 333 } 334 } 335 } 336}