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 sm) {
        super(sm);
    }
    
    @Override
    public boolean matches(final CraftingContainer baz, final Level bjw) {
        int integer4 = 0;
        ItemStack ben5 = ItemStack.EMPTY;
        for (int integer5 = 0; integer5 < baz.getContainerSize(); ++integer5) {
            final ItemStack ben6 = baz.getItem(integer5);
            if (!ben6.isEmpty()) {
                if (ben6.getItem() == Items.FILLED_MAP) {
                    if (!ben5.isEmpty()) {
                        return false;
                    }
                    ben5 = ben6;
                }
                else {
                    if (ben6.getItem() != Items.MAP) {
                        return false;
                    }
                    ++integer4;
                }
            }
        }
        return !ben5.isEmpty() && integer4 > 0;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer baz) {
        int integer3 = 0;
        ItemStack ben4 = ItemStack.EMPTY;
        for (int integer4 = 0; integer4 < baz.getContainerSize(); ++integer4) {
            final ItemStack ben5 = baz.getItem(integer4);
            if (!ben5.isEmpty()) {
                if (ben5.getItem() == Items.FILLED_MAP) {
                    if (!ben4.isEmpty()) {
                        return ItemStack.EMPTY;
                    }
                    ben4 = ben5;
                }
                else {
                    if (ben5.getItem() != Items.MAP) {
                        return ItemStack.EMPTY;
                    }
                    ++integer3;
                }
            }
        }
        if (ben4.isEmpty() || integer3 < 1) {
            return ItemStack.EMPTY;
        }
        final ItemStack ben6 = ben4.copy();
        ben6.setCount(integer3 + 1);
        return ben6;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 >= 3 && integer2 >= 3;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.MAP_CLONING;
    }
}
