use of net.reikeb.electrona.tileentities.TileNuclearBomb in project Electrona-Project by Max094Reikeb.
the class NuclearBomb method use.
@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!worldIn.isClientSide) {
BlockEntity tile = worldIn.getBlockEntity(pos);
if (player.isCrouching() && player.getItemInHand(handIn).isEmpty()) {
player.setItemInHand(handIn, new ItemStack(this, 1));
worldIn.removeBlock(pos, true);
return InteractionResult.SUCCESS;
} else if (player.getItemInHand(handIn).getItem() == Items.FLINT_AND_STEEL) {
if (tile instanceof TileNuclearBomb) {
if (((TileNuclearBomb) tile).isCharged() && worldIn.getLevelData().getGameRules().getBoolean(Gamerules.DO_NUCLEAR_BOMBS_EXPLODE)) {
if (!player.isCreative()) {
player.getItemInHand(handIn).hurtAndBreak(1, player, (p_220287_1_) -> {
p_220287_1_.broadcastBreakEvent(handIn);
});
}
new NuclearExplosion(worldIn, pos.getX(), pos.getY(), pos.getZ(), ((TileNuclearBomb) tile).getNuclearCharge());
return InteractionResult.SUCCESS;
}
}
} else {
if (tile instanceof TileNuclearBomb) {
NetworkHooks.openGui((ServerPlayer) player, (MenuProvider) tile, pos);
return InteractionResult.SUCCESS;
}
}
}
return InteractionResult.SUCCESS;
}
use of net.reikeb.electrona.tileentities.TileNuclearBomb in project Electrona-Project by Max094Reikeb.
the class NuclearBomb method explode.
private void explode(ServerLevel world, BlockPos pos) {
BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof TileNuclearBomb) {
BombFallingEntity bombFallingEntity = new BombFallingEntity(world, (double) pos.getX() + 0.5D, pos.getY(), (double) pos.getZ() + 0.5D, world.getBlockState(pos), ((TileNuclearBomb) tile).isCharged(), ((TileNuclearBomb) tile).getNuclearCharge());
this.falling(bombFallingEntity);
world.addFreshEntity(bombFallingEntity);
}
}
use of net.reikeb.electrona.tileentities.TileNuclearBomb in project Electrona-Project by Max094Reikeb.
the class NuclearBomb method onRemove.
@Override
public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity tileentity = world.getBlockEntity(pos);
if (tileentity instanceof TileNuclearBomb) {
world.updateNeighbourForOutputSignal(pos, this);
}
super.onRemove(state, world, pos, newState, isMoving);
}
}
Aggregations