Example usage for net.minecraftforge.common.crafting CraftingHelper getIngredient

List of usage examples for net.minecraftforge.common.crafting CraftingHelper getIngredient

Introduction

In this page you can find the example usage for net.minecraftforge.common.crafting CraftingHelper getIngredient.

Prototype

public static Ingredient getIngredient(ResourceLocation type, PacketBuffer buffer) 

Source Link

Usage

From source file:blusunrize.immersiveengineering.common.crafting.RecipeFactoryIEItemRepair.java

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    Ingredient ingred = CraftingHelper.getIngredient(json.get("tool"), context);
    return new RecipeIEItemRepair(ingred);
}

From source file:blusunrize.immersiveengineering.common.crafting.RecipeFactoryShapedIngredient.java

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    String group = JsonUtils.getString(json, "group", "");

    Map<Character, Ingredient> ingMap = Maps.newHashMap();
    for (Entry<String, JsonElement> entry : JsonUtils.getJsonObject(json, "key").entrySet()) {
        if (entry.getKey().length() != 1)
            throw new JsonSyntaxException("Invalid key entry: '" + entry.getKey()
                    + "' is an invalid symbol (must be 1 character only).");
        if (" ".equals(entry.getKey()))
            throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");

        ingMap.put(entry.getKey().toCharArray()[0], CraftingHelper.getIngredient(entry.getValue(), context));
    }/*from  w  w  w.  ja va2  s  .  c o  m*/

    ingMap.put(' ', Ingredient.EMPTY);

    JsonArray patternJ = JsonUtils.getJsonArray(json, "pattern");

    if (patternJ.size() == 0)
        throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");

    String[] pattern = new String[patternJ.size()];
    for (int x = 0; x < pattern.length; ++x) {
        String line = JsonUtils.getString(patternJ.get(x), "pattern[" + x + "]");
        if (x > 0 && pattern[0].length() != line.length())
            throw new JsonSyntaxException("Invalid pattern: each row must  be the same width");
        pattern[x] = line;
    }

    ShapedPrimer primer = new ShapedPrimer();
    primer.width = pattern[0].length();
    primer.height = pattern.length;
    primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
    primer.input = NonNullList.withSize(primer.width * primer.height, Ingredient.EMPTY);

    Set<Character> keys = Sets.newHashSet(ingMap.keySet());
    keys.remove(' ');

    int x = 0;
    for (String line : pattern)
        for (char chr : line.toCharArray()) {
            Ingredient ing = ingMap.get(chr);
            if (ing == null)
                throw new JsonSyntaxException(
                        "Pattern references symbol '" + chr + "' but it's not defined in the key");
            primer.input.set(x++, ing);
            keys.remove(chr);
        }

    if (!keys.isEmpty())
        throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + keys);

    ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
    RecipeShapedIngredient recipe = new RecipeShapedIngredient(
            group.isEmpty() ? null : new ResourceLocation(group), result, primer);

    if (JsonUtils.getBoolean(json, "quarter_turn", false))
        recipe.allowQuarterTurn();
    if (JsonUtils.getBoolean(json, "eighth_turn", false))
        recipe.allowEighthTurn();
    if (JsonUtils.hasField(json, "copy_nbt")) {
        if (JsonUtils.isJsonArray(json, "copy_nbt")) {
            JsonArray jArray = JsonUtils.getJsonArray(json, "copy_nbt");
            int[] array = new int[jArray.size()];
            for (int i = 0; i < array.length; i++)
                array[i] = jArray.get(i).getAsInt();
            recipe.setNBTCopyTargetRecipe(array);
        } else
            recipe.setNBTCopyTargetRecipe(JsonUtils.getInt(json, "copy_nbt"));
        if (JsonUtils.hasField(json, "copy_nbt_predicate"))
            recipe.setNBTCopyPredicate(JsonUtils.getString(json, "copy_nbt_predicate"));
    }
    return recipe;
}

From source file:blusunrize.immersiveengineering.common.crafting.RecipeFactoryShapelessIngredient.java

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    String group = JsonUtils.getString(json, "group", "");

    NonNullList<Ingredient> ings = NonNullList.create();
    for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients"))
        ings.add(CraftingHelper.getIngredient(ele, context));

    if (ings.isEmpty())
        throw new JsonParseException("No ingredients for shapeless recipe");

    ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
    RecipeShapelessIngredient recipe = new RecipeShapelessIngredient(
            group.isEmpty() ? null : new ResourceLocation(group), result, ings);

    if (JsonUtils.hasField(json, "damage_tool"))
        recipe.setToolDamageRecipe(JsonUtils.getInt(json, "damage_tool"));
    if (JsonUtils.hasField(json, "copy_nbt"))
        recipe.setNBTCopyTargetRecipe(JsonUtils.getInt(json, "copy_nbt"));

    return recipe;
}