Paper/nms-patches/BlockFire.patch

163 lines
8.7 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/BlockFire.java
+++ b/net/minecraft/server/BlockFire.java
2018-07-15 02:00:00 +02:00
@@ -8,6 +8,16 @@
import java.util.function.Predicate;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
2018-07-15 02:00:00 +02:00
+
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.block.CraftBlockState;
+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;
+import org.bukkit.event.block.BlockSpreadEvent;
+// CraftBukkit end
+
public class BlockFire extends Block {
2018-08-26 04:00:00 +02:00
public static final BlockStateInteger AGE = BlockProperties.X;
2018-07-15 02:00:00 +02:00
@@ -32,7 +42,20 @@
}
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
@@ -82,7 +105,7 @@
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Random random) {
if (world.getGameRules().getBoolean("doFireTick")) {
2018-07-15 02:00:00 +02:00
if (!iblockdata.canPlace(world, blockposition)) {
- world.setAir(blockposition);
+ fireExtinguished(world, blockposition); // CraftBukkit - invalid place location
}
Block block = world.getType(blockposition.down()).getBlock();
2018-07-15 02:00:00 +02:00
@@ -90,7 +113,7 @@
2016-02-29 22:32:46 +01:00
int i = ((Integer) iblockdata.get(BlockFire.AGE)).intValue();
2018-07-15 02:00:00 +02:00
if (!flag && world.isRaining() && this.a(world, blockposition) && random.nextFloat() < 0.2F + (float) i * 0.03F) {
- world.setAir(blockposition);
+ fireExtinguished(world, blockposition); // CraftBukkit - extinguished by rain
} else {
2018-07-15 02:00:00 +02:00
int j = Math.min(15, i + random.nextInt(3) / 2);
@@ -103,14 +126,14 @@
2018-08-26 04:00:00 +02:00
world.J().a(blockposition, this, this.a((IWorldReader) world) + random.nextInt(10));
2018-07-15 02:00:00 +02:00
if (!this.d(world, blockposition)) {
2017-05-19 13:00:13 +02:00
if (!world.getType(blockposition.down()).q() || i > 3) {
2015-02-17 15:06:54 +01:00
- world.setAir(blockposition);
+ fireExtinguished(world, blockposition); // CraftBukkit
}
return;
}
2018-07-22 04:00:00 +02:00
if (i == 15 && random.nextInt(4) == 0 && !this.k(world.getType(blockposition.down()))) {
2015-02-17 15:06:54 +01:00
- world.setAir(blockposition);
+ fireExtinguished(world, blockposition); // CraftBukkit
return;
}
}
2018-07-15 02:00:00 +02:00
@@ -118,12 +141,14 @@
boolean flag1 = world.x(blockposition);
int k = flag1 ? -50 : 0;
2017-03-08 23:20:24 +01:00
2018-07-15 02:00:00 +02:00
- this.a(world, blockposition.east(), 300 + k, random, i);
- this.a(world, blockposition.west(), 300 + k, random, i);
- this.a(world, blockposition.down(), 250 + k, random, i);
- this.a(world, blockposition.up(), 250 + k, random, i);
- this.a(world, blockposition.north(), 300 + k, random, i);
- this.a(world, blockposition.south(), 300 + k, random, i);
2017-03-08 23:20:24 +01:00
+ // CraftBukkit start - add source blockposition to burn calls
2018-07-15 02:00:00 +02:00
+ this.a(world, blockposition.east(), 300 + k, random, i, blockposition);
+ this.a(world, blockposition.west(), 300 + k, random, i, blockposition);
+ this.a(world, blockposition.down(), 250 + k, random, i, blockposition);
+ this.a(world, blockposition.up(), 250 + k, random, i, blockposition);
+ this.a(world, blockposition.north(), 300 + k, random, i, blockposition);
+ this.a(world, 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) {
@@ -149,7 +174,15 @@
if (i2 > 0 && random.nextInt(k1) <= i2 && (!world.isRaining() || !this.a(world, (BlockPosition) blockposition_mutableblockposition))) {
int j2 = Math.min(15, i + random.nextInt(5) / 4);
2018-07-15 02:00:00 +02:00
- world.setTypeAndData(blockposition_mutableblockposition, (IBlockData) this.a((IBlockAccess) world, (BlockPosition) blockposition_mutableblockposition).set(BlockFire.AGE, Integer.valueOf(j2)), 3);
+ // CraftBukkit start - Call to stop spread of fire
2018-07-15 02:00:00 +02:00
+ if (world.getType(blockposition_mutableblockposition) != Blocks.FIRE) {
+ if (CraftEventFactory.callBlockIgniteEvent(world, blockposition_mutableblockposition, blockposition).isCancelled()) {
+ continue;
+ }
+
2018-07-15 02:00:00 +02:00
+ CraftEventFactory.handleBlockSpreadEvent(world, blockposition, blockposition_mutableblockposition, (IBlockData) this.a((IBlockAccess) world, (BlockPosition) blockposition_mutableblockposition).set(BlockFire.AGE, Integer.valueOf(j2)), 3); // CraftBukkit
+ }
+ // CraftBukkit end
}
}
}
2018-07-15 02:00:00 +02:00
@@ -173,12 +206,24 @@
return this.flameChances.getInt(block);
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
2018-07-15 02:00:00 +02:00
int k = this.f(world.getType(blockposition).getBlock());
2017-03-08 23:20:24 +01:00
if (random.nextInt(i) < k) {
IBlockData iblockdata = world.getType(blockposition);
2015-02-26 23:41:06 +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());
+
2017-03-08 23:20:24 +01:00
+ BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock);
+ world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +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);
2018-07-15 02:00:00 +02:00
@@ -241,7 +286,7 @@
if (iblockdata1.getBlock() != iblockdata.getBlock()) {
2018-08-26 04:00:00 +02:00
if (world.worldProvider.getDimensionManager() != DimensionManager.OVERWORLD && world.worldProvider.getDimensionManager() != DimensionManager.NETHER || !((BlockPortal) Blocks.NETHER_PORTAL).a((GeneratorAccess) world, blockposition)) {
2018-07-15 02:00:00 +02:00
if (!iblockdata.canPlace(world, blockposition)) {
- world.setAir(blockposition);
+ fireExtinguished(world, blockposition); // CraftBukkit - fuel block broke
} else {
2018-08-26 04:00:00 +02:00
world.J().a(blockposition, this, this.a((IWorldReader) world) + world.random.nextInt(10));
2018-07-15 02:00:00 +02:00
}
@@ -387,4 +432,12 @@
blockfire.a(Blocks.BLACK_CARPET, 60, 20);
blockfire.a(Blocks.DRIED_KELP_BLOCK, 30, 60);
}
+
+ // 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()) {
+ world.setAir(position);
+ }
+ }
+ // CraftBukkit end
}