It took me a little while to figure this out because there aren't really that many examples out there but thanks for getting me on correct path. Here is what I ended up doing.
JSON recipe:
{
"type": "pearlmod:shaped_enchanting_book_recipe",
"pattern":
[
"fbf",
" p "
],
"key":
{
"p":
{
"item": "minecraft:ender_pearl"
},
"b":
{
"item": "minecraft:book"
},
"f":
{
"item": "minecraft:feather"
}
},
"result":
{
"item": "minecraft:enchanted_book",
"enchantments":
[
{
"enchant": "minecraft:infinity",
"lvl": 1
}
]
}
}
Parse method on recipe factory:
@Override
public IRecipe parse(JsonContext context, JsonObject json)
{
ShapedOreRecipe recipe = ShapedOreRecipe.factory(context, json);
ItemStack output = recipe.getRecipeOutput();
final JsonObject result = JsonUtils.getJsonObject(json, "result");
final String item = JsonUtils.getString(result, "item");
assert item == "minecraft:enchanted_book";
final JsonArray enchantments = JsonUtils.getJsonArray(result, "enchantments");
for (JsonElement e : enchantments)
{
final String enchant = JsonUtils.getString(e.getAsJsonObject(), "enchant");
final int lvl = JsonUtils.getInt(e.getAsJsonObject(), "lvl");
EnchantmentData storedEnchant = new EnchantmentData(Enchantment.getEnchantmentByLocation(enchant), lvl);
ItemEnchantedBook.addEnchantment(output, storedEnchant);
}
ShapedPrimer primer = new ShapedPrimer();
primer.width = recipe.getRecipeWidth();
primer.height = recipe.getRecipeHeight();
primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
primer.input = recipe.func_192400_c();
return new ShapedEnchantingBookRecipe(new ResourceLocation(Constants.modid, "shaped_enchanting_book_recipe"), output, primer);
}
I'm not sure if there was a more effective way of parsing the JSON or not. I'm not familiar with teh goog's JSON library and I didn't find any quick examples so I just fudged this together quickly.
At any rate, this works. If anybody has a suggestion to make it better please contribute to the example.