2022-12-20 06:09:51 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 22 Oct 2021 16:25:07 -0700
2023-07-12 21:12:12 +02:00
Subject: [PATCH] Add exploded block state to BlockExplodeEvent and
EntityDamageByBlockEvent
2022-12-20 06:09:51 +01:00
diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSource.java b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
2024-01-19 12:30:04 +01:00
index ed1277fad60992344b94f8a939febaca3edd9702..fc6903b20a6e084729306fc960a6fc80e094f76c 100644
2022-12-20 06:09:51 +01:00
--- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
2023-03-15 01:06:28 +01:00
@@ -52,6 +52,7 @@ public class DamageSource {
2022-12-20 06:09:51 +01:00
return this;
}
2023-03-15 01:06:28 +01:00
// CraftBukkit end
2022-12-20 06:09:51 +01:00
+ public @Nullable org.bukkit.block.BlockState explodedBlockState; // Paper - add exploded state
2023-03-15 01:06:28 +01:00
public String toString() {
return "DamageSource (" + this.type().msgId() + ")";
diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSources.java b/src/main/java/net/minecraft/world/damagesource/DamageSources.java
2024-01-16 12:41:40 +01:00
index 8bde8c581796ed11809b80b9a30a33df86116745..f339475185645f7be30963e4f980ce81a6f7e536 100644
2023-03-15 01:06:28 +01:00
--- a/src/main/java/net/minecraft/world/damagesource/DamageSources.java
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSources.java
2023-06-08 10:47:19 +02:00
@@ -247,8 +247,17 @@ public class DamageSources {
2023-03-15 01:06:28 +01:00
return this.source(DamageTypes.SONIC_BOOM, attacker);
2022-12-20 06:09:51 +01:00
}
2024-01-16 12:41:40 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper - add exploded state
2023-03-15 01:06:28 +01:00
public DamageSource badRespawnPointExplosion(Vec3 position) {
- return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), position);
2024-01-16 12:41:40 +01:00
+ // Paper start - add exploded state
2023-03-15 01:06:28 +01:00
+ return this.badRespawnPointExplosion(position, null);
2022-12-20 06:09:51 +01:00
+ }
2023-03-15 01:06:28 +01:00
+
+ public DamageSource badRespawnPointExplosion(Vec3 position, @Nullable org.bukkit.block.BlockState explodedBlockState) {
+ DamageSource source = new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), position);
2022-12-20 06:09:51 +01:00
+ source.explodedBlockState = explodedBlockState;
+ return source;
2024-01-16 12:41:40 +01:00
+ // Paper end - add exploded state
2022-12-20 06:09:51 +01:00
}
2023-06-08 10:47:19 +02:00
public DamageSource outOfBorder() {
2022-12-20 06:09:51 +01:00
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
2024-01-24 15:57:53 +01:00
index c7075aaf417b1dc9eab4a19b72fac50d2a44286b..34159798e6617ce13b3ac8aae07d24d9bca6ee36 100644
2022-12-20 06:09:51 +01:00
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
2024-01-23 12:06:27 +01:00
@@ -367,7 +367,7 @@ public class Explosion {
2022-12-20 06:09:51 +01:00
bukkitBlocks = event.blockList();
2023-12-06 17:21:56 +01:00
this.yield = event.getYield();
2022-12-20 06:09:51 +01:00
} else {
2023-12-06 17:21:56 +01:00
- BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.yield);
2024-01-16 12:41:40 +01:00
+ BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.yield, this.damageSource.explodedBlockState); // Paper - add exploded state
2022-12-20 06:09:51 +01:00
this.level.getCraftServer().getPluginManager().callEvent(event);
2023-12-06 17:21:56 +01:00
this.wasCanceled = event.isCancelled();
2022-12-20 06:09:51 +01:00
bukkitBlocks = event.blockList();
diff --git a/src/main/java/net/minecraft/world/level/block/BedBlock.java b/src/main/java/net/minecraft/world/level/block/BedBlock.java
2024-02-01 10:15:57 +01:00
index c5d892950b4027cf9879eafc1c0f4e4c62fb4f51..c14cddd42c61512c312231b1e93ccc6efbde620c 100644
2022-12-20 06:09:51 +01:00
--- a/src/main/java/net/minecraft/world/level/block/BedBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BedBlock.java
2023-12-06 17:21:56 +01:00
@@ -96,6 +96,7 @@ public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock
2022-12-20 06:09:51 +01:00
// CraftBukkit - moved world and biome check into EntityHuman
if (false && !BedBlock.canSetSpawn(world)) {
2024-01-16 12:41:40 +01:00
+ final org.bukkit.block.BlockState explodedBlockState = org.bukkit.craftbukkit.block.CraftBlockStates.getUnplacedBlockState(world, pos, state); // Paper - add exploded state (this won't be called due to the false, but it's good for reference)
2022-12-20 06:09:51 +01:00
world.removeBlock(pos, false);
BlockPos blockposition1 = pos.relative(((Direction) state.getValue(BedBlock.FACING)).getOpposite());
2023-12-06 17:21:56 +01:00
@@ -105,7 +106,7 @@ public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock
2022-12-20 06:09:51 +01:00
Vec3 vec3d = pos.getCenter();
2023-03-15 01:06:28 +01:00
- world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, Level.ExplosionInteraction.BLOCK);
2024-01-16 12:41:40 +01:00
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, explodedBlockState), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, Level.ExplosionInteraction.BLOCK); // Paper - add exploded state
2022-12-20 06:09:51 +01:00
return InteractionResult.SUCCESS;
} else if ((Boolean) state.getValue(BedBlock.OCCUPIED)) {
if (!this.kickVillagerOutOfBed(world, pos)) {
2023-12-06 17:21:56 +01:00
@@ -147,6 +148,7 @@ public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock
2022-12-20 06:09:51 +01:00
private InteractionResult explodeBed(BlockState iblockdata, Level world, BlockPos blockposition) {
{
{
2024-01-16 12:41:40 +01:00
+ final org.bukkit.block.BlockState explodedBlockState = org.bukkit.craftbukkit.block.CraftBlockStates.getUnplacedBlockState(world, blockposition, iblockdata); // Paper - add exploded state
2022-12-20 06:09:51 +01:00
world.removeBlock(blockposition, false);
BlockPos blockposition1 = blockposition.relative(((Direction) iblockdata.getValue(BedBlock.FACING)).getOpposite());
2023-12-06 17:21:56 +01:00
@@ -156,7 +158,7 @@ public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock
2022-12-20 06:09:51 +01:00
Vec3 vec3d = blockposition.getCenter();
2023-03-15 01:06:28 +01:00
- world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, Level.ExplosionInteraction.BLOCK);
2024-01-16 12:41:40 +01:00
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, explodedBlockState), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, Level.ExplosionInteraction.BLOCK); // Paper - add exploded state
2022-12-20 06:09:51 +01:00
return InteractionResult.SUCCESS;
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
2024-01-19 17:54:05 +01:00
index acd5ec218b8d4c096f44ae2eec1379eeaf30ddc5..088262f306755a9cb785c7a0cf0a9c66ed0965a8 100644
2022-12-20 06:09:51 +01:00
--- a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
2023-12-06 17:21:56 +01:00
@@ -131,6 +131,7 @@ public class RespawnAnchorBlock extends Block {
2022-12-20 06:09:51 +01:00
}
private void explode(BlockState state, Level world, final BlockPos explodedPos) {
2024-01-16 12:41:40 +01:00
+ final org.bukkit.block.BlockState explodedBlockState = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(explodedPos, state, null); // Paper - add exploded state
2022-12-20 06:09:51 +01:00
world.removeBlock(explodedPos, false);
2023-05-12 13:10:08 +02:00
Stream<Direction> stream = Direction.Plane.HORIZONTAL.stream(); // CraftBukkit - decompile error
2023-12-06 17:21:56 +01:00
@@ -147,7 +148,7 @@ public class RespawnAnchorBlock extends Block {
2022-12-20 06:09:51 +01:00
};
2023-05-12 13:10:08 +02:00
Vec3 vec3d = explodedPos.getCenter();
- world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d), explosiondamagecalculator, vec3d, 5.0F, true, Level.ExplosionInteraction.BLOCK);
2024-01-16 12:41:40 +01:00
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, explodedBlockState), explosiondamagecalculator, vec3d, 5.0F, true, Level.ExplosionInteraction.BLOCK); // Paper - add exploded state
2022-12-20 06:09:51 +01:00
}
public static boolean canSetSpawn(Level world) {
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
2024-01-16 12:41:40 +01:00
index f81c0d07a5efc92942d8ab5c50a8260db033307d..8afc396c162d928902a9d9beb9f039b06630f755 100644
2022-12-20 06:09:51 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
2024-01-14 10:46:04 +01:00
@@ -276,6 +276,12 @@ public final class CraftBlockStates {
2022-12-20 06:09:51 +01:00
BlockEntity tileEntity = (blockEntityTag == null) ? null : BlockEntity.loadStatic(blockPosition, blockData, blockEntityTag);
return CraftBlockStates.getBlockState(null, blockPosition, blockData, tileEntity);
}
2024-01-16 12:41:40 +01:00
+ // Paper start - add exploded state
2022-12-20 06:09:51 +01:00
+ public static BlockState getUnplacedBlockState(net.minecraft.world.level.BlockGetter levelAccessor, BlockPos blockPos, net.minecraft.world.level.block.state.BlockState blockData) {
+ BlockEntity tileEntity = levelAccessor.getBlockEntity(blockPos);
+ return CraftBlockStates.getBlockState(null, blockPos, blockData, tileEntity);
+ }
2024-01-16 12:41:40 +01:00
+ // Paper end - add exploded state
2022-12-20 06:09:51 +01:00
// See BlockStateFactory#createBlockState(World, BlockPosition, IBlockData, TileEntity)
private static CraftBlockState getBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) {
2023-07-12 21:12:12 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-02-01 10:15:57 +01:00
index a1860e21fd53b801ffd651cd27f5a8f9fcd02ee0..52444c7c83e60e5fe40c485c13a59cca9ce5ee20 100644
2023-07-12 21:12:12 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-02-10 20:27:29 +01:00
@@ -1071,7 +1071,7 @@ public class CraftEventFactory {
2023-07-12 21:12:12 +02:00
CraftEventFactory.entityDamage = null;
EntityDamageEvent event;
if (damager == null) {
- event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.BLOCK_EXPLOSION, modifiers, modifierFunctions);
2024-01-16 12:41:40 +01:00
+ event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.BLOCK_EXPLOSION, modifiers, modifierFunctions, source.explodedBlockState); // Paper - add exploded state
2023-07-12 21:12:12 +02:00
} else if (entity instanceof EnderDragon && /*PAIL FIXME ((EntityEnderDragon) entity).target == damager*/ false) {
event = new EntityDamageEvent(entity.getBukkitEntity(), DamageCause.ENTITY_EXPLOSION, modifiers, modifierFunctions);
} else {