2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
Date: Mon, 16 Jul 2018 00:05:05 +0300
Subject: [PATCH] Add TNTPrimeEvent
diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
2024-10-23 12:32:08 +02:00
index ba1bb0f82634054e02c5f4bc062c1822a356e2a6..25d2226c2a5dda411a9e35f7a0e3ab183110c227 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
2024-10-23 12:32:08 +02:00
@@ -543,6 +543,11 @@ public class EnderDragon extends Mob implements Enemy {
2021-06-11 14:02:28 +02:00
});
2023-06-07 22:19:14 +02:00
craftBlock.getNMS().spawnAfterBreak((ServerLevel) this.level(), blockposition, ItemStack.EMPTY, false);
2021-06-11 14:02:28 +02:00
}
+ // Paper start - TNTPrimeEvent
2024-02-01 10:15:57 +01:00
+ org.bukkit.block.Block tntBlock = CraftBlock.at(this.level(), blockposition);
2024-01-21 17:39:05 +01:00
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, explosionSource.getIndirectSourceEntity().getBukkitEntity()).callEvent())
2021-06-11 14:02:28 +02:00
+ continue;
2024-01-21 17:39:05 +01:00
+ // Paper end - TNTPrimeEvent
2024-10-23 12:32:08 +02:00
nmsBlock.wasExploded((ServerLevel) this.level(), blockposition, this.explosionSource);
2021-06-11 14:02:28 +02:00
2023-06-07 22:19:14 +02:00
this.level().removeBlock(blockposition, false);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/FireBlock.java b/src/main/java/net/minecraft/world/level/block/FireBlock.java
2024-10-23 12:32:08 +02:00
index 88976aa06028adcb8f0c91e32b794887d0b55308..f44457c0d75efe323cc8242ef5173a3d5067fad0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/FireBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FireBlock.java
2023-12-05 23:12:48 +01:00
@@ -302,12 +302,19 @@ public class FireBlock extends BaseFireBlock {
2021-06-11 14:02:28 +02:00
world.setBlock(blockposition, this.getStateWithAge(world, blockposition, l), 3);
} else {
- world.removeBlock(blockposition, false);
2024-01-21 17:39:05 +01:00
+ if(iblockdata.getBlock() != Blocks.TNT) world.removeBlock(blockposition, false); // Paper - TNTPrimeEvent; We might be cancelling it below, move the setAir down
2021-06-11 14:02:28 +02:00
}
Block block = iblockdata.getBlock();
2022-06-07 23:45:11 +02:00
if (block instanceof TntBlock) {
2021-06-11 14:02:28 +02:00
+ // Paper start - TNTPrimeEvent
2024-02-01 10:15:57 +01:00
+ org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition);
2021-06-13 01:45:00 +02:00
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.FIRE, null).callEvent()) {
2021-06-11 14:02:28 +02:00
+ return;
+ }
2021-06-17 23:39:36 +02:00
+ world.removeBlock(blockposition, false);
2024-01-21 17:39:05 +01:00
+ // Paper end - TNTPrimeEvent
2021-06-11 14:02:28 +02:00
TntBlock.explode(world, blockposition);
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/TntBlock.java b/src/main/java/net/minecraft/world/level/block/TntBlock.java
2024-10-23 12:32:08 +02:00
index 5e14568b325dc805e507d23ae66e789fc35ec3df..d256b0f3998028709334dd6c394d184f2c36efce 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/TntBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/TntBlock.java
2024-10-23 12:32:08 +02:00
@@ -52,6 +52,12 @@ public class TntBlock extends Block {
2024-04-24 04:46:06 +02:00
protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
2021-06-11 14:02:28 +02:00
if (!oldState.is(state.getBlock())) {
2023-05-12 13:10:08 +02:00
if (world.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(world, pos, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
2021-06-11 14:02:28 +02:00
+ // Paper start - TNTPrimeEvent
2024-02-01 10:15:57 +01:00
+ org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
2023-05-12 13:10:08 +02:00
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent()) {
2021-06-11 14:02:28 +02:00
+ return;
2023-05-12 13:10:08 +02:00
+ }
2024-01-21 17:39:05 +01:00
+ // Paper end - TNTPrimeEvent
2021-06-13 01:45:00 +02:00
TntBlock.explode(world, pos);
2021-06-11 14:02:28 +02:00
world.removeBlock(pos, false);
}
2024-10-23 12:32:08 +02:00
@@ -62,6 +68,12 @@ public class TntBlock extends Block {
2021-06-11 14:02:28 +02:00
@Override
2024-10-23 12:32:08 +02:00
protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) {
if (world.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(world, pos, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
2021-06-11 14:02:28 +02:00
+ // Paper start - TNTPrimeEvent
2024-02-01 10:15:57 +01:00
+ org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
2023-05-12 13:10:08 +02:00
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent()) {
2021-06-11 14:02:28 +02:00
+ return;
2023-05-12 13:10:08 +02:00
+ }
2024-01-21 17:39:05 +01:00
+ // Paper end - TNTPrimeEvent
2021-06-13 01:45:00 +02:00
TntBlock.explode(world, pos);
2021-06-11 14:02:28 +02:00
world.removeBlock(pos, false);
}
2024-10-23 12:32:08 +02:00
@@ -79,6 +91,13 @@ public class TntBlock extends Block {
2021-06-11 14:02:28 +02:00
@Override
2024-10-23 12:32:08 +02:00
public void wasExploded(ServerLevel world, BlockPos pos, Explosion explosion) {
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
+ org.bukkit.entity.Entity source = explosion.getDirectSourceEntity() != null ? explosion.getDirectSourceEntity().getBukkitEntity() : null;
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, source).callEvent()) {
+ return;
+ }
+ // Paper end - TNTPrimeEvent
PrimedTnt entitytntprimed = new PrimedTnt(world, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getIndirectSourceEntity());
int i = entitytntprimed.getFuse();
2021-06-11 14:02:28 +02:00
2024-04-24 04:46:06 +02:00
@@ -110,6 +129,12 @@ public class TntBlock extends Block {
2024-10-23 12:32:08 +02:00
return InteractionResult.CONSUME;
2023-05-12 13:10:08 +02:00
}
// CraftBukkit end
2021-06-11 14:02:28 +02:00
+ // Paper start - TNTPrimeEvent
2024-02-01 10:15:57 +01:00
+ org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
2023-05-12 13:10:08 +02:00
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.ITEM, player.getBukkitEntity()).callEvent()) {
2024-10-23 12:32:08 +02:00
+ return InteractionResult.FAIL;
2023-05-12 13:10:08 +02:00
+ }
2024-01-21 17:39:05 +01:00
+ // Paper end - TNTPrimeEvent
2021-11-23 16:04:41 +01:00
TntBlock.explode(world, pos, player);
2021-06-11 14:02:28 +02:00
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
2024-04-24 04:46:06 +02:00
Item item = stack.getItem();
2024-06-13 21:04:27 +02:00
@@ -137,6 +162,12 @@ public class TntBlock extends Block {
2021-06-13 01:45:00 +02:00
return;
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
+ // Paper start - TNTPrimeEvent
2024-02-01 10:15:57 +01:00
+ org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition);
2021-06-13 01:45:00 +02:00
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.PROJECTILE, projectile.getBukkitEntity()).callEvent()) {
2021-06-11 14:02:28 +02:00
+ return;
+ }
2024-01-21 17:39:05 +01:00
+ // Paper end - TNTPrimeEvent
2021-06-13 01:45:00 +02:00
TntBlock.explode(world, blockposition, entity instanceof LivingEntity ? (LivingEntity) entity : null);
2021-06-11 14:02:28 +02:00
world.removeBlock(blockposition, false);
}