fix: guard IngredientStack against empty Ingredient.values (#12)#13
Merged
Dark-Arcana merged 3 commits intoJun 11, 2026
Merged
Conversation
SmashingMods#12) The main constructor read pIngredient.values[0] directly, assuming every Ingredient carries at least one value. NeoForge custom/compound ingredients (and the empty ingredient) leave the vanilla values[] array empty and expose their contents through getItems(), so decoding such a recipe at world creation threw ArrayIndexOutOfBoundsException and crashed the client. Resolve registryName via a new resolveRegistryName helper: keep the existing values[0] path when present, otherwise fall back to the first item the ingredient resolves to, and finally to the item registry default key (minecraft:air). Add regression tests for the empty-ingredient path.
…, never resolving items at decode time The previous fix for SmashingMods#12 stopped the ArrayIndexOutOfBoundsException but fell back to Ingredient.getItems()[0] when the values array is empty. Recipes are decoded during RecipeManager.apply, before registry tags are bound to that reload, so getItems() resolves tag-backed children to NeoForge's barrier "Empty Tag" placeholder stacks and memoizes that snapshot for the Ingredient's lifetime (barrier ghosts in JEI and the recipe selector). Worse, every unresolvable custom ingredient collapsed to the same fallback name (minecraft:barrier or minecraft:air), and with equality keyed on count plus that single name, recipes collecting inputs into a LinkedHashSet silently dropped any second custom-ingredient input. Never resolve items in the constructor. Instead key both registryName and the new identity field on what the Ingredient declares: - custom ingredient (Ingredient.isCustom()): stand-in name alchemylib:custom, identity = the ICustomIngredient itself. NeoForge mandates equals/hashCode on ICustomIngredient implementations (its own, like CompoundIngredient, are records); third-party customs that skip the contract degrade to instance identity, which still keeps separately decoded ingredients distinct. - no declared values (Ingredient.of()): stand-in name alchemylib:empty, empty identity. - declared values: identity = the whole sorted value set (tag locations and item registry names), registryName = the first value's location as before. equals/hashCode now compare count plus the full identity, which also brings the 1.21.4 whole-ingredient-identity fix (b06042f) to 1.21.1: two multi-item ingredients sharing only a first item are no longer equal. Keeps the existing empty-ingredient regression tests (the stand-in expectation replaces minecraft:air) and adds coverage for the custom-ingredient constructor path, custom and multi-item equality, and the LinkedHashSet input-drop regression.
…k identity The identity introduced in 1275a86 is a sorted list of bare declared locations, mixing tag locations and item registry names. A tag and an item may legally share a ResourceLocation, so Ingredient.of(#mymod:x) and Ingredient.of(mymod:x item) compared equal at equal counts -- reproducing, for that pair, the exact silent LinkedHashSet recipe-input merge the identity exists to prevent. Prefix each identity entry with its value kind: tag values become "tag:<location>", item values "item:<registry name>". The custom branch (identity = the ICustomIngredient itself) and registryName semantics are unchanged. Adds a regression test pinning that a tag-backed and an item-backed ingredient sharing minecraft:stone at equal counts are not equal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12 — a client crash (
ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0) when creating a new world.IngredientStack's main constructor readpIngredient.values[0]directly, assuming everyIngredientcarries at least one value. That holds for plain item/tag ingredients, but NeoForge custom/compound ingredients (and the empty ingredient) leave the vanillavalues[]array empty and expose their contents through
getItems()instead. When a recipe using such an ingredient is decoded during the resource reload at world creation,values[0]throws and takes down the client.Crash
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.smashingmods.alchemylib.api.item.IngredientStack.(IngredientStack.java:45)
...
at net.minecraft.world.item.crafting.RecipeManager.apply(RecipeManager.java:60)
Fix
registryNameis now derived through a newresolveRegistryName(Ingredient)helper:valuesnon-empty → unchanged behaviour (item value → item registry name, tag value → tag location).valuesempty → fall back to the first item the ingredient resolves to (getItems()[0]).minecraft:air).This keeps
registryNamenon-null (required byequals/hashCode) and preserves the existing happy-path semantics.Tests
constructor_emptyIngredient_doesNotThrow— direct regression on the AIOOBE.getRegistryName_emptyIngredient_isItemRegistryDefaultKey— empty ingredient resolves tominecraft:air../gradlew test --tests "*IngredientStackTest"→ green.