package net.minecraft.world.item.crafting;

import net.minecraft.world.Container;
import net.minecraft.world.item.Item;
import java.util.List;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.item.DyeableLeatherItem;
import com.google.common.collect.Lists;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.resources.ResourceLocation;

public class ArmorDyeRecipe extends CustomRecipe {
    public ArmorDyeRecipe(final ResourceLocation uh) {
        super(uh);
    }
    
    @Override
    public boolean matches(final CraftingContainer bgu, final Level bqb) {
        ItemStack bki4 = ItemStack.EMPTY;
        final List<ItemStack> list5 = Lists.newArrayList();
        for (int integer6 = 0; integer6 < bgu.getContainerSize(); ++integer6) {
            final ItemStack bki5 = bgu.getItem(integer6);
            if (!bki5.isEmpty()) {
                if (bki5.getItem() instanceof DyeableLeatherItem) {
                    if (!bki4.isEmpty()) {
                        return false;
                    }
                    bki4 = bki5;
                }
                else {
                    if (!(bki5.getItem() instanceof DyeItem)) {
                        return false;
                    }
                    list5.add(bki5);
                }
            }
        }
        return !bki4.isEmpty() && !list5.isEmpty();
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer bgu) {
        final List<DyeItem> list3 = Lists.newArrayList();
        ItemStack bki4 = ItemStack.EMPTY;
        for (int integer5 = 0; integer5 < bgu.getContainerSize(); ++integer5) {
            final ItemStack bki5 = bgu.getItem(integer5);
            if (!bki5.isEmpty()) {
                final Item bke7 = bki5.getItem();
                if (bke7 instanceof DyeableLeatherItem) {
                    if (!bki4.isEmpty()) {
                        return ItemStack.EMPTY;
                    }
                    bki4 = bki5.copy();
                }
                else {
                    if (!(bke7 instanceof DyeItem)) {
                        return ItemStack.EMPTY;
                    }
                    list3.add((DyeItem)bke7);
                }
            }
        }
        if (bki4.isEmpty() || list3.isEmpty()) {
            return ItemStack.EMPTY;
        }
        return DyeableLeatherItem.dyeArmor(bki4, list3);
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.ARMOR_DYE;
    }
}
