Guide-API

Guide-API

76M Downloads

[1.12] PageIRecipe.fromJson only seems to work on Vanilla recipes

The-Fireplace opened this issue ยท 4 comments

commented

I will resolve this one. After my issues with null pages, trying to track down the cause, it turns out the method used in fromJson only works for Vanilla recipes. Every Forge method I have found so far does the same. I am self-assigning this. I caused this issue, and I will fix it.

commented

Ok, after looking further into it, mod recipes are not loaded until after the book is built. Which means I will have to change when books are built to allow loading of PageIRecipes from json files.
EDIT: Cannot do that either. That would create and issue with book crafting recipes. Perhaps I can force-load mod recipes early.

commented

An alternative could be PageJsonRecipe which only stores the ResourceLocation and loads the IRecipe as needed. That would be a bit less performant though. Could loop through every book during FMLLoadCompleteEvent and find all the JSON recipe pages to construct the IRecipe's. A slightly longer loading period, but shouldn't be horrible.

Perhaps something like the following:

public class PageJsonRecipe extends PageIRecipe {

    private final ResourceLocation recipeId;

    public PageJsonRecipe(ResourceLocation recipeId) {
        super(null);
        
        this.recipeId = recipeId;
    }
    
    // Call from FMLLoadCompleteEvent
    public void init() {
        this.recipe = CraftingManager.getRecipe(recipeId);
        this.iRecipeRenderer = getRenderer(recipe);
    }
}
commented

Interesting. That sounds like a better idea than mine. I'll give it a shot.

commented

Also to note is that all recipes have a ResourceLocation, not just JSON ones. So this should work for all recipes.