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 bfz) {
        final Level bjw3 = bfz.getLevel();
        if (!bjw3.isClientSide) {
            final ItemStack ben4 = bfz.getItemInHand();
            final Vec3 cvl5 = bfz.getClickLocation();
            final Direction fp6 = bfz.getClickedFace();
            final FireworkRocketEntity ayu7 = new FireworkRocketEntity(bjw3, cvl5.x + fp6.getStepX() * 0.15, cvl5.y + fp6.getStepY() * 0.15, cvl5.z + fp6.getStepZ() * 0.15, ben4);
            bjw3.addFreshEntity(ayu7);
            ben4.shrink(1);
        }
        return InteractionResult.SUCCESS;
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bjw, final Player ayj, final InteractionHand ajk) {
        if (ayj.isFallFlying()) {
            final ItemStack ben5 = ayj.getItemInHand(ajk);
            if (!bjw.isClientSide) {
                bjw.addFreshEntity(new FireworkRocketEntity(bjw, ben5, ayj));
                if (!ayj.abilities.instabuild) {
                    ben5.shrink(1);
                }
            }
            return InteractionResultHolder.<ItemStack>success(ayj.getItemInHand(ajk));
        }
        return InteractionResultHolder.<ItemStack>pass(ayj.getItemInHand(ajk));
    }
    
    @Override
    public void appendHoverText(final ItemStack ben, @Nullable final Level bjw, final List<Component> list, final TooltipFlag bfw) {
        final CompoundTag jt6 = ben.getTagElement("Fireworks");
        if (jt6 == null) {
            return;
        }
        if (jt6.contains("Flight", 99)) {
            list.add(new TranslatableComponent("item.minecraft.firework_rocket.flight", new Object[0]).append(" ").append(String.valueOf(jt6.getByte("Flight"))).withStyle(ChatFormatting.GRAY));
        }
        final ListTag jz7 = jt6.getList("Explosions", 10);
        if (!jz7.isEmpty()) {
            for (int integer8 = 0; integer8 < jz7.size(); ++integer8) {
                final CompoundTag jt7 = jz7.getCompound(integer8);
                final List<Component> list2 = Lists.newArrayList();
                FireworkStarItem.appendHoverText(jt7, 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);
        }
    }
}
