Search in sources :

Example 1 with Ingredient

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

the class CompoundIngredient method getStackingIds.

@Override
@Nonnull
public IntList getStackingIds() {
    boolean childrenNeedInvalidation = false;
    for (Ingredient child : children) {
        childrenNeedInvalidation |= child.checkInvalidation();
    }
    if (childrenNeedInvalidation || this.itemIds == null || checkInvalidation()) {
        this.markValid();
        this.itemIds = new IntArrayList();
        for (Ingredient child : children) this.itemIds.addAll(child.getStackingIds());
        this.itemIds.sort(IntComparators.NATURAL_COMPARATOR);
    }
    return this.itemIds;
}
Also used : Ingredient(net.minecraft.world.item.crafting.Ingredient) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) Nonnull(javax.annotation.Nonnull)

Example 2 with Ingredient

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

the class ForgeRecipeProvider method enhance.

private FinishedRecipe enhance(ShapedRecipeBuilder.Result vanilla) {
    Map<Character, Ingredient> ingredients = getField(ShapedRecipeBuilder.Result.class, vanilla, 5);
    boolean modified = false;
    for (Character x : ingredients.keySet()) {
        Ingredient ing = enhance(vanilla.getId(), ingredients.get(x));
        if (ing != null) {
            ingredients.put(x, ing);
            modified = true;
        }
    }
    return modified ? vanilla : null;
}
Also used : Ingredient(net.minecraft.world.item.crafting.Ingredient) ShapedRecipeBuilder(net.minecraft.data.recipes.ShapedRecipeBuilder)

Example 3 with Ingredient

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

the class ForgeRecipeProvider method enhance.

private FinishedRecipe enhance(ShapelessRecipeBuilder.Result vanilla) {
    List<Ingredient> ingredients = getField(ShapelessRecipeBuilder.Result.class, vanilla, 4);
    boolean modified = false;
    for (int x = 0; x < ingredients.size(); x++) {
        Ingredient ing = enhance(vanilla.getId(), ingredients.get(x));
        if (ing != null) {
            ingredients.set(x, ing);
            modified = true;
        }
    }
    return modified ? vanilla : null;
}
Also used : Ingredient(net.minecraft.world.item.crafting.Ingredient) ShapelessRecipeBuilder(net.minecraft.data.recipes.ShapelessRecipeBuilder)

Example 4 with Ingredient

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

the class CraftingHelper method getIngredient.

public static Ingredient getIngredient(JsonElement json) {
    if (json == null || json.isJsonNull())
        throw new JsonSyntaxException("Json cannot be null");
    if (json.isJsonArray()) {
        List<Ingredient> ingredients = Lists.newArrayList();
        List<Ingredient> vanilla = Lists.newArrayList();
        json.getAsJsonArray().forEach((ele) -> {
            Ingredient ing = CraftingHelper.getIngredient(ele);
            if (// Vanilla, Due to how we read it splits each itemstack, so we pull out to re-merge later
            ing.getClass() == Ingredient.class)
                vanilla.add(ing);
            else
                ingredients.add(ing);
        });
        if (!vanilla.isEmpty())
            ingredients.add(Ingredient.merge(vanilla));
        if (ingredients.size() == 0)
            throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
        if (ingredients.size() == 1)
            return ingredients.get(0);
        return new CompoundIngredient(ingredients);
    }
    if (!json.isJsonObject())
        throw new JsonSyntaxException("Expcted ingredient to be a object or array of objects");
    JsonObject obj = (JsonObject) json;
    String type = GsonHelper.getAsString(obj, "type", "minecraft:item");
    if (type.isEmpty())
        throw new JsonSyntaxException("Ingredient type can not be an empty string");
    IIngredientSerializer<?> serializer = ingredients.get(new ResourceLocation(type));
    if (serializer == null)
        throw new JsonSyntaxException("Unknown ingredient type: " + type);
    return serializer.parse(obj);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Ingredient(net.minecraft.world.item.crafting.Ingredient) ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject)

Example 5 with Ingredient

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

the class CompoundIngredient method getItems.

@Override
@Nonnull
public ItemStack[] getItems() {
    if (stacks == null) {
        List<ItemStack> tmp = Lists.newArrayList();
        for (Ingredient child : children) Collections.addAll(tmp, child.getItems());
        stacks = tmp.toArray(new ItemStack[tmp.size()]);
    }
    return stacks;
}
Also used : Ingredient(net.minecraft.world.item.crafting.Ingredient) ItemStack(net.minecraft.world.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

Ingredient (net.minecraft.world.item.crafting.Ingredient)5 Nonnull (javax.annotation.Nonnull)2 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 ShapedRecipeBuilder (net.minecraft.data.recipes.ShapedRecipeBuilder)1 ShapelessRecipeBuilder (net.minecraft.data.recipes.ShapelessRecipeBuilder)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ItemStack (net.minecraft.world.item.ItemStack)1