Search in sources :

Example 1 with ItemValue

use of net.minecraft.world.item.crafting.Ingredient.ItemValue in project MinecraftForge by MinecraftForge.

the class ForgeRecipeProvider method enhance.

private Ingredient enhance(ResourceLocation name, Ingredient vanilla) {
    if (excludes.contains(name))
        return null;
    boolean modified = false;
    List<Value> items = new ArrayList<>();
    // This will probably crash between versions, if null fix index
    Value[] vanillaItems = getField(Ingredient.class, vanilla, 2);
    for (Value entry : vanillaItems) {
        if (entry instanceof ItemValue) {
            ItemStack stack = entry.getItems().stream().findFirst().orElse(ItemStack.EMPTY);
            Tag<Item> replacement = replacements.get(stack.getItem());
            if (replacement != null) {
                items.add(new TagValue(replacement));
                modified = true;
            } else
                items.add(entry);
        } else
            items.add(entry);
    }
    return modified ? Ingredient.fromValues(items.stream()) : null;
}
Also used : Item(net.minecraft.world.item.Item) ItemValue(net.minecraft.world.item.crafting.Ingredient.ItemValue) TagValue(net.minecraft.world.item.crafting.Ingredient.TagValue) ItemValue(net.minecraft.world.item.crafting.Ingredient.ItemValue) Value(net.minecraft.world.item.crafting.Ingredient.Value) ItemStack(net.minecraft.world.item.ItemStack) TagValue(net.minecraft.world.item.crafting.Ingredient.TagValue)

Aggregations

Item (net.minecraft.world.item.Item)1 ItemStack (net.minecraft.world.item.ItemStack)1 ItemValue (net.minecraft.world.item.crafting.Ingredient.ItemValue)1 TagValue (net.minecraft.world.item.crafting.Ingredient.TagValue)1 Value (net.minecraft.world.item.crafting.Ingredient.Value)1