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 uh) {
        super(uh);
    }
    
    @Override
    public boolean matches(final CraftingContainer bgu, final Level bqb) {
        boolean boolean4 = false;
        boolean boolean5 = false;
        for (int integer6 = 0; integer6 < bgu.getContainerSize(); ++integer6) {
            final ItemStack bki7 = bgu.getItem(integer6);
            if (!bki7.isEmpty()) {
                if (bki7.getItem() instanceof DyeItem) {
                    boolean4 = true;
                }
                else {
                    if (!FireworkStarFadeRecipe.STAR_INGREDIENT.test(bki7)) {
                        return false;
                    }
                    if (boolean5) {
                        return false;
                    }
                    boolean5 = true;
                }
            }
        }
        return boolean5 && boolean4;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer bgu) {
        final List<Integer> list3 = Lists.newArrayList();
        ItemStack bki4 = null;
        for (int integer5 = 0; integer5 < bgu.getContainerSize(); ++integer5) {
            final ItemStack bki5 = bgu.getItem(integer5);
            final Item bke7 = bki5.getItem();
            if (bke7 instanceof DyeItem) {
                list3.add(((DyeItem)bke7).getDyeColor().getFireworkColor());
            }
            else if (FireworkStarFadeRecipe.STAR_INGREDIENT.test(bki5)) {
                bki4 = bki5.copy();
                bki4.setCount(1);
            }
        }
        if (bki4 == null || list3.isEmpty()) {
            return ItemStack.EMPTY;
        }
        bki4.getOrCreateTagElement("Explosion").putIntArray("FadeColors", list3);
        return bki4;
    }
    
    @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);
    }
}
