Paper/src/main/java/net/minecraft/server/BlockFire.java

275 lines
10 KiB
Java
Raw Normal View History

package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.util.Random;
// CraftBukkit start
import org.bukkit.event.block.BlockIgniteEvent;
2011-01-26 22:13:27 +01:00
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockSpreadEvent;
// CraftBukkit end
public class BlockFire extends Block {
2011-01-29 22:50:29 +01:00
private int[] a = new int[256];
private int[] b = new int[256];
protected BlockFire(int i, int j) {
2011-01-29 22:50:29 +01:00
super(i, j, Material.FIRE);
2012-07-29 09:33:13 +02:00
this.b(true);
2011-05-26 14:48:22 +02:00
}
2012-07-29 09:33:13 +02:00
public void r_() {
2011-01-29 22:50:29 +01:00
this.a(Block.WOOD.id, 5, 20);
2012-07-29 09:33:13 +02:00
this.a(Block.WOOD_DOUBLE_STEP.id, 5, 20);
this.a(Block.WOOD_STEP.id, 5, 20);
2011-05-26 14:48:22 +02:00
this.a(Block.FENCE.id, 5, 20);
this.a(Block.WOOD_STAIRS.id, 5, 20);
2012-07-29 09:33:13 +02:00
this.a(Block.BIRCH_WOOD_STAIRS.id, 5, 20);
this.a(Block.SPRUCE_WOOD_STAIRS.id, 5, 20);
this.a(Block.JUNGLE_WOOD_STAIRS.id, 5, 20);
2011-01-29 22:50:29 +01:00
this.a(Block.LOG.id, 5, 5);
this.a(Block.LEAVES.id, 30, 60);
this.a(Block.BOOKSHELF.id, 30, 20);
this.a(Block.TNT.id, 15, 100);
2011-05-26 14:48:22 +02:00
this.a(Block.LONG_GRASS.id, 60, 100);
2011-01-29 22:50:29 +01:00
this.a(Block.WOOL.id, 30, 60);
2011-09-15 02:23:52 +02:00
this.a(Block.VINE.id, 15, 100);
}
private void a(int i, int j, int k) {
2011-01-29 22:50:29 +01:00
this.a[i] = j;
this.b[i] = k;
}
2011-06-30 00:02:25 +02:00
public AxisAlignedBB e(World world, int i, int j, int k) {
return null;
}
2012-07-29 09:33:13 +02:00
public boolean d() {
return false;
}
2012-07-29 09:33:13 +02:00
public boolean c() {
2011-05-26 14:48:22 +02:00
return false;
}
2012-07-29 09:33:13 +02:00
public int b() {
2011-11-20 09:01:14 +01:00
return 3;
}
public int a(Random random) {
return 0;
}
2012-07-29 09:33:13 +02:00
public int p_() {
2012-03-01 11:49:23 +01:00
return 30;
}
2012-07-29 09:33:13 +02:00
public void b(World world, int i, int j, int k, Random random) {
2011-01-29 22:50:29 +01:00
boolean flag = world.getTypeId(i, j - 1, k) == Block.NETHERRACK.id;
if (world.worldProvider instanceof WorldProviderTheEnd && world.getTypeId(i, j - 1, k) == Block.BEDROCK.id) {
2011-11-20 09:01:14 +01:00
flag = true;
}
2011-05-26 14:48:22 +02:00
if (!this.canPlace(world, i, j, k)) {
2012-07-29 09:33:13 +02:00
fireExtinguished(world, i, j, k); // CraftBukkit - invalid place location
2011-05-26 14:48:22 +02:00
}
2012-07-29 09:33:13 +02:00
if (!flag && world.J() && (world.B(i, j, k) || world.B(i - 1, j, k) || world.B(i + 1, j, k) || world.B(i, j, k - 1) || world.B(i, j, k + 1))) {
fireExtinguished(world, i, j, k); // CraftBukkit - extinguished by rain
2011-01-29 22:50:29 +01:00
} else {
int l = world.getData(i, j, k);
2011-01-29 22:50:29 +01:00
if (l < 15) {
2011-05-26 14:48:22 +02:00
world.setRawData(i, j, k, l + random.nextInt(3) / 2);
}
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
world.a(i, j, k, this.id, this.p_() + random.nextInt(10));
if (!flag && !this.l(world, i, j, k)) {
if (!world.t(i, j - 1, k) || l > 3) {
fireExtinguished(world, i, j, k); // CraftBukkit - burn out
}
2012-07-29 09:33:13 +02:00
} else if (!flag && !this.d((IBlockAccess) world, i, j - 1, k) && l == 15 && random.nextInt(4) == 0) {
fireExtinguished(world, i, j, k); // CraftBukkit - burn out
} else {
2012-07-29 09:33:13 +02:00
boolean flag1 = world.C(i, j, k);
2012-03-01 11:49:23 +01:00
byte b0 = 0;
if (flag1) {
b0 = -50;
}
this.a(world, i + 1, j, k, 300 + b0, random, l);
this.a(world, i - 1, j, k, 300 + b0, random, l);
this.a(world, i, j - 1, k, 250 + b0, random, l);
this.a(world, i, j + 1, k, 250 + b0, random, l);
this.a(world, i, j, k - 1, 300 + b0, random, l);
this.a(world, i, j, k + 1, 300 + b0, random, l);
2011-05-26 14:48:22 +02:00
2012-07-29 09:33:13 +02:00
// CraftBukkit start - call to stop spread of fire
org.bukkit.Server server = world.getServer();
org.bukkit.World bworld = world.getWorld();
2011-05-26 14:48:22 +02:00
BlockIgniteEvent.IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SPREAD;
org.bukkit.block.Block fromBlock = bworld.getBlockAt(i, j, k);
// CraftBukkit end
2011-05-26 14:48:22 +02:00
for (int i1 = i - 1; i1 <= i + 1; ++i1) {
for (int j1 = k - 1; j1 <= k + 1; ++j1) {
for (int k1 = j - 1; k1 <= j + 4; ++k1) {
if (i1 != i || k1 != j || j1 != k) {
int l1 = 100;
if (k1 > j + 1) {
l1 += (k1 - (j + 1)) * 100;
}
2012-07-29 09:33:13 +02:00
int i2 = this.n(world, i1, k1, j1);
2011-05-26 14:48:22 +02:00
if (i2 > 0) {
int j2 = (i2 + 40) / (l + 30);
2012-03-01 11:49:23 +01:00
if (flag1) {
j2 /= 2;
}
2012-07-29 09:33:13 +02:00
if (j2 > 0 && random.nextInt(l1) <= j2 && (!world.J() || !world.B(i1, k1, j1)) && !world.B(i1 - 1, k1, k) && !world.B(i1 + 1, k1, j1) && !world.B(i1, k1, j1 - 1) && !world.B(i1, k1, j1 + 1)) {
2011-05-26 14:48:22 +02:00
int k2 = l + random.nextInt(5) / 4;
2011-01-29 22:50:29 +01:00
2011-05-26 14:48:22 +02:00
if (k2 > 15) {
k2 = 15;
}
2012-07-29 09:33:13 +02:00
// CraftBukkit start - call to stop spread of fire
org.bukkit.block.Block block = bworld.getBlockAt(i1, k1, j1);
if (block.getTypeId() != Block.FIRE.id) {
BlockIgniteEvent event = new BlockIgniteEvent(block, igniteCause, null);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
2011-05-26 14:48:22 +02:00
org.bukkit.block.BlockState blockState = bworld.getBlockAt(i1, k1, j1).getState();
blockState.setTypeId(this.id);
blockState.setData(new org.bukkit.material.MaterialData(this.id, (byte) k2));
BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), fromBlock, blockState);
server.getPluginManager().callEvent(spreadEvent);
if (!spreadEvent.isCancelled()) {
blockState.update(true);
}
2011-01-29 22:50:29 +01:00
}
// CraftBukkit end
}
2011-01-29 22:50:29 +01:00
}
}
}
}
}
2011-02-23 03:37:56 +01:00
}
2011-02-01 12:43:31 +01:00
}
}
2011-05-26 14:48:22 +02:00
private void a(World world, int i, int j, int k, int l, Random random, int i1) {
int j1 = this.b[world.getTypeId(i, j, k)];
2011-05-26 14:48:22 +02:00
if (random.nextInt(l) < j1) {
2011-01-29 22:50:29 +01:00
boolean flag = world.getTypeId(i, j, k) == Block.TNT.id;
2012-07-29 09:33:13 +02:00
2011-02-02 00:32:18 +01:00
// CraftBukkit start
org.bukkit.block.Block theBlock = world.getWorld().getBlockAt(i, j, k);
2011-02-02 00:32:18 +01:00
BlockBurnEvent event = new BlockBurnEvent(theBlock);
world.getServer().getPluginManager().callEvent(event);
2011-02-23 13:56:36 +01:00
if (event.isCancelled()) {
return;
}
2011-02-02 00:32:18 +01:00
// CraftBukkit end
2011-02-23 13:56:36 +01:00
2012-07-29 09:33:13 +02:00
if (random.nextInt(i1 + 10) < 5 && !world.B(i, j, k)) {
2011-05-26 14:48:22 +02:00
int k1 = i1 + random.nextInt(5) / 4;
if (k1 > 15) {
k1 = 15;
}
world.setTypeIdAndData(i, j, k, this.id, k1);
} else {
world.setTypeId(i, j, k, 0);
}
if (flag) {
2011-06-30 00:02:25 +02:00
Block.TNT.postBreak(world, i, j, k, 1);
}
}
}
2012-07-29 09:33:13 +02:00
private boolean l(World world, int i, int j, int k) {
return this.d((IBlockAccess) world, i + 1, j, k) ? true : (this.d((IBlockAccess) world, i - 1, j, k) ? true : (this.d((IBlockAccess) world, i, j - 1, k) ? true : (this.d((IBlockAccess) world, i, j + 1, k) ? true : (this.d((IBlockAccess) world, i, j, k - 1) ? true : this.d((IBlockAccess) world, i, j, k + 1)))));
}
2012-07-29 09:33:13 +02:00
private int n(World world, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
byte b0 = 0;
2011-01-29 22:50:29 +01:00
if (!world.isEmpty(i, j, k)) {
return 0;
} else {
2012-07-29 09:33:13 +02:00
int l = this.e(world, i + 1, j, k, b0);
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
l = this.e(world, i - 1, j, k, l);
l = this.e(world, i, j - 1, k, l);
l = this.e(world, i, j + 1, k, l);
l = this.e(world, i, j, k - 1, l);
l = this.e(world, i, j, k + 1, l);
return l;
}
}
2012-07-29 09:33:13 +02:00
public boolean l() {
return false;
}
2012-07-29 09:33:13 +02:00
public boolean d(IBlockAccess iblockaccess, int i, int j, int k) {
2011-01-29 22:50:29 +01:00
return this.a[iblockaccess.getTypeId(i, j, k)] > 0;
}
2012-07-29 09:33:13 +02:00
public int e(World world, int i, int j, int k, int l) {
2011-01-29 22:50:29 +01:00
int i1 = this.a[world.getTypeId(i, j, k)];
2011-01-29 22:50:29 +01:00
return i1 > l ? i1 : l;
}
public boolean canPlace(World world, int i, int j, int k) {
2012-07-29 09:33:13 +02:00
return world.t(i, j - 1, k) || this.l(world, i, j, k);
}
public void doPhysics(World world, int i, int j, int k, int l) {
2012-07-29 09:33:13 +02:00
if (!world.t(i, j - 1, k) && !this.l(world, i, j, k)) {
fireExtinguished(world, i, j, k); // CraftBukkit - fuel block gone
}
}
public void onPlace(World world, int i, int j, int k) {
2012-07-29 09:33:13 +02:00
if (world.worldProvider.dimension > 0 || world.getTypeId(i, j - 1, k) != Block.OBSIDIAN.id || !Block.PORTAL.i_(world, i, j, k)) {
if (!world.t(i, j - 1, k) && !this.l(world, i, j, k)) {
fireExtinguished(world, i, j, k); // CraftBukkit - fuel block broke
2011-01-29 22:50:29 +01:00
} else {
2012-07-29 09:33:13 +02:00
world.a(i, j, k, this.id, this.p_() + world.random.nextInt(10));
2011-01-29 22:50:29 +01:00
}
}
}
2012-07-29 09:33:13 +02:00
// CraftBukkit start
private void fireExtinguished(World world, int x, int y, int z) {
if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(world.getWorld().getBlockAt(x, y, z), 0).isCancelled() == false) {
world.setTypeId(x, y, z, 0);
}
}
// CraftBukkit end
}