Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure Cryogenic Chamber parts break when the base block is destroyed by explosion #349

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -57,6 +58,18 @@ public BlockState playerWillDestroy(Level world, BlockPos pos, BlockState state,
return returnState;
}

@Override
public void wasExploded(Level world, BlockPos pos, Explosion explosion) {
for (BlockPos part : this.getOtherParts(world.getBlockState(pos))) {
part = pos.immutable().offset(part);
if (!(world.getBlockEntity(part) instanceof MultiBlockPart)) {
continue;
}
world.removeBlock(part, false);
}
super.wasExploded(world, pos, explosion);
}

@Override
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
for (BlockPos otherPart : this.getOtherParts(state)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
Expand Down Expand Up @@ -146,6 +147,18 @@ public void onPartDestroyed(Level level, Player player, BlockState blockState, B
}
}

@Override
public void wasExploded(Level world, BlockPos pos, Explosion explosion) {
for (BlockPos part : this.getOtherParts(world.getBlockState(pos))) {
part = pos.immutable().offset(part);
if (!(world.getBlockEntity(part) instanceof MultiBlockPart)) {
continue;
}
world.removeBlock(part, false);
}
super.wasExploded(world, pos, explosion);
}

@Override
public boolean canSurvive(BlockState blockState, LevelReader level, BlockPos blockPos) {
for (var otherPart : this.getOtherParts(blockState)) {
Expand Down