package net.minecraft.world.item.crafting;

import net.minecraft.Util;
import com.google.common.collect.Maps;
import java.util.HashMap;
import net.minecraft.world.Container;
import java.util.List;
import net.minecraft.nbt.CompoundTag;
import com.google.common.collect.Lists;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.FireworkRocketItem;
import net.minecraft.world.item.Item;
import java.util.Map;

public class FireworkStarRecipe extends CustomRecipe {
    private static final Ingredient SHAPE_INGREDIENT;
    private static final Ingredient TRAIL_INGREDIENT;
    private static final Ingredient FLICKER_INGREDIENT;
    private static final Map<Item, FireworkRocketItem.Shape> SHAPE_BY_ITEM;
    private static final Ingredient GUNPOWDER_INGREDIENT;
    
    public FireworkStarRecipe(final ResourceLocation uh) {
        super(uh);
    }
    
    @Override
    public boolean matches(final CraftingContainer bgu, final Level bqb) {
        boolean boolean4 = false;
        boolean boolean5 = false;
        boolean boolean6 = false;
        boolean boolean7 = false;
        boolean boolean8 = false;
        for (int integer9 = 0; integer9 < bgu.getContainerSize(); ++integer9) {
            final ItemStack bki10 = bgu.getItem(integer9);
            if (!bki10.isEmpty()) {
                if (FireworkStarRecipe.SHAPE_INGREDIENT.test(bki10)) {
                    if (boolean6) {
                        return false;
                    }
                    boolean6 = true;
                }
                else if (FireworkStarRecipe.FLICKER_INGREDIENT.test(bki10)) {
                    if (boolean8) {
                        return false;
                    }
                    boolean8 = true;
                }
                else if (FireworkStarRecipe.TRAIL_INGREDIENT.test(bki10)) {
                    if (boolean7) {
                        return false;
                    }
                    boolean7 = true;
                }
                else if (FireworkStarRecipe.GUNPOWDER_INGREDIENT.test(bki10)) {
                    if (boolean4) {
                        return false;
                    }
                    boolean4 = true;
                }
                else {
                    if (!(bki10.getItem() instanceof DyeItem)) {
                        return false;
                    }
                    boolean5 = true;
                }
            }
        }
        return boolean4 && boolean5;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer bgu) {
        final ItemStack bki3 = new ItemStack(Items.FIREWORK_STAR);
        final CompoundTag le4 = bki3.getOrCreateTagElement("Explosion");
        FireworkRocketItem.Shape a5 = FireworkRocketItem.Shape.SMALL_BALL;
        final List<Integer> list6 = Lists.newArrayList();
        for (int integer7 = 0; integer7 < bgu.getContainerSize(); ++integer7) {
            final ItemStack bki4 = bgu.getItem(integer7);
            if (!bki4.isEmpty()) {
                if (FireworkStarRecipe.SHAPE_INGREDIENT.test(bki4)) {
                    a5 = FireworkStarRecipe.SHAPE_BY_ITEM.get(bki4.getItem());
                }
                else if (FireworkStarRecipe.FLICKER_INGREDIENT.test(bki4)) {
                    le4.putBoolean("Flicker", true);
                }
                else if (FireworkStarRecipe.TRAIL_INGREDIENT.test(bki4)) {
                    le4.putBoolean("Trail", true);
                }
                else if (bki4.getItem() instanceof DyeItem) {
                    list6.add(((DyeItem)bki4.getItem()).getDyeColor().getFireworkColor());
                }
            }
        }
        le4.putIntArray("Colors", list6);
        le4.putByte("Type", (byte)a5.getId());
        return bki3;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public ItemStack getResultItem() {
        return new ItemStack(Items.FIREWORK_STAR);
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.FIREWORK_STAR;
    }
    
    static {
        SHAPE_INGREDIENT = Ingredient.of(Items.FIRE_CHARGE, Items.FEATHER, Items.GOLD_NUGGET, Items.SKELETON_SKULL, Items.WITHER_SKELETON_SKULL, Items.CREEPER_HEAD, Items.PLAYER_HEAD, Items.DRAGON_HEAD, Items.ZOMBIE_HEAD);
        TRAIL_INGREDIENT = Ingredient.of(Items.DIAMOND);
        FLICKER_INGREDIENT = Ingredient.of(Items.GLOWSTONE_DUST);
        SHAPE_BY_ITEM = Util.<Map<Item, FireworkRocketItem.Shape>>make(Maps.newHashMap(), hashMap -> {
            hashMap.put(Items.FIRE_CHARGE, FireworkRocketItem.Shape.LARGE_BALL);
            hashMap.put(Items.FEATHER, FireworkRocketItem.Shape.BURST);
            hashMap.put(Items.GOLD_NUGGET, FireworkRocketItem.Shape.STAR);
            hashMap.put(Items.SKELETON_SKULL, FireworkRocketItem.Shape.CREEPER);
            hashMap.put(Items.WITHER_SKELETON_SKULL, FireworkRocketItem.Shape.CREEPER);
            hashMap.put(Items.CREEPER_HEAD, FireworkRocketItem.Shape.CREEPER);
            hashMap.put(Items.PLAYER_HEAD, FireworkRocketItem.Shape.CREEPER);
            hashMap.put(Items.DRAGON_HEAD, FireworkRocketItem.Shape.CREEPER);
            hashMap.put(Items.ZOMBIE_HEAD, FireworkRocketItem.Shape.CREEPER);
            return;
        });
        GUNPOWDER_INGREDIENT = Ingredient.of(Items.GUNPOWDER);
    }
}
