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

Rewrite recipe chain calculator #530

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Meegooo
Copy link

@Meegooo Meegooo commented Sep 15, 2024

Rewrote recipe chain calculator. The main difference is that it now uses graph traversal to calculate things. Fixes GTNewHorizons/GT-New-Horizons-Modpack#17148

Notable features:

  • Support for "ore dictionary" (but really for multiple ingredients per slot)
  • Ability to request negative amount of items to indicate that you already have some.
  • Proper handling of recipes with multiple outputs and recursive recipes (with some caveats)

There are some differences in how it looks and feels. Here are new behaviors.

  1. Modifying item counts

    • Ctrl+scroll works only on recipe outputs and increases requested amount of only that item by 1. Fluids are increased by whatever one cell contains, or, if there is no cell, by whatever container holds the max amount. I don't like how the method looks (StackInfo::getFluidCellSize), but could not find a better approach.
    • Ctrl+Shift+Scroll works on any ingredient of the recipe and increases amount of requested items by whatever one craft gives you. This is notably different from how it was before, which was "increase number of requested items by one craft worth for the very last recipe in the chain". I decided to not reimplement this because of potential ambiguity, and because you can simply scroll on the recipe that you actually want.
    • Alt adds a multiplier that is equal to number under NEI item list on the bottom right.
  2. Visual

    • The number of requested items is shown in the top right corner as +123/-123. This is not required to be a multiple of whatever the recipe output is. Previously it would just change number of items individually.
    • With shift held, top rights shows number of craft operations in the top right for the whole chain as x123. Background highlights behave the same way.
    • Shift how highlights group that your cursor is next to. You don't need to put you mouse over an itemstack. Tooltips were annoying.
    • Bottom right shows however many items will be consumed/produced by however many craft iterations were calculated.
  3. Behavioral and implementation details.

    • Pinning item without ingredients will sum requested ingredients from other recipes.
    • Pressing Shift+A on an output stack in a NEI recipe pins all output stacks, not just the one you hovered over. I want opinions on that one. Changed it to be consistent with doing the same thing over plus sign. And in general, I don't like how you can only remove ingredients and outputs from pinned recipe, but adding them back is practically impossible. I have no idea how to fix it though.
    • Amount of requested items is completely separate from pinned stack size that is shown. This means that toggling crafting mode will result in zeroed out item stack sizes. This also means that pinning item counts along with ingredients (Ctrl+Shift+A vs Shift+A) has no actual difference for this functionality.
    • If there are multiple recipes that give the same output, code will choose the first one it encounters that has ingredients pinned. If nothing has ingredients pinned, it will chose the first one with
    • Graph traversal continues for an ingredient only if that ingredient is pinned as both input, and output in other recipe.
    • Recipes are still serialized and stored as BookmarkRecipeId. I extract actual recipes at runtime.
    • Mapping from original ItemStack to calculated ItemStack is done via indexes. Previously it was done as a mapping from ItemStack to ItemStack.

Some screenshots:
image
image
image
image

@Dream-Master Dream-Master requested review from slprime and a team September 15, 2024 10:37
@Meegooo Meegooo force-pushed the recipe_chain_refactor branch 2 times, most recently from bdf0c69 to 0146a73 Compare September 15, 2024 11:59
@Meegooo Meegooo marked this pull request as ready for review September 15, 2024 12:02
@slprime
Copy link
Member

slprime commented Sep 15, 2024

ctrl+shift+scroll don't scroll full recipe, only item under mouse. (work only ctrl+scroll)
image

why used second recipe? has ingredients pinned what you meen?
image

Recipe from first group scrolled too
Minecraft1 7 102024-09-1521-13-08-ezgif com-video-to-gif-converter

Alt adds a multiplier that is equal to number under NEI item list on the bottom right.

Don't work correctly. The value must be a multiple of 64 (in my example) but have 65

before after
image image

I'm not sure there is a need for a negative main recipe. I often use shift+ctrl+alt+scroll to reset the recipe.
image

Shift in fluid show how many it is by detail (29kL=29000=....) But if use negative value i don't know how many fluids I've specified. For items same problem

Positive Negative
image image

The ingredient "Magnesiumchloride Dust" is a catalyst in this recipe group, it should not be in the ingredients and remainders. The display of circuits is also questionable

