NPE when calling recipes.getRecipesFor(IIngredient)
codetaylor opened this issue ยท 5 comments
Issue Description:
NPE when calling recipes.getRecipesFor(IIngredient);
What happens:
NPE when calling recipes.getRecipesFor(IIngredient);
It looks like MCRecipeManager.recipes
is first initialized here, but isn't that after scripts are compiled and run here?
What you expected to happen:
No NPE
Script used (Please Pastebin or gist your script, posting an unpasted or ungist'd script will automatically close this issue):
recipes.getRecipesFor(<minecraft:furnace>);
Minetweaker.log file (Please Pastebin or gist your file, posting an unpasted or ungist'd file will automatically close this issue):
Affected Versions (Do not use "latest"):
- Minecraft: 1.12.2
- Forge: 1.12.2-14.23.0.2546
- Crafttweaker: 1.12-4.1.4.426
It's only initialized there because that's when CrT actually modifies the recipes.
I'm not sure whether initialising the recipe earlier would work since probably many recipes wouldn't yet be in there.
I suggest you'd do the same as we do and postpone the execution of the script using a list that stores the calls to be executed later.
Also, did I actually @ZenAnnotate that method?
It's annotated in the interface:
/**
* Returns all crafting recipes resulting in the given ingredient.
*
* @param ingredient ingredient to find
*
* @return crafting recipes for the given item(s)
*/
@ZenMethod
List<ICraftingRecipe> getRecipesFor(IIngredient ingredient);
I suggest you'd do the same as we do and postpone the execution of the script using a list that stores the calls to be executed later.
I already do that, aggregate IAction objects for recipe additions / removals and apply them at the appropriate time. I'm not sure how I could delay the call to recipes.getRecipesFor(IIngredient);
or delay the execution of the script.
This is my use case:
import mods.artisanworktables.Worktable;
recipes.remove(<minecraft:furnace>);
val builder = Worktable.createRecipeBuilder("basic");
for recipe in recipes.getRecipesFor(<minecraft:furnace>) {
builder
.copyRecipe(recipe)
.addTool(<ore:artisansHammer>, 1)
.addOutput(<minecraft:diamond>)
.create();
}
Maybe I'm missing something, but I don't understand the purpose of these methods, specifically recipes.getRecipesFor(IIngredient)
and recipes.all
, if they throw a NPE when called in a script outside of a delayed or postponed context.
Should they only be used inside of delayed actions?