package net.minecraft.client.gui.screens.recipebook;

import net.minecraft.world.item.ItemStack;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.world.entity.player.StackedContents;
import java.util.Iterator;
import net.minecraft.stats.RecipeBook;
import com.google.common.collect.Sets;
import com.google.common.collect.Lists;
import java.util.Set;
import net.minecraft.world.item.crafting.Recipe;
import java.util.List;

public class RecipeCollection {
    private final List<Recipe<?>> recipes;
    private final Set<Recipe<?>> craftable;
    private final Set<Recipe<?>> fitsDimensions;
    private final Set<Recipe<?>> known;
    private boolean singleResultItem;
    
    public RecipeCollection() {
        this.recipes = Lists.newArrayList();
        this.craftable = Sets.newHashSet();
        this.fitsDimensions = Sets.newHashSet();
        this.known = Sets.newHashSet();
        this.singleResultItem = true;
    }
    
    public boolean hasKnownRecipes() {
        return !this.known.isEmpty();
    }
    
    public void updateKnownRecipes(final RecipeBook aco) {
        for (final Recipe<?> bmu4 : this.recipes) {
            if (aco.contains(bmu4)) {
                this.known.add(bmu4);
            }
        }
    }
    
    public void canCraft(final StackedContents bee, final int integer2, final int integer3, final RecipeBook aco) {
        for (int integer4 = 0; integer4 < this.recipes.size(); ++integer4) {
            final Recipe<?> bmu7 = this.recipes.get(integer4);
            final boolean boolean8 = bmu7.canCraftInDimensions(integer2, integer3) && aco.contains(bmu7);
            if (boolean8) {
                this.fitsDimensions.add(bmu7);
            }
            else {
                this.fitsDimensions.remove(bmu7);
            }
            if (boolean8 && bee.canCraft(bmu7, null)) {
                this.craftable.add(bmu7);
            }
            else {
                this.craftable.remove(bmu7);
            }
        }
    }
    
    public boolean isCraftable(final Recipe<?> bmu) {
        return this.craftable.contains(bmu);
    }
    
    public boolean hasCraftable() {
        return !this.craftable.isEmpty();
    }
    
    public boolean hasFitting() {
        return !this.fitsDimensions.isEmpty();
    }
    
    public List<Recipe<?>> getRecipes() {
        return this.recipes;
    }
    
    public List<Recipe<?>> getRecipes(final boolean boolean1) {
        final List<Recipe<?>> list3 = Lists.newArrayList();
        final Set<Recipe<?>> set4 = boolean1 ? this.craftable : this.fitsDimensions;
        for (final Recipe<?> bmu6 : this.recipes) {
            if (set4.contains(bmu6)) {
                list3.add(bmu6);
            }
        }
        return list3;
    }
    
    public List<Recipe<?>> getDisplayRecipes(final boolean boolean1) {
        final List<Recipe<?>> list3 = Lists.newArrayList();
        for (final Recipe<?> bmu5 : this.recipes) {
            if (this.fitsDimensions.contains(bmu5) && this.craftable.contains(bmu5) == boolean1) {
                list3.add(bmu5);
            }
        }
        return list3;
    }
    
    public void add(final Recipe<?> bmu) {
        this.recipes.add(bmu);
        if (this.singleResultItem) {
            final ItemStack bki3 = this.recipes.get(0).getResultItem();
            final ItemStack bki4 = bmu.getResultItem();
            this.singleResultItem = (ItemStack.isSame(bki3, bki4) && ItemStack.tagMatches(bki3, bki4));
        }
    }
    
    public boolean hasSingleResultItem() {
        return this.singleResultItem;
    }
}
