From 983e0a93db9fbe93397f290530357862da008e73 Mon Sep 17 00:00:00 2001 From: LexManos Date: Tue, 9 Jul 2019 17:07:09 -0700 Subject: [PATCH] Re-implement state.onBlockExploded() Closes #5914 --- .../net/minecraft/world/Explosion.java.patch | 13 +++++++++++-- .../common/extensions/IForgeBlock.java | 15 +++++++++++++++ .../common/extensions/IForgeBlockState.java | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/patches/minecraft/net/minecraft/world/Explosion.java.patch b/patches/minecraft/net/minecraft/world/Explosion.java.patch index 3cc83ddc2..8bc35e97e 100644 --- a/patches/minecraft/net/minecraft/world/Explosion.java.patch +++ b/patches/minecraft/net/minecraft/world/Explosion.java.patch @@ -48,7 +48,16 @@ LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld)this.field_77287_j)).func_216023_a(this.field_77287_j.field_73012_v).func_216015_a(LootParameters.field_216286_f, blockpos).func_216015_a(LootParameters.field_216289_i, ItemStack.field_190927_a).func_216021_b(LootParameters.field_216288_h, tileentity); if (this.field_222260_b == Explosion.Mode.DESTROY) { lootcontext$builder.func_216015_a(LootParameters.field_216290_j, this.field_77280_f); -@@ -248,7 +251,7 @@ +@@ -240,15 +243,14 @@ + Block.func_220078_b(blockstate, lootcontext$builder); + } + +- this.field_77287_j.func_180501_a(blockpos, Blocks.field_150350_a.func_176223_P(), 3); +- block.func_180652_a(this.field_77287_j, blockpos, this); ++ blockstate.onBlockExploded(this.field_77287_j, blockpos, this); + } + } + } if (this.field_77286_a) { for(BlockPos blockpos1 : this.field_77281_g) { @@ -57,7 +66,7 @@ this.field_77287_j.func_175656_a(blockpos1, Blocks.field_150480_ab.func_176223_P()); } } -@@ -287,6 +290,10 @@ +@@ -287,6 +289,10 @@ return this.field_77281_g; } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java b/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java index b25af5d3f..eb3191385 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java @@ -1009,4 +1009,19 @@ public interface IForgeBlock * This should be used in favor of TagCollection.getOwningTags, as this caches the result and automatically updates when the TagCollection changes. */ Set getTags(); + + /** + * Called when the block is destroyed by an explosion. + * Useful for allowing the block to take into account tile entities, + * state, etc. when exploded, before it is removed. + * + * @param world The current world + * @param pos Block position in world + * @param explosion The explosion instance affecting the block + */ + default void onBlockExploded(BlockState state, World world, BlockPos pos, Explosion explosion) + { + world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3); + getBlock().onExplosionDestroy(world, pos, explosion); + } } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java b/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java index 5cbb53f8c..f133f02b8 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java @@ -853,4 +853,18 @@ public interface IForgeBlockState { return getBlockState().getBlock().canDropFromExplosion(getBlockState(), world, pos, explosion); } + + /** + * Called when the block is destroyed by an explosion. + * Useful for allowing the block to take into account tile entities, + * state, etc. when exploded, before it is removed. + * + * @param world The current world + * @param pos Block position in world + * @param explosion The explosion instance affecting the block + */ + default void onBlockExploded(World world, BlockPos pos, Explosion explosion) + { + getBlockState().getBlock().onBlockExploded(getBlockState(), world, pos, explosion); + } }