package net.minecraft.world.item.crafting;

import net.minecraft.world.Container;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.BannerItem;
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 ShieldDecorationRecipe extends CustomRecipe {
    public ShieldDecorationRecipe(final ResourceLocation uh) {
        super(uh);
    }
    
    @Override
    public boolean matches(final CraftingContainer bgu, final Level bqb) {
        ItemStack bki4 = ItemStack.EMPTY;
        ItemStack bki5 = ItemStack.EMPTY;
        for (int integer6 = 0; integer6 < bgu.getContainerSize(); ++integer6) {
            final ItemStack bki6 = bgu.getItem(integer6);
            if (!bki6.isEmpty()) {
                if (bki6.getItem() instanceof BannerItem) {
                    if (!bki5.isEmpty()) {
                        return false;
                    }
                    bki5 = bki6;
                }
                else {
                    if (bki6.getItem() != Items.SHIELD) {
                        return false;
                    }
                    if (!bki4.isEmpty()) {
                        return false;
                    }
                    if (bki6.getTagElement("BlockEntityTag") != null) {
                        return false;
                    }
                    bki4 = bki6;
                }
            }
        }
        return !bki4.isEmpty() && !bki5.isEmpty();
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer bgu) {
        ItemStack bki3 = ItemStack.EMPTY;
        ItemStack bki4 = ItemStack.EMPTY;
        for (int integer5 = 0; integer5 < bgu.getContainerSize(); ++integer5) {
            final ItemStack bki5 = bgu.getItem(integer5);
            if (!bki5.isEmpty()) {
                if (bki5.getItem() instanceof BannerItem) {
                    bki3 = bki5;
                }
                else if (bki5.getItem() == Items.SHIELD) {
                    bki4 = bki5.copy();
                }
            }
        }
        if (bki4.isEmpty()) {
            return bki4;
        }
        final CompoundTag le5 = bki3.getTagElement("BlockEntityTag");
        final CompoundTag le6 = (le5 == null) ? new CompoundTag() : le5.copy();
        le6.putInt("Base", ((BannerItem)bki3.getItem()).getColor().getId());
        bki4.addTagElement("BlockEntityTag", le6);
        return bki4;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.SHIELD_DECORATION;
    }
}
