package net.minecraft.world.item;

import java.util.Comparator;
import java.util.Arrays;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.CompoundTag;
import java.util.Collection;
import net.minecraft.network.chat.TextComponent;
import com.google.common.collect.Lists;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.Component;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.InteractionResult;

public class FireworkRocketItem extends Item {
    public FireworkRocketItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext blv) {
        final Level bqb3 = blv.getLevel();
        if (!bqb3.isClientSide) {
            final ItemStack bki4 = blv.getItemInHand();
            final Vec3 dem5 = blv.getClickLocation();
            final Direction fz6 = blv.getClickedFace();
            final FireworkRocketEntity ben7 = new FireworkRocketEntity(bqb3, blv.getPlayer(), dem5.x + fz6.getStepX() * 0.15, dem5.y + fz6.getStepY() * 0.15, dem5.z + fz6.getStepZ() * 0.15, bki4);
            bqb3.addFreshEntity(ben7);
            bki4.shrink(1);
        }
        return InteractionResult.sidedSuccess(bqb3.isClientSide);
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bqb, final Player bec, final InteractionHand anf) {
        if (bec.isFallFlying()) {
            final ItemStack bki5 = bec.getItemInHand(anf);
            if (!bqb.isClientSide) {
                bqb.addFreshEntity(new FireworkRocketEntity(bqb, bki5, bec));
                if (!bec.abilities.instabuild) {
                    bki5.shrink(1);
                }
            }
            return InteractionResultHolder.<ItemStack>sidedSuccess(bec.getItemInHand(anf), bqb.isClientSide());
        }
        return InteractionResultHolder.<ItemStack>pass(bec.getItemInHand(anf));
    }
    
    @Override
    public void appendHoverText(final ItemStack bki, @Nullable final Level bqb, final List<Component> list, final TooltipFlag bls) {
        final CompoundTag le6 = bki.getTagElement("Fireworks");
        if (le6 == null) {
            return;
        }
        if (le6.contains("Flight", 99)) {
            list.add(new TranslatableComponent("item.minecraft.firework_rocket.flight").append(" ").append(String.valueOf(le6.getByte("Flight"))).withStyle(ChatFormatting.GRAY));
        }
        final ListTag lk7 = le6.getList("Explosions", 10);
        if (!lk7.isEmpty()) {
            for (int integer8 = 0; integer8 < lk7.size(); ++integer8) {
                final CompoundTag le7 = lk7.getCompound(integer8);
                final List<Component> list2 = Lists.newArrayList();
                FireworkStarItem.appendHoverText(le7, list2);
                if (!list2.isEmpty()) {
                    for (int integer9 = 1; integer9 < list2.size(); ++integer9) {
                        list2.set(integer9, new TextComponent("  ").append(list2.get(integer9)).withStyle(ChatFormatting.GRAY));
                    }
                    list.addAll(list2);
                }
            }
        }
    }
    
    public enum Shape {
        SMALL_BALL(0, "small_ball"), 
        LARGE_BALL(1, "large_ball"), 
        STAR(2, "star"), 
        CREEPER(3, "creeper"), 
        BURST(4, "burst");
        
        private static final Shape[] BY_ID;
        private final int id;
        private final String name;
        
        private Shape(final int integer3, final String string4) {
            this.id = integer3;
            this.name = string4;
        }
        
        public int getId() {
            return this.id;
        }
        
        public String getName() {
            return this.name;
        }
        
        public static Shape byId(final int integer) {
            if (integer < 0 || integer >= Shape.BY_ID.length) {
                return Shape.SMALL_BALL;
            }
            return Shape.BY_ID[integer];
        }
        
        static {
            BY_ID = Arrays.<Shape>stream(values()).sorted(Comparator.comparingInt(a -> a.id)).<Shape>toArray(Shape[]::new);
        }
    }
}
