2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/BlockFire.java
+++ b/net/minecraft/server/BlockFire.java
2019-04-23 04:00:00 +02:00
@@ -7,6 +7,15 @@
2018-12-25 22:00:00 +01:00
import java.util.Map.Entry;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2018-07-15 02:00:00 +02:00
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.block.CraftBlockState;
2014-11-25 22:32:16 +01:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockBurnEvent;
2018-07-15 02:00:00 +02:00
+import org.bukkit.event.block.BlockFadeEvent;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.block.BlockSpreadEvent;
+// CraftBukkit end
+
public class BlockFire extends Block {
2019-04-23 04:00:00 +02:00
public static final BlockStateInteger AGE = BlockProperties.ad;
@@ -33,7 +42,20 @@
2018-07-15 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
@Override
2018-07-15 02:00:00 +02:00
public IBlockData updateState(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) {
- return this.canPlace(iblockdata, generatoraccess, blockposition) ? (IBlockData) this.a((IBlockAccess) generatoraccess, blockposition).set(BlockFire.AGE, iblockdata.get(BlockFire.AGE)) : Blocks.AIR.getBlockData();
+ // CraftBukkit start
+ if (!iblockdata.canPlace(generatoraccess, blockposition)) {
+ CraftBlockState blockState = CraftBlockState.getBlockState(generatoraccess, blockposition);
+ blockState.setData(Blocks.AIR.getBlockData());
+
+ BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
+ generatoraccess.getMinecraftWorld().getMinecraftServer().server.getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ return blockState.getHandle();
+ }
+ }
+ return this.a((IBlockAccess) generatoraccess, blockposition).set(BlockFire.AGE, iblockdata.get(BlockFire.AGE));
+ // CraftBukkit end
}
@Nullable
2019-04-23 04:00:00 +02:00
@@ -82,7 +104,7 @@
2019-12-10 23:00:00 +01:00
public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, Random random) {
if (worldserver.getGameRules().getBoolean(GameRules.DO_FIRE_TICK)) {
if (!iblockdata.canPlace(worldserver, blockposition)) {
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit - invalid place location
2014-11-25 22:32:16 +01:00
}
2019-12-10 23:00:00 +01:00
Block block = worldserver.getType(blockposition.down()).getBlock();
2019-04-23 04:00:00 +02:00
@@ -90,7 +112,7 @@
2018-12-06 00:00:00 +01:00
int i = (Integer) iblockdata.get(BlockFire.AGE);
2014-11-25 22:32:16 +01:00
2019-12-10 23:00:00 +01:00
if (!flag && worldserver.isRaining() && this.a((World) worldserver, blockposition) && random.nextFloat() < 0.2F + (float) i * 0.03F) {
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit - extinguished by rain
2014-11-25 22:32:16 +01:00
} else {
2018-07-15 02:00:00 +02:00
int j = Math.min(15, i + random.nextInt(3) / 2);
2019-04-23 04:00:00 +02:00
@@ -105,14 +127,14 @@
BlockPosition blockposition1 = blockposition.down();
2019-12-10 23:00:00 +01:00
if (!worldserver.getType(blockposition1).d(worldserver, blockposition1, EnumDirection.UP) || i > 3) {
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit
2015-02-17 15:06:54 +01:00
}
return;
}
2019-12-10 23:00:00 +01:00
if (i == 15 && random.nextInt(4) == 0 && !this.h(worldserver.getType(blockposition.down()))) {
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit
2015-02-17 15:06:54 +01:00
return;
}
}
2019-04-23 04:00:00 +02:00
@@ -120,12 +142,14 @@
2019-12-10 23:00:00 +01:00
boolean flag1 = worldserver.s(blockposition);
2018-07-15 02:00:00 +02:00
int k = flag1 ? -50 : 0;
2017-03-08 23:20:24 +01:00
2019-12-10 23:00:00 +01:00
- this.a(worldserver, blockposition.east(), 300 + k, random, i);
- this.a(worldserver, blockposition.west(), 300 + k, random, i);
- this.a(worldserver, blockposition.down(), 250 + k, random, i);
- this.a(worldserver, blockposition.up(), 250 + k, random, i);
- this.a(worldserver, blockposition.north(), 300 + k, random, i);
- this.a(worldserver, blockposition.south(), 300 + k, random, i);
2017-03-08 23:20:24 +01:00
+ // CraftBukkit start - add source blockposition to burn calls
2019-12-10 23:00:00 +01:00
+ this.a(worldserver, blockposition.east(), 300 + k, random, i, blockposition);
+ this.a(worldserver, blockposition.west(), 300 + k, random, i, blockposition);
+ this.a(worldserver, blockposition.down(), 250 + k, random, i, blockposition);
+ this.a(worldserver, blockposition.up(), 250 + k, random, i, blockposition);
+ this.a(worldserver, blockposition.north(), 300 + k, random, i, blockposition);
+ this.a(worldserver, blockposition.south(), 300 + k, random, i, blockposition);
2017-03-08 23:20:24 +01:00
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
2017-03-08 23:20:24 +01:00
2018-07-15 02:00:00 +02:00
for (int l = -1; l <= 1; ++l) {
2019-04-23 04:00:00 +02:00
@@ -151,7 +175,15 @@
2019-12-10 23:00:00 +01:00
if (i2 > 0 && random.nextInt(k1) <= i2 && (!worldserver.isRaining() || !this.a((World) worldserver, (BlockPosition) blockposition_mutableblockposition))) {
2018-07-15 02:00:00 +02:00
int j2 = Math.min(15, i + random.nextInt(5) / 4);
2014-11-25 22:32:16 +01:00
2019-12-10 23:00:00 +01:00
- worldserver.setTypeAndData(blockposition_mutableblockposition, (IBlockData) this.a((IBlockAccess) worldserver, (BlockPosition) blockposition_mutableblockposition).set(BlockFire.AGE, j2), 3);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Call to stop spread of fire
2019-12-10 23:00:00 +01:00
+ if (worldserver.getType(blockposition_mutableblockposition).getBlock() != Blocks.FIRE) {
+ if (CraftEventFactory.callBlockIgniteEvent(worldserver, blockposition_mutableblockposition, blockposition).isCancelled()) {
2014-11-25 22:32:16 +01:00
+ continue;
+ }
+
2019-12-10 23:00:00 +01:00
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition_mutableblockposition, (IBlockData) this.a((IBlockAccess) worldserver, (BlockPosition) blockposition_mutableblockposition).set(BlockFire.AGE, j2), 3); // CraftBukkit
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
}
}
}
2019-04-23 04:00:00 +02:00
@@ -175,12 +207,24 @@
return iblockdata.b((IBlockState) BlockProperties.C) && (Boolean) iblockdata.get(BlockProperties.C) ? 0 : this.flameChances.getInt(iblockdata.getBlock());
2017-03-08 23:20:24 +01:00
}
- private void a(World world, BlockPosition blockposition, int i, Random random, int j) {
+ private void a(World world, BlockPosition blockposition, int i, Random random, int j, BlockPosition sourceposition) { // CraftBukkit add sourceposition
2019-12-10 23:00:00 +01:00
int k = this.i(world.getType(blockposition));
2017-03-08 23:20:24 +01:00
2014-11-25 22:32:16 +01:00
if (random.nextInt(i) < k) {
IBlockData iblockdata = world.getType(blockposition);
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ org.bukkit.block.Block theBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
2017-03-08 23:20:24 +01:00
+ org.bukkit.block.Block sourceBlock = world.getWorld().getBlockAt(sourceposition.getX(), sourceposition.getY(), sourceposition.getZ());
2014-11-25 22:32:16 +01:00
+
2017-03-08 23:20:24 +01:00
+ BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock);
2014-11-25 22:32:16 +01:00
+ world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
if (random.nextInt(j + 10) < 5 && !world.isRainingAt(blockposition)) {
2018-07-15 02:00:00 +02:00
int l = Math.min(j + random.nextInt(5) / 4, 15);
2014-11-25 22:32:16 +01:00
2019-05-12 03:15:48 +02:00
@@ -241,9 +285,10 @@
@Override
public void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
2018-07-15 02:00:00 +02:00
if (iblockdata1.getBlock() != iblockdata.getBlock()) {
2019-05-12 03:15:48 +02:00
- if (world.worldProvider.getDimensionManager() != DimensionManager.OVERWORLD && world.worldProvider.getDimensionManager() != DimensionManager.NETHER || !((BlockPortal) Blocks.NETHER_PORTAL).a((GeneratorAccess) world, blockposition)) {
+ // CraftBukkit - getType()
+ if (world.worldProvider.getDimensionManager().getType() != DimensionManager.OVERWORLD && world.worldProvider.getDimensionManager().getType() != DimensionManager.NETHER || !((BlockPortal) Blocks.NETHER_PORTAL).a((GeneratorAccess) world, blockposition)) {
2018-07-15 02:00:00 +02:00
if (!iblockdata.canPlace(world, blockposition)) {
2019-04-23 04:00:00 +02:00
- world.a(blockposition, false);
2018-07-15 02:00:00 +02:00
+ fireExtinguished(world, blockposition); // CraftBukkit - fuel block broke
} else {
2018-12-13 01:00:00 +01:00
world.getBlockTickList().a(blockposition, this, this.a((IWorldReader) world) + world.random.nextInt(10));
2018-07-15 02:00:00 +02:00
}
2019-12-10 23:00:00 +01:00
@@ -392,4 +437,12 @@
blockfire.a(Blocks.BEEHIVE, 5, 20);
blockfire.a(Blocks.BEE_NEST, 30, 20);
2014-11-25 22:32:16 +01:00
}
+
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
+ private void fireExtinguished(GeneratorAccess world, BlockPosition position) {
+ if (!CraftEventFactory.callBlockFadeEvent(world, position, Blocks.AIR.getBlockData()).isCancelled()) {
2019-04-23 04:00:00 +02:00
+ world.a(position, false);
2014-11-25 22:32:16 +01:00
+ }
+ }
+ // CraftBukkit end
}