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
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
index 0d84f1fb53384a827d7418c322a32e3286f4081a..6d01175ea2092bc5f5ebb7aa066450bfec2443a1 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
@@ -559,6 +559,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
2023-10-27 01:34:58 +02:00
nmsBlock.wasExploded(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-02-01 10:15:57 +01:00
index 016c8b7762c2b4eacb95a455940db4684b34e03c..da9cd2da60186b94f3b8a259c13b20f20e50fccb 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-02-01 10:15:57 +01:00
index cc20c320cbb3420e5e302a94571bab374c8553c8..4edd2e7bb62df65d6da8c8a623cf03e7e947bf75 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
2023-12-05 23:12:48 +01:00
@@ -49,6 +49,12 @@ 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())) {
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);
}
2023-12-05 23:12:48 +01:00
@@ -59,6 +65,12 @@ 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) {
2023-05-12 13:10:08 +02:00
if (world.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(world, pos, PrimeCause.REDSTONE, null, sourcePos)) { // 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);
}
2023-12-05 23:12:48 +01:00
@@ -77,6 +89,13 @@ 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
2024-02-01 10:15:57 +01:00
+ org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
2021-06-11 14:02:28 +02:00
+ org.bukkit.entity.Entity source = explosion.source != null ? explosion.source.getBukkitEntity() : null;
2023-05-12 13:10:08 +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;
2023-05-12 13:10:08 +02:00
+ }
2024-01-21 17:39:05 +01:00
+ // Paper end - TNTPrimeEvent
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
2023-12-05 23:12:48 +01:00
@@ -111,6 +130,12 @@ public class TntBlock extends Block {
2023-05-12 13:10:08 +02:00
return InteractionResult.CONSUME;
}
// 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()) {
2021-06-11 14:02:28 +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);
2021-06-13 01:45:00 +02:00
Item item = itemstack.getItem();
2023-12-05 23:12:48 +01:00
@@ -142,6 +167,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);
}