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
2022-12-08 07:11:20 +01:00
index a889be9dd2a94b531a227ff69a5e761e103067be..3b14fd5d67716a5b3610c10e8105d29f93a1d7a9 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
2022-06-07 23:45:11 +02:00
@@ -532,6 +532,11 @@ public class EnderDragon extends Mob implements Enemy {
2021-06-11 14:02:28 +02:00
});
2022-06-07 23:45:11 +02:00
craftBlock.getNMS().spawnAfterBreak((ServerLevel) level, blockposition, ItemStack.EMPTY, false);
2021-06-11 14:02:28 +02:00
}
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = level.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
2022-12-08 07:11:20 +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;
+ // Paper end
nmsBlock.wasExploded(level, blockposition, explosionSource);
this.level.removeBlock(blockposition, false);
diff --git a/src/main/java/net/minecraft/world/level/block/FireBlock.java b/src/main/java/net/minecraft/world/level/block/FireBlock.java
2022-12-07 20:22:28 +01:00
index e725168ebce3d1b2548a1bc5baa612a6e718e337..7e48326b6dc847a84e0aff2d393cadf9bace7979 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
2022-06-07 23:45:11 +02:00
@@ -290,12 +290,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);
+ if(iblockdata.getBlock() != Blocks.TNT) world.removeBlock(blockposition, false); // Paper - TNTPrimeEvent - We might be cancelling it below, move the setAir down
}
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
2022-10-24 21:43:46 +02:00
+ org.bukkit.block.Block tntBlock = io.papermc.paper.util.MCUtil.toBukkitBlock(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);
2021-06-11 14:02:28 +02:00
+ // Paper end
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
2022-12-07 20:22:28 +01:00
index f5b685cb678f523c1c07d72b818ada93af64840a..ade39e877edbb07082bb2d87e00ae4bfb6ab1c8f 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
2021-06-13 01:45:00 +02:00
@@ -38,6 +38,11 @@ public class TntBlock extends Block {
2021-06-11 14:02:28 +02:00
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
if (!oldState.is(state.getBlock())) {
if (world.hasNeighborSignal(pos)) {
+ // Paper start - TNTPrimeEvent
2022-10-24 21:43:46 +02:00
+ org.bukkit.block.Block tntBlock = io.papermc.paper.util.MCUtil.toBukkitBlock(world, pos);;
2021-06-13 01:45:00 +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;
+ // Paper end
2021-06-13 01:45:00 +02:00
TntBlock.explode(world, pos);
2021-06-11 14:02:28 +02:00
world.removeBlock(pos, false);
}
2021-06-13 01:45:00 +02:00
@@ -48,6 +53,11 @@ public class TntBlock extends Block {
2021-06-11 14:02:28 +02:00
@Override
2022-06-07 23:45:11 +02:00
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
2021-06-11 14:02:28 +02:00
if (world.hasNeighborSignal(pos)) {
+ // Paper start - TNTPrimeEvent
2022-10-24 21:43:46 +02:00
+ org.bukkit.block.Block tntBlock = io.papermc.paper.util.MCUtil.toBukkitBlock(world, pos);;
2021-06-13 01:45:00 +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;
+ // Paper end
2021-06-13 01:45:00 +02:00
TntBlock.explode(world, pos);
2021-06-11 14:02:28 +02:00
world.removeBlock(pos, false);
}
2021-06-13 01:45:00 +02:00
@@ -66,6 +76,12 @@ public class TntBlock extends Block {
2021-06-11 14:02:28 +02:00
@Override
public void wasExploded(Level world, BlockPos pos, Explosion explosion) {
if (!world.isClientSide) {
+ // Paper start - TNTPrimeEvent
2022-10-24 21:43:46 +02:00
+ org.bukkit.block.Block tntBlock = io.papermc.paper.util.MCUtil.toBukkitBlock(world, pos);
2021-06-11 14:02:28 +02:00
+ org.bukkit.entity.Entity source = explosion.source != null ? explosion.source.getBukkitEntity() : null;
2021-06-13 01:45:00 +02:00
+ if(!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, source).callEvent())
2021-06-11 14:02:28 +02:00
+ return;
+ // Paper end
2022-12-07 20:22:28 +01:00
PrimedTnt entitytntprimed = new PrimedTnt(world, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getIndirectSourceEntity());
2021-06-13 01:45:00 +02:00
int i = entitytntprimed.getFuse();
2021-06-11 14:02:28 +02:00
2021-06-13 01:45:00 +02:00
@@ -95,6 +111,11 @@ public class TntBlock extends Block {
if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) {
2021-06-11 14:02:28 +02:00
return super.use(state, world, pos, player, hand, hit);
} else {
+ // Paper start - TNTPrimeEvent
2022-10-24 21:43:46 +02:00
+ org.bukkit.block.Block tntBlock = io.papermc.paper.util.MCUtil.toBukkitBlock(world, pos);
2021-06-13 01:45:00 +02:00
+ if(!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.ITEM, player.getBukkitEntity()).callEvent())
2021-06-11 14:02:28 +02:00
+ return InteractionResult.FAIL;
+ // Paper end
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);
2021-06-13 01:45:00 +02:00
Item item = itemstack.getItem();
@@ -126,6 +147,12 @@ public class TntBlock extends Block {
return;
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
+ // Paper start - TNTPrimeEvent
2022-10-24 21:43:46 +02:00
+ org.bukkit.block.Block tntBlock = io.papermc.paper.util.MCUtil.toBukkitBlock(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;
+ }
+ // Paper end
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);
}