3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 23:00:08 +01:00
Paper/nms-patches/BlockFire.patch

142 Zeilen
7.8 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/BlockFire.java
+++ b/net/minecraft/server/BlockFire.java
2020-06-25 02:00:00 +02:00
@@ -5,6 +5,13 @@
import java.util.Map;
import java.util.Random;
+// CraftBukkit start
2018-07-15 02:00:00 +02:00
+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;
+// CraftBukkit end
+
2020-06-25 02:00:00 +02:00
public class BlockFire extends BlockFireAbstract {
2020-06-25 02:00:00 +02:00
public static final BlockStateInteger AGE = BlockProperties.aj;
@@ -26,7 +33,24 @@
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) {
2020-06-25 02:00:00 +02:00
- return this.canPlace(iblockdata, generatoraccess, blockposition) ? this.a(generatoraccess, blockposition, (Integer) iblockdata.get(BlockFire.AGE)) : Blocks.AIR.getBlockData();
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ if (!this.canPlace(iblockdata, generatoraccess, blockposition)) {
+ // Suppress during worldgen
+ if (!(generatoraccess instanceof World)) {
+ return Blocks.AIR.getBlockData();
+ }
2018-07-15 02:00:00 +02:00
+ 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();
+ }
+ }
2020-06-25 02:00:00 +02:00
+ return this.a(generatoraccess, blockposition, (Integer) iblockdata.get(BlockFire.AGE));
2018-07-15 02:00:00 +02:00
+ // CraftBukkit end
}
2020-06-25 02:00:00 +02:00
@Override
@@ -97,7 +121,7 @@
2020-06-25 02:00:00 +02:00
worldserver.getBlockTickList().a(blockposition, this, a(worldserver.random));
2019-12-10 23:00:00 +01:00
if (worldserver.getGameRules().getBoolean(GameRules.DO_FIRE_TICK)) {
if (!iblockdata.canPlace(worldserver, blockposition)) {
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit - invalid place location
}
2020-06-25 02:00:00 +02:00
IBlockData iblockdata1 = worldserver.getType(blockposition.down());
@@ -105,7 +129,7 @@
2018-12-06 00:00:00 +01:00
int i = (Integer) iblockdata.get(BlockFire.AGE);
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
} else {
2018-07-15 02:00:00 +02:00
int j = Math.min(15, i + random.nextInt(3) / 2);
@@ -119,14 +143,14 @@
2019-04-23 04:00:00 +02:00
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;
}
2020-06-25 02:00:00 +02:00
if (i == 15 && random.nextInt(4) == 0 && !this.e(worldserver.getType(blockposition.down()))) {
2019-12-10 23:00:00 +01:00
- worldserver.a(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit
2015-02-17 15:06:54 +01:00
return;
}
}
@@ -134,12 +158,14 @@
2020-06-25 02:00:00 +02:00
boolean flag1 = worldserver.u(blockposition);
2018-07-15 02:00:00 +02:00
int k = flag1 ? -50 : 0;
2017-03-08 23:20:24 +01:00
2020-06-25 02:00:00 +02:00
- 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);
2017-03-08 23:20:24 +01:00
+ // CraftBukkit start - add source blockposition to burn calls
2020-06-25 02:00:00 +02:00
+ 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);
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) {
@@ -165,7 +191,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);
2020-06-25 02:00:00 +02:00
- worldserver.setTypeAndData(blockposition_mutableblockposition, this.a(worldserver, blockposition_mutableblockposition, j2), 3);
+ // 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()) {
+ continue;
+ }
+
2020-06-25 02:00:00 +02:00
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition_mutableblockposition, this.a(worldserver, blockposition_mutableblockposition, j2), 3); // CraftBukkit
+ }
+ // CraftBukkit end
}
}
}
@@ -189,12 +223,24 @@
2020-06-25 02:00:00 +02:00
return iblockdata.b(BlockProperties.C) && (Boolean) iblockdata.get(BlockProperties.C) ? 0 : this.flameChances.getInt(iblockdata.getBlock());
2017-03-08 23:20:24 +01:00
}
2020-06-25 02:00:00 +02:00
- 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));
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);