Using 6c4885edb32f230641ffa61e9a5f729616cfae49 + unrelated local changes:
Trying to make a vehicle welding rig, which requires 2 makeshift welders as ingredients, and a welding source (e.g. charged makeshift welder) as tool.
If I have:
a) a charged UPS-mod makeshift welder and 2 additional uncharged makeshift welders: tool requirement is satisfied, ingredient requirement is brown.
b) a charged UPS-mod makeshift welder and _3_ additional uncharged makeshift welders: everything is green
c) 1 charged non-UPS makeshift welder and 2 additional uncharged makeshift welders: everything is green
Case (a) should work too.
What I usually do is put the conflicting component somewhere out of sight for a second while I craft with the components I want to use. I have to do this all the time with wheels on vehicles, sometimes it just picks a random size wheel and so I put all wheels for the vehicle under my feet or closer and it works fine.
The problem here is not picking the wrong item, it is that an extra item
(not consumed, doesn't satisfy the tool requirements) is required before
crafting can start
Have you tried to craft the item with only 2 regular makeshift welders? No additional welders should be needed for the craft. The only problem I can see happening is that the check for the 2 makeshift welders counted the ups-modded one when it shouldn't have. (I'm not sure if the crafting checks for all makeshift welders or if it just tags the first two in your inventory, the former obviously being the better check)
If you are saying that the recipe requires 3 makeshift welders, then it would be a trivial bug to fix.
Have you tried to craft the item with only 2 regular makeshift welders?
That should fail: you do not have a welding source separate from the ingredients.
This is _probably_ (I haven't entirely worked through it) because the "tool is also a component" test in requirement_data::check_enough_materials fires and requires 3 makeshift welders to be available; but then item_comp::has fails to count the charged UPS welder (used as a tool) because it has a toolmod installed and item::allow_crafting_component returns false.
The underlying problem here is that there are three classes of item involved:
1) Matches the tool requirement, does not match the component requirement
2) Does not matches the tool requirement, does match the component requirement
3) Matches both the tool requirement and the component requirement
The current code assumes that if the same item type is needed as both a component and a tool, then it must be case (3) and therefore you need an extra item to handle the separate tool. However, in the situation described in this issue, it is actually case (1) because a modified item cannot be used in crafting; the modified tool that satisfies the tool requirement is not counted as an available component.
To fix that it looks like we need to have requirement_data::check_enough_materials test the inventory more explicitly, looking at each item in isolation rather than trying to combine tool and component counts after the fact:
foreach (item) {
if (it is a tool) {
if (it is also a component) { ++shared_tools }
else { ++unshared_tools }
}
else if (it is a component) { ++components }
}
test for (unshared_tools + shared_tools) >= required tools
if (unshared_tools == 0) { --shared_tools } // one tool-or-component is needed as the tool
test for (components + shared_tools) >= required components
From #19200:
I have a makeshift welder recharged through a medium storage battery, two discharged makeshift welders and I am not able to craft the vehicle welding rig. The makeshift welder for the welding is marked as green, but the two needed for the crafting are brown.
I do not know if it could be related to this problem, but having a soldering iron recharged with storage batteries gives problem when trying to repair things. The system says that there are not enough charges.
and
I came across this issue as well, crafted 2 makeshift welders, went to craft vehicle welding rig. Not enough makeshift welders. Drop one, tried again and all was fine. Hopefully that gives a useful hint to the problem.
have three makeshift welders (two usual, one battery compartment), all of them charged enough, still can't do it
after disassembling the battery compartment one and assembling it as a regular one it works
I reproduced this with:
The recipe was disabled and I couldn't pick it.
You can work around it by making three makeshift welders for components and it will enable the recipe.
I got 2 empty makeshift welders and 1 fully charged makeshift welder modded with battery compartment mod.


Most helpful comment
The underlying problem here is that there are three classes of item involved:
1) Matches the tool requirement, does not match the component requirement
2) Does not matches the tool requirement, does match the component requirement
3) Matches both the tool requirement and the component requirement
The current code assumes that if the same item type is needed as both a component and a tool, then it must be case (3) and therefore you need an extra item to handle the separate tool. However, in the situation described in this issue, it is actually case (1) because a modified item cannot be used in crafting; the modified tool that satisfies the tool requirement is not counted as an available component.
To fix that it looks like we need to have requirement_data::check_enough_materials test the inventory more explicitly, looking at each item in isolation rather than trying to combine tool and component counts after the fact: