API users cannot add alchemy or conjuration recipes if an infusion recipe exists for that item.
CplPibald opened this issue · 7 comments
This issue affects mods using the Botania API, under the following conditions:
- The mod wants to add an infusion recipe using either the alchemy or conjuration catalysts.
- Botania already defines a mana infusion recipe for that item.
The issue is that the new recipe will never be called, even when a pool has the correct type of catalyst.
Detailed Explanation
When an item is thrown into a mana pool, the pool iterates over the list of recipes and stops when the following conditions are met.
if(recipe.matches(stack) && (recipe.getCatalyst() == null || worldObj.getBlockState(pos.down()) == recipe.getCatalyst()))
In particular, if a recipe that doesn't need a catalyst is encountered for that item, the search will stop and that recipe will be used. Botania gets around this problem by adding all alchemy and conjuration recipes first, and infusion (no catalyst) recipes last, guaranteeing that the more specific recipe will be found first when appropriate.
The design intent seems to be that when a catalyst is present, that catalyst's recipes should take precedence. (For example, redstone dust which has all three recipes). Unfortunately, when a mod calls registerManaAlchemyRecipe
or registerManaConjurationRecipe
, the new recipe is added to the end of the BotaniaAPI.manaInfusionRecipes
list, meaning its recipes are always searched last.
Possible solutions:
-
When adding recipes via the API, add to the front of the
manaInfusionRecipes
list if the recipe requires a catalyst, and add to the back if it doesn't. -
Change the logic to always iterate the whole list searching for catalyst-specific recipes before settling on a non-catalyst recipe. The logic above is in both TilePool.java and HUDHandler.java
-
Split
BotaniaAPI.manaInfusionRecipes
into multiple lists, and iterate them separately in order when finding recipes.
Workarounds
-
A mod can ensure its
preInit()
gets called before Botania's so its recipes are added earlier. -
A mod can directly manipulate the
manaInfusionRecipes
ArrayList instead of calling the API functions.
Also, damn, how did I miss that ._.
Because it's a really obscure bug and I'm possibly the first person ever to be affected by it. No worries, you're not a dev until you've shipped a few bugs. :-)
No, i mean I tested with all kinds of things that the new system worked but somehow missed glow/redstone
You won't see this problem with glowstone/redstone because Botania adds all of its own alchemy/conjuration recipes first before any infusion recipes. See CommonProxy::init(). This only happens with addons that call the API after Botania has initialized.
Ah. Fair enough, my tests in that regard were not exhaustive
On Fri, May 20, 2016 at 2:04 PM CplPibald [email protected] wrote:
You won't see this problem with glowstone/redstone because Botania adds
all of its own alchemy/conjuration recipes first before any infusion
recipes. See CommonProxy::init()
https://github.com/williewillus/Botania/blob/MC19/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java#L126.
This only happens with addons that call the API after Botania has
initialized.—
You are receiving this because you commented.Reply to this email directly or view it on GitHub
#291 (comment)
Will probably go with #2
Thanks for the super detailed report!