Search in sources :

Example 1 with TileNuclearBomb

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;
}
Also used : TileNuclearBomb(net.reikeb.electrona.tileentities.TileNuclearBomb) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CollisionContext(net.minecraft.world.phys.shapes.CollisionContext) Items(net.minecraft.world.item.Items) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) ServerLevel(net.minecraft.server.level.ServerLevel) ElectronaUtils(net.reikeb.electrona.utils.ElectronaUtils) NuclearExplosion(net.reikeb.electrona.world.NuclearExplosion) ServerPlayer(net.minecraft.server.level.ServerPlayer) BlockGetter(net.minecraft.world.level.BlockGetter) LootContext(net.minecraft.world.level.storage.loot.LootContext) Gamerules(net.reikeb.electrona.world.Gamerules) net.minecraft.world.level.block(net.minecraft.world.level.block) BombFallingEntity(net.reikeb.electrona.entity.BombFallingEntity) StateDefinition(net.minecraft.world.level.block.state.StateDefinition) BlockHitResult(net.minecraft.world.phys.BlockHitResult) InteractionResult(net.minecraft.world.InteractionResult) TileNuclearBomb(net.reikeb.electrona.tileentities.TileNuclearBomb) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Explosion(net.minecraft.world.level.Explosion) Material(net.minecraft.world.level.material.Material) Player(net.minecraft.world.entity.player.Player) CustomShapes(net.reikeb.electrona.misc.vm.CustomShapes) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) DirectionProperty(net.minecraft.world.level.block.state.properties.DirectionProperty) MenuProvider(net.minecraft.world.MenuProvider) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) Collections(java.util.Collections) NetworkHooks(net.minecraftforge.network.NetworkHooks) NuclearExplosion(net.reikeb.electrona.world.NuclearExplosion) ServerPlayer(net.minecraft.server.level.ServerPlayer) ItemStack(net.minecraft.world.item.ItemStack) MenuProvider(net.minecraft.world.MenuProvider) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with TileNuclearBomb

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);
    }
}
Also used : TileNuclearBomb(net.reikeb.electrona.tileentities.TileNuclearBomb) BombFallingEntity(net.reikeb.electrona.entity.BombFallingEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with TileNuclearBomb

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);
    }
}
Also used : TileNuclearBomb(net.reikeb.electrona.tileentities.TileNuclearBomb) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)3 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)3 TileNuclearBomb (net.reikeb.electrona.tileentities.TileNuclearBomb)3 BombFallingEntity (net.reikeb.electrona.entity.BombFallingEntity)2 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 InteractionHand (net.minecraft.world.InteractionHand)1 InteractionResult (net.minecraft.world.InteractionResult)1 MenuProvider (net.minecraft.world.MenuProvider)1 Player (net.minecraft.world.entity.player.Player)1 ItemStack (net.minecraft.world.item.ItemStack)1 Items (net.minecraft.world.item.Items)1 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)1 BlockGetter (net.minecraft.world.level.BlockGetter)1 Explosion (net.minecraft.world.level.Explosion)1