package net.minecraft.world.item.crafting;

import net.minecraft.world.Container;
import net.minecraft.world.item.Items;
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 MapCloningRecipe extends CustomRecipe {
    public MapCloningRecipe(final ResourceLocation uh) {
        super(uh);
    }
    
    @Override
    public boolean matches(final CraftingContainer bgu, final Level bqb) {
        int integer4 = 0;
        ItemStack bki5 = ItemStack.EMPTY;
        for (int integer5 = 0; integer5 < bgu.getContainerSize(); ++integer5) {
            final ItemStack bki6 = bgu.getItem(integer5);
            if (!bki6.isEmpty()) {
                if (bki6.getItem() == Items.FILLED_MAP) {
                    if (!bki5.isEmpty()) {
                        return false;
                    }
                    bki5 = bki6;
                }
                else {
                    if (bki6.getItem() != Items.MAP) {
                        return false;
                    }
                    ++integer4;
                }
            }
        }
        return !bki5.isEmpty() && integer4 > 0;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer bgu) {
        int integer3 = 0;
        ItemStack bki4 = ItemStack.EMPTY;
        for (int integer4 = 0; integer4 < bgu.getContainerSize(); ++integer4) {
            final ItemStack bki5 = bgu.getItem(integer4);
            if (!bki5.isEmpty()) {
                if (bki5.getItem() == Items.FILLED_MAP) {
                    if (!bki4.isEmpty()) {
                        return ItemStack.EMPTY;
                    }
                    bki4 = bki5;
                }
                else {
                    if (bki5.getItem() != Items.MAP) {
                        return ItemStack.EMPTY;
                    }
                    ++integer3;
                }
            }
        }
        if (bki4.isEmpty() || integer3 < 1) {
            return ItemStack.EMPTY;
        }
        final ItemStack bki6 = bki4.copy();
        bki6.setCount(integer3 + 1);
        return bki6;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 >= 3 && integer2 >= 3;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.MAP_CLONING;
    }
}