Recipe Tooltip
image image

Same problem. Results have 72 chips but should have 64

Recipe Tooltip
image image

2 different recipes form "Cryogenic Freezer" and "Vacuum Freezer", but only one of them scrolls.
image

Recipe Group

  1. oil -> "Sulfuric Light Fuel"
  2. "Sulfuric Light Fuel" -> "Light Fuel"
  3. "Light Fuel" -> "Lightly Steam-Cracked Light Fuel"
  4. "Lightly Steam-Cracked Light Fuel" -> Ethylene

Chain brocken because fluid in cell (it will work fine before)

Recipe shift
image image

"Sulfuric Light Fuel" and "Light Fuel" highlight like it is in results/remainders, but it isn't

Recipe Tooltip
image image

Previously, the highlight was more informative. Using shift showed how many items were left

Before Now
image image

That's enough for now

@Meegooo
Copy link
Author

Meegooo commented Sep 16, 2024

ctrl+shift+scroll don't scroll full recipe, only item under mouse. (work only ctrl+scroll)

Here you have crafting chain mode disabled. Did it use to do that on shift+ctrl+scroll?

why used second recipe?
2 different recipes form "Cryogenic Freezer" and "Vacuum Freezer", but only one of them scrolls.

It uses whatever recipe it encounters first. I should probably make it more consistent, because currently to the user it feels random because of hashmap. And maybe color conflicting recipe in gray or something. But functionally, I don't see a way to support multiple recipes that give the same output. If there is a recipe that you need pinned, but that you don't wanna use for some item, you can unpin output from that recipe.

has ingredients pinned what you meen?

If you unpin an ingredient from the recipe, then graph traversal won't continue, even if that recipe is pinned. For example, iron is not pinned in hopper recipe, so iron is not calculated.
image
That filtering required extra (annoying) code. So i'm happy to remove that and always continue through for all ingredients.

Recipe from first group scrolled too

Oops, forgot to filter by group id.

Don't work correctly. The value must be a multiple of 64 (in my example) but have 65
I'm not sure there is a need for a negative main recipe. I often use shift+ctrl+alt+scroll to reset the recipe.

Cause currently it adds/removes 64 or whatever multiple you have set. But now that I think about it, forcing it to be a multiple would be nicer. Noted.
Adding shift would increase/decrease number of crafting operations, not reuqested items. So, for 6 slabs from 3 planks it would scroll to -320, 0, 320, 640, 960, etc.

Chain brocken because fluid in cell (it will work fine before)

You mean it should treat cells as raw fluids? Makes sense, noted.

The ingredient "Magnesiumchloride Dust" is a catalyst in this recipe group, it should not be in the ingredients and remainders. The display of circuits is also questionable
Same problem. Results have 72 chips but should have 64

That is by design. It is a catalyst that is unused, but it is required for the craft. They were cancelling each other in first implementation, but after some playtesting I found out that it was not very helpful. In general, this tries to mimic the way AE2 autocrafting works. And that's how it would see it.
As for circuits, not showing ingredients with stack size of 0 would solve it.

"Sulfuric Light Fuel" and "Light Fuel" highlight like it is in results/remainders, but it isn't

That's actually Lightly Steam-Cracked fuel in the remainders. Ethylene requires 19000L and cracking recipe will produce 19200. That is a problem I had with the tooltip, because you often can't tell what ingredient/results/remainders are shown, because a lot of them look very similar
Sulfuric acid is also in the remainders. You did not explicitly request it (you requested only Ethylene), but it was produced as a byproduct of converting sulfuric fuel to normal fuel. Now, if you Ctrl+scroll up on it twice, it will be considered something you requested and will move from remainders to results.

Using shift showed how many items were left

You mean showing outputs+remainders as a stack size for outputs? Okay, previously I couldn't exactly figure out what that was.

Shift in fluid show how many it is by detail (29kL=29000=....) But if use negative value i don't know how many fluids I've specified. For items same problem.

Do you know where that is calculated? There is no reason it shouldn't work, other than explicitly checking for stack size to be greater than 0.

@slprime
Copy link
Member

slprime commented Sep 16, 2024

