Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recipe book #113

Merged
merged 5 commits into from
Aug 26, 2023
Merged

Recipe book #113

merged 5 commits into from
Aug 26, 2023

Conversation

melontini
Copy link
Contributor

@melontini melontini commented Aug 25, 2023

Hello, this PR is related to #103, but I completely changed the implementation due to a little issue.

I tested it with RBIP (Forge and Fabric) and it works correctly.

The patch is pretty simple, and I also added comments, but as a gist:

  • We reset RecipeBookCategories.AGGREGATE_CATEGORIES to vanilla values.
  • We inject at the TAIL of RecipeBookManager.init() to merge any categories that may have been added by fabric mods.
  • We set RecipeBookCategories.AGGREGATE_CATEGORIES to RecipeBookManager.AGGREGATE_CATEGORIES.

This should account for most additions. Everything else works as is.

@Su5eD Su5eD self-assigned this Aug 25, 2023
@Su5eD Su5eD added the enhancement New feature or request label Aug 25, 2023
@melontini
Copy link
Contributor Author

melontini commented Aug 25, 2023

Btw, since Forge's event doesn't support modifying existing categories (Unless you do this, lol), it might be better to just insert merged categories at their index.

Actually, it might be better to find the index of the previous group. Something like this:

            //Insert better code here.
            for (int i = 0; i < categories.size(); i++) {
                RecipeBookCategories c = categories.get(i);
                if (eventCategories.contains(c)) continue;

                int realIndex = i;
                if (i > 0) {
                    RecipeBookCategories prev = categories.get(i - 1);
                    int prevIndex = eventCategories.indexOf(prev);
                    if (prevIndex != -1) realIndex = prevIndex + 1;
                }

                if (realIndex >= eventCategories.size()) eventCategories.add(c);
                else eventCategories.add(realIndex, c);
            }

Copy link
Member

@Su5eD Su5eD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this and it works as expected. Just needs some minor style/structure changes, but otherwise it's good to go.

@Su5eD Su5eD linked an issue Aug 26, 2023 that may be closed by this pull request
@Su5eD Su5eD merged commit 0c41b24 into Sinytra:master Aug 26, 2023
1 check passed
@melontini melontini deleted the recipe-book branch August 27, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"The sins of the recipe book", or "how do you fix that damn thing?"
2 participants