/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.ImmutableMap * com.google.common.collect.ImmutableMap$Builder * com.google.common.collect.ImmutableMultimap * com.google.common.collect.ImmutableMultimap$Builder * com.google.common.collect.Multimap * org.jspecify.annotations.Nullable */ package net.minecraft.world.item.crafting; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import java.util.Collection; import java.util.Map; import java.util.stream.Stream; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeInput; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import org.jspecify.annotations.Nullable; public class RecipeMap { public static final RecipeMap EMPTY = new RecipeMap((Multimap, RecipeHolder>)ImmutableMultimap.of(), Map.of()); private final Multimap, RecipeHolder> byType; private final Map>, RecipeHolder> byKey; private RecipeMap(Multimap, RecipeHolder> byType, Map>, RecipeHolder> byKey) { this.byType = byType; this.byKey = byKey; } public static RecipeMap create(Iterable> recipes) { ImmutableMultimap.Builder byType = ImmutableMultimap.builder(); ImmutableMap.Builder byKey = ImmutableMap.builder(); for (RecipeHolder recipe : recipes) { byType.put(recipe.value().getType(), recipe); byKey.put(recipe.id(), recipe); } return new RecipeMap((Multimap, RecipeHolder>)byType.build(), (Map>, RecipeHolder>)byKey.build()); } public > Collection> byType(RecipeType type) { return this.byType.get(type); } public Collection> values() { return this.byKey.values(); } public @Nullable RecipeHolder byKey(ResourceKey> recipeId) { return this.byKey.get(recipeId); } public > Stream> getRecipesFor(RecipeType type, I container, Level level) { if (container.isEmpty()) { return Stream.empty(); } return this.byType(type).stream().filter(r -> r.value().matches((RecipeInput)container, level)); } }