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
Inconsistency with crafting replacements with multiple inputs #9250
Comments
MTG actually does have a replacement recipe in fuel recipe for bucket of lava. |
The intended behavior is that each replacement gets applied only once (so recipe 1 should have the same number of replacements as 3, and 2 should have the same numbers as 4) . If you want both cactuses to be replaced in recipe 1, you would use Here's the fix: diff --git a/src/craftdef.cpp b/src/craftdef.cpp
index 0181ceb6..07c3ebc0 100644
--- a/src/craftdef.cpp
+++ b/src/craftdef.cpp
@@ -229,6 +229,7 @@ static void craftDecrementOrReplaceInput(CraftInput &input,
rep.deSerialize(j->second, gamedef->idef());
item.remove(1);
found_replacement = true;
+ pairs.erase(j);
output_replacements.push_back(rep);
break; |
@pauloue Is there a reason you didn't submit that fix as a PR? This seems to still be an issue. |
I'll verify that it's correct and submit it when I get a chance, but until then anyone else can feel free to do so. |
@pauloue So? |
Replacements have been an issue for some time, especially with food crafts that need to return buckets for certain items or vessels for others e.g. the following recipe should return dirt for every sand used but it only ever returns one item unless a number is added to the replacements section:
|
@tenplus1, when I read the code I concluded that the intended behavior is that each replacement table specifies the replacement of a single input item, so that recipe should only replace the first sand. To replace all of them you need to use
This means it's possible to replace only one sand or replace some input sand with one item and other input sand with another item. |
it occurred to me recently that the "correct" way, as outlined here, prevents replacing a single item w/ multiple replacements, while the "wrong" way allows for that. |
Thank you. I actually discovered this myself when I started documenting crafting recipes, thanks for confirming. Bugfix PR: #12819 |
Minetest version
OS / Hardware
N/A
Summary
There is some inconsistency with crafting w/ the results of crafting recipes w/ replacements, and I don't know what the correct behaviour is. If a recipe lists a replacement, and there are multiple instances of the "source" item in the recipe, you will get a varying number of replacements, depending on various things.
Steps to reproduce
I noticed this behaviour while using unified_inventory (and sometimes unified_inventory_plus), but it works the same w/ the default inventory screen. Because there are no recipes w/ replacements in minetest_game, we'll have to add a mod w/ a few recipes for tests:
Note that recipes (1) and (2) demonstrate the issue; recipes (3) and (4) are just provided for reference. Also note that recipes that replace multiple different kinds of items behave like (3) and (4), as long as there is only a single instance of each "source" item in the recipe.
The real result of this behaviour, is that different mods seem to assume that the replacements in crafting recipes work differently; some have recipes like recipe (1), and some have recipes like (2). With recipes like (1), however, you don't always get the replacements you expected, and with (2), you can easily end up w/ many more replacements than you should get, which is technically an exploit.
My intuition, looking at this data, is that the code that is used to add replacements in the crafting grid after a craft only replaces a single instance of an item in a recipe, whereas the code that adds replacements to the player's inventory replaces all of them, and that the former should be made to behave like the latter. I'd like some input from people more familiar w/ the code and the intentions, though.
The text was updated successfully, but these errors were encountered: