avoid encoding hidden items in patterns #6463
Merged
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.
This PR implements an improvement for modpacks that care about unification and hide ingredients.
As an example, we can take the Crafting Table. It accepts any planks from the planks tag as ingredients. When encoding the recipe for it, it will use Oak Planks as input because that's the first entry in the planks tag. If you now hide Oak Planks in JEI/REI, it will no longer show up as an ingredient in the recipe.
When encoding patterns after hiding the Oak Planks using the
+
button, it will still use Oak Planks as inputs which makes no sense. Instead, it will now iterate through the tag until it finds the first visible stack and uses that instead. If there is no visible stack and all are hidden, it will use the previous behavior of using the first tag entry.Why would this be useful you may ask.
Think about several mods being installed besides AE2 and instead of the Crafting Table, think about a storage block like silver. 3 mods may add their own silver ingots but you only want one primary ingot to be available so you hide the others. To prevent encoding the hidden ingot as input and having to manually overwrite it, it will now use the visible item.
The change was implemented and tested in JEI and REI. While JEI exposes a method to check for visibility, REI is a bit trickier.
I used the same approach they use in their JEI compat layer and it works fine. For performance reasons, I decided to cache the visibility results. The visibility lookup is not that slow but it's better to cache it imo.
Caching it has only one downside. REI's hiding system works on the fly if you hide items within the in-game config menu and the item is instantly gone while it's still marked as visible in the cache. You will have to restart the world if you want to have the encoding work again but since this is only really interesting for a small number of packmakers, this should be fine.
Edit: the author of REI will expose a method for checking the item visibility in one of the next versions because the current way is not very handy