PaperMC/nms-patches/BlockFire.patch
2020-08-12 07:00:00 +10:00

141 lines
7.8 KiB
Diff

--- a/net/minecraft/server/BlockFire.java
+++ b/net/minecraft/server/BlockFire.java
@@ -8,6 +8,13 @@
import java.util.function.Function;
import java.util.stream.Collectors;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockBurnEvent;
+import org.bukkit.event.block.BlockFadeEvent;
+// CraftBukkit end
+
public class BlockFire extends BlockFireAbstract {
public static final BlockStateInteger AGE = BlockProperties.aj;
@@ -64,7 +71,24 @@
@Override
public IBlockData updateState(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) {
- return this.canPlace(iblockdata, generatoraccess, blockposition) ? this.a(generatoraccess, blockposition, (Integer) iblockdata.get(BlockFire.AGE)) : Blocks.AIR.getBlockData();
+ // CraftBukkit start
+ if (!this.canPlace(iblockdata, generatoraccess, blockposition)) {
+ // Suppress during worldgen
+ if (!(generatoraccess instanceof World)) {
+ return Blocks.AIR.getBlockData();
+ }
+ CraftBlockState blockState = CraftBlockState.getBlockState(generatoraccess, blockposition);
+ blockState.setData(Blocks.AIR.getBlockData());
+
+ BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
+ ((World) generatoraccess).getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ return blockState.getHandle();
+ }
+ }
+ return this.a(generatoraccess, blockposition, (Integer) iblockdata.get(BlockFire.AGE));
+ // CraftBukkit end
}
@Override
@@ -113,7 +137,7 @@
worldserver.getBlockTickList().a(blockposition, this, a(worldserver.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
}
IBlockData iblockdata1 = worldserver.getType(blockposition.down());
@@ -121,7 +145,7 @@
int i = (Integer) iblockdata.get(BlockFire.AGE);
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
} else {
int j = Math.min(15, i + random.nextInt(3) / 2);
@@ -135,14 +159,14 @@
BlockPosition blockposition1 = blockposition.down();
if (!worldserver.getType(blockposition1).d(worldserver, blockposition1, EnumDirection.UP) || i > 3) {
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit
}
return;
}
if (i == 15 && random.nextInt(4) == 0 && !this.e(worldserver.getType(blockposition.down()))) {
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit
return;
}
}
@@ -150,12 +174,14 @@
boolean flag1 = worldserver.u(blockposition);
int k = flag1 ? -50 : 0;
- this.trySpread(worldserver, blockposition.east(), 300 + k, random, i);
- this.trySpread(worldserver, blockposition.west(), 300 + k, random, i);
- this.trySpread(worldserver, blockposition.down(), 250 + k, random, i);
- this.trySpread(worldserver, blockposition.up(), 250 + k, random, i);
- this.trySpread(worldserver, blockposition.north(), 300 + k, random, i);
- this.trySpread(worldserver, blockposition.south(), 300 + k, random, i);
+ // CraftBukkit start - add source blockposition to burn calls
+ this.trySpread(worldserver, blockposition.east(), 300 + k, random, i, blockposition);
+ this.trySpread(worldserver, blockposition.west(), 300 + k, random, i, blockposition);
+ this.trySpread(worldserver, blockposition.down(), 250 + k, random, i, blockposition);
+ this.trySpread(worldserver, blockposition.up(), 250 + k, random, i, blockposition);
+ this.trySpread(worldserver, blockposition.north(), 300 + k, random, i, blockposition);
+ this.trySpread(worldserver, blockposition.south(), 300 + k, random, i, blockposition);
+ // CraftBukkit end
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
for (int l = -1; l <= 1; ++l) {
@@ -181,7 +207,15 @@
if (i2 > 0 && random.nextInt(k1) <= i2 && (!worldserver.isRaining() || !this.a((World) worldserver, (BlockPosition) blockposition_mutableblockposition))) {
int j2 = Math.min(15, i + random.nextInt(5) / 4);
- worldserver.setTypeAndData(blockposition_mutableblockposition, this.a(worldserver, blockposition_mutableblockposition, j2), 3);
+ // CraftBukkit start - Call to stop spread of fire
+ if (worldserver.getType(blockposition_mutableblockposition).getBlock() != Blocks.FIRE) {
+ if (CraftEventFactory.callBlockIgniteEvent(worldserver, blockposition_mutableblockposition, blockposition).isCancelled()) {
+ continue;
+ }
+
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition_mutableblockposition, this.a(worldserver, blockposition_mutableblockposition, j2), 3); // CraftBukkit
+ }
+ // CraftBukkit end
}
}
}
@@ -205,12 +239,24 @@
return iblockdata.b(BlockProperties.C) && (Boolean) iblockdata.get(BlockProperties.C) ? 0 : this.flameChances.getInt(iblockdata.getBlock());
}
- private void trySpread(World world, BlockPosition blockposition, int i, Random random, int j) {
+ private void trySpread(World world, BlockPosition blockposition, int i, Random random, int j, BlockPosition sourceposition) { // CraftBukkit add sourceposition
int k = this.getBurnChance(world.getType(blockposition));
if (random.nextInt(i) < k) {
IBlockData iblockdata = world.getType(blockposition);
+ // CraftBukkit start
+ org.bukkit.block.Block theBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ org.bukkit.block.Block sourceBlock = world.getWorld().getBlockAt(sourceposition.getX(), sourceposition.getY(), sourceposition.getZ());
+
+ BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock);
+ world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
+
if (random.nextInt(j + 10) < 5 && !world.isRainingAt(blockposition)) {
int l = Math.min(j + random.nextInt(5) / 4, 15);