package net.minecraft.world.item.crafting;

import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.Container;
import net.minecraft.world.item.Item;
import java.util.List;
import com.google.common.collect.Lists;
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;

public class FireworkStarFadeRecipe extends CustomRecipe {
    private static final Ingredient STAR_INGREDIENT;
    
    public FireworkStarFadeRecipe(final ResourceLocation sm) {
        super(sm);
    }
    
    @Override
    public boolean matches(final CraftingContainer baz, final Level bjw) {
        boolean boolean4 = false;
        boolean boolean5 = false;
        for (int integer6 = 0; integer6 < baz.getContainerSize(); ++integer6) {
            final ItemStack ben7 = baz.getItem(integer6);
            if (!ben7.isEmpty()) {
                if (ben7.getItem() instanceof DyeItem) {
                    boolean4 = true;
                }
                else {
                    if (!FireworkStarFadeRecipe.STAR_INGREDIENT.test(ben7)) {
                        return false;
                    }
                    if (boolean5) {
                        return false;
                    }
                    boolean5 = true;
                }
            }
        }
        return boolean5 && boolean4;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer baz) {
        final List<Integer> list3 = Lists.newArrayList();
        ItemStack ben4 = null;
        for (int integer5 = 0; integer5 < baz.getContainerSize(); ++integer5) {
            final ItemStack ben5 = baz.getItem(integer5);
            final Item bei7 = ben5.getItem();
            if (bei7 instanceof DyeItem) {
                list3.add(((DyeItem)bei7).getDyeColor().getFireworkColor());
            }
            else if (FireworkStarFadeRecipe.STAR_INGREDIENT.test(ben5)) {
                ben4 = ben5.copy();
                ben4.setCount(1);
            }
        }
        if (ben4 == null || list3.isEmpty()) {
            return ItemStack.EMPTY;
        }
        ben4.getOrCreateTagElement("Explosion").putIntArray("FadeColors", list3);
        return ben4;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.FIREWORK_STAR_FADE;
    }
    
    static {
        STAR_INGREDIENT = Ingredient.of(Items.FIREWORK_STAR);
    }
}
