Java Code Examples for net.minecraft.item.crafting.Ingredient#deserialize()

The following examples show how to use net.minecraft.item.crafting.Ingredient#deserialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChoppingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public ChoppingRecipe read(ResourceLocation recipeId, JsonObject json)
{
    String group = JSONUtils.getString(json, "group", "");
    JsonElement jsonelement = JSONUtils.isJsonArray(json, "ingredient")
            ? JSONUtils.getJsonArray(json, "ingredient")
            : JSONUtils.getJsonObject(json, "ingredient");
    Ingredient ingredient = Ingredient.deserialize(jsonelement);
    String s1 = JSONUtils.getString(json, "result");
    ResourceLocation resourcelocation = new ResourceLocation(s1);
    ItemStack itemstack = new ItemStack(Optional.ofNullable(ForgeRegistries.ITEMS.getValue(resourcelocation)).orElseThrow(() -> new IllegalStateException("Item: " + s1 + " does not exist")));
    double outputMultiplier = JSONUtils.getFloat(json, "output_multiplier", 1.0f);
    double hitCountMultiplier = JSONUtils.getFloat(json, "hit_count_multiplier", 1.0f);
    int maxOutput = JSONUtils.getInt(json, "max_output", 0);
    int sawingTime = JSONUtils.getInt(json, "sawing_time", 200);
    return new ChoppingRecipe(recipeId, group, ingredient, itemstack, outputMultiplier, hitCountMultiplier, maxOutput, sawingTime);
}
 
Example 2
Source File: ReColourRecipe.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public ReColourRecipe read(ResourceLocation recipeId, JsonObject json) {
    String group = JSONUtils.getString(json, "group", "");
    ItemStack result = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result"));
    Ingredient ingredient;
    JsonElement ing = json.get("ingredient");
    if (ing != null) {
        ingredient = Ingredient.deserialize(ing);
    } else {
        ingredient = Ingredient.fromStacks(result);
    }

    return new ReColourRecipe(recipeId, group, result, ingredient);
}
 
Example 3
Source File: DryingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public DryingRecipe read(ResourceLocation recipeId, JsonObject json)
{
    String group = JSONUtils.getString(json, "group", "");
    JsonElement jsonelement = JSONUtils.isJsonArray(json, "ingredient")
            ? JSONUtils.getJsonArray(json, "ingredient")
            : JSONUtils.getJsonObject(json, "ingredient");
    Ingredient ingredient = Ingredient.deserialize(jsonelement);
    String s1 = JSONUtils.getString(json, "result");
    ResourceLocation resourcelocation = new ResourceLocation(s1);
    ItemStack itemstack = new ItemStack(Optional.ofNullable(ForgeRegistries.ITEMS.getValue(resourcelocation)).orElseThrow(() -> new IllegalStateException("Item: " + s1 + " does not exist")));
    int dryingTime = JSONUtils.getInt(json, "dryingTime", 200);
    return new DryingRecipe(recipeId, group, ingredient, itemstack, dryingTime);
}