package net.minecraft.world.item;

import net.minecraft.world.level.dimension.end.EndDragonFight;
import java.util.List;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.InteractionResult;

public class EndCrystalItem extends Item {
    public EndCrystalItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext blv) {
        final Level bqb3 = blv.getLevel();
        final BlockPos fu4 = blv.getClickedPos();
        final BlockState cfj5 = bqb3.getBlockState(fu4);
        if (!cfj5.is(Blocks.OBSIDIAN) && !cfj5.is(Blocks.BEDROCK)) {
            return InteractionResult.FAIL;
        }
        final BlockPos fu5 = fu4.above();
        if (!bqb3.isEmptyBlock(fu5)) {
            return InteractionResult.FAIL;
        }
        final double double7 = fu5.getX();
        final double double8 = fu5.getY();
        final double double9 = fu5.getZ();
        final List<Entity> list13 = bqb3.getEntities(null, new AABB(double7, double8, double9, double7 + 1.0, double8 + 2.0, double9 + 1.0));
        if (!list13.isEmpty()) {
            return InteractionResult.FAIL;
        }
        if (bqb3 instanceof ServerLevel) {
            final EndCrystal bab14 = new EndCrystal(bqb3, double7 + 0.5, double8, double9 + 0.5);
            bab14.setShowBottom(false);
            bqb3.addFreshEntity(bab14);
            final EndDragonFight cii15 = ((ServerLevel)bqb3).dragonFight();
            if (cii15 != null) {
                cii15.tryRespawn();
            }
        }
        blv.getItemInHand().shrink(1);
        return InteractionResult.sidedSuccess(bqb3.isClientSide);
    }
    
    @Override
    public boolean isFoil(final ItemStack bki) {
        return true;
    }
}
