SPIGOT-7617: Add BlockExplodeEvent#getExplodedBlockState()

By: 2008Choco <hawkeboyz2@hotmail.com>
This commit is contained in:
CraftBukkit/Spigot 2024-04-29 20:08:56 +10:00
parent 1390477e34
commit a78a169340
5 changed files with 38 additions and 6 deletions

View file

@ -1,12 +1,14 @@
--- a/net/minecraft/world/damagesource/DamageSource.java
+++ b/net/minecraft/world/damagesource/DamageSource.java
@@ -21,6 +21,86 @@
@@ -21,6 +21,88 @@
private final Entity directEntity;
@Nullable
private final Vec3D damageSourcePosition;
+ // CraftBukkit start
+ @Nullable
+ private org.bukkit.block.Block directBlock; // The block that caused the damage. damageSourcePosition is not used for all block damages
+ @Nullable
+ public org.bukkit.block.BlockState blockState; // The block state of the block relevant to this damage source
+ private boolean withSweep = false;
+ private boolean melting = false;
+ private boolean poison = false;

View file

@ -33,3 +33,22 @@
public DamageSource inFire() {
return this.inFire;
}
@@ -250,7 +266,17 @@
}
public DamageSource badRespawnPointExplosion(Vec3D vec3d) {
- return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d);
+ // CraftBukkit start
+ return badRespawnPointExplosion(vec3d, null, null, null);
+ }
+
+ public DamageSource badRespawnPointExplosion(Vec3D vec3d, net.minecraft.world.level.World world, net.minecraft.world.level.block.state.IBlockData blockData, net.minecraft.core.BlockPosition position) {
+ DamageSource damageSource = new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d);
+ if (world != null && blockData != null && position != null) {
+ damageSource.blockState = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(world, position, blockData, null);
+ }
+ return damageSource;
+ // CraftBukkit end
}
public DamageSource outOfBorder() {

View file

@ -116,7 +116,7 @@
entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
if (entity instanceof EntityHuman) {
EntityHuman entityhuman = (EntityHuman) entity;
@@ -290,9 +349,63 @@
@@ -290,9 +349,65 @@
SystemUtils.shuffle(this.toBlow, this.level.random);
ObjectListIterator objectlistiterator = this.toBlow.iterator();
@ -143,7 +143,9 @@
+ bukkitBlocks = event.blockList();
+ this.yield = event.getYield();
+ } else {
+ BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.yield);
+ org.bukkit.block.Block block = location.getBlock();
+ org.bukkit.block.BlockState blockState = (damageSource.blockState != null) ? damageSource.blockState : block.getState();
+ BlockExplodeEvent event = new BlockExplodeEvent(block, blockState, blockList, this.yield);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ this.wasCanceled = event.isCancelled();
+ bukkitBlocks = event.blockList();
@ -180,7 +182,7 @@
this.level.getBlockState(blockposition).onExplosionHit(this.level, blockposition, this, (itemstack, blockposition1) -> {
addOrAppendStack(list, itemstack, blockposition1);
@@ -317,7 +430,11 @@
@@ -317,7 +432,11 @@
BlockPosition blockposition1 = (BlockPosition) objectlistiterator1.next();
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockposition1).isAir() && this.level.getBlockState(blockposition1.below()).isSolidRender(this.level, blockposition1.below())) {
@ -193,7 +195,7 @@
}
}
}
@@ -325,6 +442,7 @@
@@ -325,6 +444,7 @@
}
private static void addOrAppendStack(List<Pair<ItemStack, BlockPosition>> list, ItemStack itemstack, BlockPosition blockposition) {

View file

@ -44,7 +44,7 @@
+
+ Vec3D vec3d = blockposition.getCenter();
+
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, World.a.BLOCK);
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, world, iblockdata, blockposition), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, World.a.BLOCK); // CraftBukkit - add state
+ return EnumInteractionResult.SUCCESS;
+ }
+ }

View file

@ -26,3 +26,12 @@
@Override
public Optional<Float> getBlockExplosionResistance(Explosion explosion, IBlockAccess iblockaccess, BlockPosition blockposition1, IBlockData iblockdata1, Fluid fluid) {
return blockposition1.equals(blockposition) && flag1 ? Optional.of(Blocks.WATER.getExplosionResistance()) : super.getBlockExplosionResistance(explosion, iblockaccess, blockposition1, iblockdata1, fluid);
@@ -144,7 +144,7 @@
};
Vec3D vec3d = blockposition.getCenter();
- world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d), explosiondamagecalculator, vec3d, 5.0F, true, World.a.BLOCK);
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, world, iblockdata, blockposition), explosiondamagecalculator, vec3d, 5.0F, true, World.a.BLOCK); // CraftBukkit - add state
}
public static boolean canSetSpawn(World world) {