Here you have crafting chain mode disabled. Did it use to do that on shift+ctrl+scroll?

Previously, the algorithm worked the same whether the chain was enabled or not

It uses whatever recipe it encounters first. I should probably make it more consistent, because currently to the user it feels random because of hashmap. And maybe color conflicting recipe in gray or something. But functionally, I don't see a way to support multiple recipes that give the same output. If there is a recipe that you need pinned, but that you don't wanna use for some item, you can unpin output from that recipe.

Here it would be correct to change the quantity on the recipe you are on.
How will it behave if it is an intermediate recipe? will i be able to specify how many recipes should go on one path and how many on the other or will i have to create several groups?

Adding shift would increase/decrease number of crafting operations, not reuqested items. So, for 6 slabs from 3 planks it would scroll to -320, 0, 320, 640, 960, etc.

How to reset group state? Why do you need a negative value in the final recipe?

You mean it should treat cells as raw fluids? Makes sense, noted.

yes, it will work fine before

That is by design. It is a catalyst that is unused, but it is required for the craft. They were cancelling each other in first implementation, but after some playtesting I found out that it was not very helpful. In general, this tries to mimic the way AE2 autocrafting works. And that's how it would see it.

This will mislead the player into crafting a catalyst in quantities he doesn't need. they are no different from a circuit in situations like this. The only thing you can do is to output it as an ingredient in the amount of one item. Otherwise the player will again have to filter out unnecessary things in tooltips/highlights

That's actually Lightly Steam-Cracked fuel in the remainders. Ethylene requires 19000L and cracking recipe will produce 19200. That is a problem I had with the tooltip, because you often can't tell what ingredient/results/remainders are shown, because a lot of them look very similar

correctly: Ethylene requires 18800L and cracking recipe will produce 19000.
Previously, by holding down the shift key, I could clearly understand what I would have left and at what stage, now I have to look for inputs and outputs for item/fluid and subtract one number from another.

Do you know where that is calculated? There is no reason it shouldn't work, other than explicitly checking for stack size to be greater than 0.

GuiContainerManager.itemCountDetails

@Meegooo
Copy link
Author

Meegooo commented Sep 16, 2024

Notes to self, to not forget anything

  • Make output conflict resolution predictable (always pick the topmost recipe)
  • Forbid changing request amount for conflicting recipe
  • Color conflicting recipe in red and show tooltip with hint (only when shift is held, to reduce noise)
  • Allow using conflicting recipes as passive ingredient providers.
  • Stop changing request count with Ctrl+Shift+Scroll for same recipe in another group
  • Make scrolling consistent between regular mode and crafting mode.
    • Ctrl+Scroll - change requests/stack size by 1 (or once cell worth for fluids) for only selected item (for crafting mode, only output items)
    • Ctrl+Shift+Scroll - change requests/stack size by meta.factor for all items in selected recipe (for crafting mode, only output items, inputs will be calculated)
    • Alt - adds an extra modifier.
    • Final count sticks to a multiple of final multiplier (meta.factor*alt_modifier or cell_size*alt_modifier or 1*alt_modifier, etc)
  • Make negative requests a config option (disable by default)
  • Add config option to remove unconsumed catalysts and common items from inputs and outputs+remainders (enabled by default). Decided against adding a config option for now.
    • reduce fluids in different containers as well. Not necessary anymore.
  • Add number of requested items to tooltip (to know exact amount when it gets compressed to K/M/G)
  • Show remainder amount on pinned itemstacks while holding shift
  • Pulling items for selected group doesn't work (works as intended and as it was before, did not realize there were differences in behavior between selecting a group and not selecting).
  • Support fluids in cells as raw fluid
  • If a recipe produces more than one stack of item (i.e. 64 + 6 of cryolite dust), 64 gets pinned as a regular bookmark, and recipe calculator thinks one craft produces 6. This is an issue in current version when adding recipe from the "plus" sign. I'll fix it here because now this code is used by all recipe pins. However there is another issue with duping recipes (i.e. null catalyst) in that this recipe can't be pinned, because input and output contain the same item. This I would rather fix separately, because this PR is large enough.

@slprime slprime marked this pull request as draft September 17, 2024 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Item counts in NEI pinned recipe chains are buggy
2 participants