Mekanism API - Can't add recipe
trabpukcip opened this issue ยท 8 comments
Issue description:
Can't add Mekanism recipes using Mekanism API. Crashes at startup complaining that the recipes are not being added in init (despite them actually being added in init).
Steps to reproduce:
- Make a very basic single class mod.
- Add Mekanism and Mekanism API to you mods libs folder and import them to your build path.
- Add a recipe such as
MekanismAPI.recipeHelper().addEnrichmentChamberRecipe(new ItemStack(Blocks.END_STONE, 1), new ItemStack(Items.BEEF, 4));
to your mods init.
Version (make sure you are on the latest version before reporting):
Forge: 14.23.2.2611
Mekanism: 9.4.3.330 + API
If a (crash)log is relevant for this issue, link it here: (It's almost always relevant)
crash-2018-04-22_14.27.20-client.txt
Notes:
Test Mod Repo: https://github.com/trabpukcip/Trab-Test-Mod
Works fine using the RecipeHandler class from Mekanism itself. That of course defeats the purpose of using the API though ๐
Also I could just be doing something derpy...
Message is incorrect, register recipes before init. The Recipe registry event is your last chance.
I have tried previously to put the statement into preInit (crashes because too early). I have now has a crack at doing the same thing with the recipe registry event and it still crashes: https://github.com/trabpukcip/Trab-Test-Mod/blob/master/src/main/java/org/icannt/trabtestmod/RecipeRegistry.java
After looking at this statement in mekanism.api.MekanismRecipeHelper is have come to the conclusion that the logic is plain screwed. This:
Preconditions.checkState(Loader.instance().getLoaderState().ordinal() > LoaderState.INITIALIZATION.ordinal(), "Recipes should be registered during Init.");
Should be this:
Preconditions.checkState(Loader.instance().getLoaderState().ordinal() <= LoaderState.INITIALIZATION.ordinal(), "Recipes should be registered during Init.");
So that it throws the error in the right spot i.e. PostInit.
That statement as is would error at Init AND PreInit at any point no matter what I do.
This used for testing that theory:
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
try {
Preconditions.checkState(Loader.instance().getLoaderState().ordinal() > LoaderState.INITIALIZATION.ordinal(), "Recipes should be registered during Init.");
} catch (Exception e1) {
LOG.error("Exception thrown at " + Loader.instance().getLoaderState());
}
}
@EventHandler
public void init(FMLInitializationEvent event) {
try {
Preconditions.checkState(Loader.instance().getLoaderState().ordinal() > LoaderState.INITIALIZATION.ordinal(), "Recipes should be registered during Init.");
} catch (Exception e1) {
LOG.error("Exception thrown at " + Loader.instance().getLoaderState());
}
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
try {
Preconditions.checkState(Loader.instance().getLoaderState().ordinal() > LoaderState.INITIALIZATION.ordinal(), "Recipes should be registered during Init.");
} catch (Exception e1) {
LOG.error("Exception thrown at " + Loader.instance().getLoaderState());
}
}
Sure enough:
[07:18:03] [main/ERROR] [Trab Test Mod]: Exception thrown at PREINITIALIZATION
[07:18:15] [main/ERROR] [Trab Test Mod]: Exception thrown at INITIALIZATION
Please fix?
@thiakil Still having issues with this, the problem with the logic statement really is that IRecipe is the only registry event that I could find that shows up as init. I updated my test repo logging when this thing fires and also compare it to the updated logic statement.
[12:06:53] [main/INFO] [Trab Test Mod]: FML Event PREINITIALIZATION
[12:06:54] [main/INFO] [Trab Test Mod]: Registry Event 0, Block; FML Event PREINITIALIZATION
[12:06:57] [main/INFO] [Trab Test Mod]: Registry Event 1, Item; FML Event PREINITIALIZATION
[12:06:57] [main/INFO] [Trab Test Mod]: Registry Event 2, Biome; FML Event PREINITIALIZATION
[12:06:57] [main/INFO] [Trab Test Mod]: Registry Event 3, Enchantment; FML Event PREINITIALIZATION
[12:06:57] [main/INFO] [Trab Test Mod]: Registry Event 4, EntityEntry; FML Event PREINITIALIZATION
[12:06:57] [main/INFO] [Trab Test Mod]: Registry Event 5, Potion; FML Event PREINITIALIZATION
[12:06:57] [main/INFO] [Trab Test Mod]: Registry Event 6, SoundEvent; FML Event PREINITIALIZATION
[12:06:57] [main/INFO] [Trab Test Mod]: Registry Event 7, VillagerProfession; FML Event PREINITIALIZATION
[12:07:08] [main/INFO] [Trab Test Mod]: Registry Event 8, IRecipe; FML Event INITIALIZATION
[12:07:08] [main/ERROR] [Trab Test Mod]: Exception thrown at registry event IRecipe, FML Event INITIALIZATION
[12:07:08] [main/INFO] [Trab Test Mod]: FML Event INITIALIZATION
[12:07:08] [main/ERROR] [Trab Test Mod]: Exception thrown at FML Event INITIALIZATION
[12:07:08] [main/INFO] [Trab Test Mod]: FML Event POSTINITIALIZATION
[12:07:08] [main/ERROR] [Trab Test Mod]: Exception thrown at FML Event POSTINITIALIZATION
You can see that IRecipe indeed does fire before init, but it reports as init! This is unlike the other registry events which load after actual preinit as you would expect and report as preinit. I don't have a suggestion on how to fix this myself.
Well it does work if you load your recipe at the VillagerProfession event.
@SubscribeEvent
public static void registerVillagerProfession(final RegistryEvent.Register<VillagerProfession> event)
{
MekanismAPI.recipeHelper().addEnrichmentChamberRecipe(new ItemStack(Blocks.END_STONE, 1), new ItemStack(Items.BEEF, 4));
}
This is kinda hacky obviously, the logic check needs to be more granular.