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 sm) {
        super(sm);
    }
    
    @Override
    public boolean matches(final CraftingContainer baz, final Level bjw) {
        ItemStack ben4 = ItemStack.EMPTY;
        final List<ItemStack> list5 = Lists.newArrayList();
        for (int integer6 = 0; integer6 < baz.getContainerSize(); ++integer6) {
            final ItemStack ben5 = baz.getItem(integer6);
            if (!ben5.isEmpty()) {
                if (ben5.getItem() instanceof DyeableLeatherItem) {
                    if (!ben4.isEmpty()) {
                        return false;
                    }
                    ben4 = ben5;
                }
                else {
                    if (!(ben5.getItem() instanceof DyeItem)) {
                        return false;
                    }
                    list5.add(ben5);
                }
            }
        }
        return !ben4.isEmpty() && !list5.isEmpty();
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer baz) {
        final List<DyeItem> list3 = Lists.newArrayList();
        ItemStack ben4 = ItemStack.EMPTY;
        for (int integer5 = 0; integer5 < baz.getContainerSize(); ++integer5) {
            final ItemStack ben5 = baz.getItem(integer5);
            if (!ben5.isEmpty()) {
                final Item bei7 = ben5.getItem();
                if (bei7 instanceof DyeableLeatherItem) {
                    if (!ben4.isEmpty()) {
                        return ItemStack.EMPTY;
                    }
                    ben4 = ben5.copy();
                }
                else {
                    if (!(bei7 instanceof DyeItem)) {
                        return ItemStack.EMPTY;
                    }
                    list3.add((DyeItem)bei7);
                }
            }
        }
        if (ben4.isEmpty() || list3.isEmpty()) {
            return ItemStack.EMPTY;
        }
        return DyeableLeatherItem.dyeArmor(ben4, list3);
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.ARMOR_DYE;
    }
}
