package net.minecraft.world.item.crafting; import java.util.ArrayList; import java.util.List; import java.util.Optional; import net.minecraft.core.Holder; import net.minecraft.world.entity.player.StackedContents; import net.minecraft.world.entity.player.StackedItemContents; import net.minecraft.world.item.Item; public class PlacementInfo { public static final PlacementInfo NOT_PLACEABLE = new PlacementInfo(List.of(), List.of(), List.of()); private final List ingredients; private final List>> unpackedIngredients; private final List> slotInfo; private PlacementInfo( List ingredients, List>> unpackedIngredients, List> slotInfo ) { this.ingredients = ingredients; this.unpackedIngredients = unpackedIngredients; this.slotInfo = slotInfo; } public static StackedContents.IngredientInfo> ingredientToContents(Ingredient ingredient) { return StackedItemContents.convertIngredientContents(ingredient.items().stream()); } public static PlacementInfo create(Ingredient ingredient) { if (ingredient.items().isEmpty()) { return NOT_PLACEABLE; } else { StackedContents.IngredientInfo> ingredientInfo = ingredientToContents(ingredient); PlacementInfo.SlotInfo slotInfo = new PlacementInfo.SlotInfo(0); return new PlacementInfo(List.of(ingredient), List.of(ingredientInfo), List.of(Optional.of(slotInfo))); } } public static PlacementInfo createFromOptionals(List> optionals) { int i = optionals.size(); List list = new ArrayList(i); List>> list2 = new ArrayList(i); List> list3 = new ArrayList(i); int j = 0; for (Optional optional : optionals) { if (optional.isPresent()) { Ingredient ingredient = (Ingredient)optional.get(); if (ingredient.items().isEmpty()) { return NOT_PLACEABLE; } list.add(ingredient); list2.add(ingredientToContents(ingredient)); list3.add(Optional.of(new PlacementInfo.SlotInfo(j++))); } else { list3.add(Optional.empty()); } } return new PlacementInfo(list, list2, list3); } public static PlacementInfo create(List ingredients) { int i = ingredients.size(); List>> list = new ArrayList(i); List> list2 = new ArrayList(i); for (int j = 0; j < i; j++) { Ingredient ingredient = (Ingredient)ingredients.get(j); if (ingredient.items().isEmpty()) { return NOT_PLACEABLE; } list.add(ingredientToContents(ingredient)); list2.add(Optional.of(new PlacementInfo.SlotInfo(j))); } return new PlacementInfo(ingredients, list, list2); } public List> slotInfo() { return this.slotInfo; } public List ingredients() { return this.ingredients; } public List>> unpackedIngredients() { return this.unpackedIngredients; } public boolean isImpossibleToPlace() { return this.slotInfo.isEmpty(); } public record SlotInfo(int placerOutputPosition) { } }