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.level.dimension.end.TheEndDimension;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
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 bfz) {
        final Level bjw3 = bfz.getLevel();
        final BlockPos fk4 = bfz.getClickedPos();
        final BlockState byj5 = bjw3.getBlockState(fk4);
        if (byj5.getBlock() != Blocks.OBSIDIAN && byj5.getBlock() != Blocks.BEDROCK) {
            return InteractionResult.FAIL;
        }
        final BlockPos fk5 = fk4.above();
        if (!bjw3.isEmptyBlock(fk5)) {
            return InteractionResult.FAIL;
        }
        final double double7 = fk5.getX();
        final double double8 = fk5.getY();
        final double double9 = fk5.getZ();
        final List<Entity> list13 = bjw3.getEntities(null, new AABB(double7, double8, double9, double7 + 1.0, double8 + 2.0, double9 + 1.0));
        if (!list13.isEmpty()) {
            return InteractionResult.FAIL;
        }
        if (!bjw3.isClientSide) {
            final EndCrystal aur14 = new EndCrystal(bjw3, double7 + 0.5, double8, double9 + 0.5);
            aur14.setShowBottom(false);
            bjw3.addFreshEntity(aur14);
            if (bjw3.dimension instanceof TheEndDimension) {
                final EndDragonFight cbm15 = ((TheEndDimension)bjw3.dimension).getDragonFight();
                cbm15.tryRespawn();
            }
        }
        bfz.getItemInHand().shrink(1);
        return InteractionResult.SUCCESS;
    }
    
    @Override
    public boolean isFoil(final ItemStack ben) {
        return true;
    }
}
