package net.minecraft.world.item.crafting;

import net.minecraft.world.Container;
import java.util.Iterator;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import net.minecraft.world.item.MapItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;
import net.minecraft.resources.ResourceLocation;

public class MapExtendingRecipe extends ShapedRecipe {
    public MapExtendingRecipe(final ResourceLocation uh) {
        super(uh, "", 3, 3, NonNullList.<Ingredient>of(Ingredient.EMPTY, new Ingredient[] { Ingredient.of(Items.PAPER), Ingredient.of(Items.PAPER), Ingredient.of(Items.PAPER), Ingredient.of(Items.PAPER), Ingredient.of(Items.FILLED_MAP), Ingredient.of(Items.PAPER), Ingredient.of(Items.PAPER), Ingredient.of(Items.PAPER), Ingredient.of(Items.PAPER) }), new ItemStack(Items.MAP));
    }
    
    @Override
    public boolean matches(final CraftingContainer bgu, final Level bqb) {
        if (!super.matches(bgu, bqb)) {
            return false;
        }
        ItemStack bki4 = ItemStack.EMPTY;
        for (int integer5 = 0; integer5 < bgu.getContainerSize() && bki4.isEmpty(); ++integer5) {
            final ItemStack bki5 = bgu.getItem(integer5);
            if (bki5.getItem() == Items.FILLED_MAP) {
                bki4 = bki5;
            }
        }
        if (bki4.isEmpty()) {
            return false;
        }
        final MapItemSavedData czv5 = MapItem.getOrCreateSavedData(bki4, bqb);
        return czv5 != null && !this.isExplorationMap(czv5) && czv5.scale < 4;
    }
    
    private boolean isExplorationMap(final MapItemSavedData czv) {
        if (czv.decorations != null) {
            for (final MapDecoration czs4 : czv.decorations.values()) {
                if (czs4.getType() == MapDecoration.Type.MANSION || czs4.getType() == MapDecoration.Type.MONUMENT) {
                    return true;
                }
            }
        }
        return false;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer bgu) {
        ItemStack bki3 = ItemStack.EMPTY;
        for (int integer4 = 0; integer4 < bgu.getContainerSize() && bki3.isEmpty(); ++integer4) {
            final ItemStack bki4 = bgu.getItem(integer4);
            if (bki4.getItem() == Items.FILLED_MAP) {
                bki3 = bki4;
            }
        }
        bki3 = bki3.copy();
        bki3.setCount(1);
        bki3.getOrCreateTag().putInt("map_scale_direction", 1);
        return bki3;
    }
    
    @Override
    public boolean isSpecial() {
        return true;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.MAP_EXTENDING;
    }
}
