Multi-Product Recipe Details

by KvaNTy

Lists all product names in recipe description if there are more than one product in the recipe.

Utilities
4 years ago
0.16 - 1.1
13.2K

b Unknown key: "item-name.wooden-chest"

6 years ago

Hi, thanks for making this great mod! It looks like you aren't properly getting the localized name for items that correspond to entities and equipment. For instance, the localized name for wooden-chest is actually "entity-name.wooden-chest". The localized name for battery-equipment is actually "equipment-name.battery-equipment". I think testing for place_result and placed_as_equipment_result should be adequate.

6 years ago

Unknown key: "item-name.wooden-chest"
Same, most recipes lack a name and description.

6 years ago

Oh, Hi. Can you explain what exactly is the issue and how you are able to reproduce it?

6 years ago
(updated 6 years ago)

Alright, I figured out that you were talking about Deadlock's Crafting Machine and it's uncrating recipes.

Items and entities have literally identical definitions in game files. Game somehow sorts out this localization uncertainty later in runtime, but I see no way to determine whether something is an item or an entity during gameload. Though since it is a rare issue, keeping a simple list of known items which are actually entities should solve the problem. So far seems to fix everything related to Deadlock's mods and wooden crates.

Also I think I've fixed the issue with equipment type items, but I have no idea which mods have such recipes, so I can't test it yet.

6 years ago
(updated 6 years ago)

Items that correspond to entities have a property called "place_result". For example:

{
type = "item",
name = "wooden-chest",
icon = "base/graphics/icons/wooden-chest.png",
icon_size = 32,
subgroup = "storage",
order = "a[items]-a[wooden-chest]",
place_result = "wooden-chest", <-- This line makes "wooden-chest" an entity
stack_size = 50
},

Here's the code I'm using in my mod to get the correct item names:

local get_item_name=function(item)
if item.localised_name then
return item.localised_name
elseif item.place_result then
return {"entity-name." .. item.place_result}
elseif item.placed_as_equipment_result then
return {"equipment-name." .. item.placed_as_equipment_result}
else
return {"item-name." .. item.name}
end
end

EDITED: Changed {"entity-name." .. item.name} to {"entity-name." .. item.place_result} because item.name might be different than item.place_result

6 years ago

Ah, I see now. I was wondering what "place_result" means. That's actually very convenient. Thank you!
So do you know any mod that has such equipment items in multi-product recipes?

6 years ago
(updated 6 years ago)

Just make a dummy recipe inside data.lua like this:

data:extend { --Periods added for formatting
....{
........type = "recipe",
........name = "item-name-test",
........icon = "base/graphics/icons/uranium-processing.png",
........icon_size = 32,
........subgroup = "raw-material",
........category = "crafting-with-fluid",
........enabled = true,
........ingredients =
........{
........},
........results =
........{
............{type="item", name="iron-plate", amount=1},
............{type="item", name="wooden-chest", amount=1},
............{type="item", name="solar-panel-equipment", amount=1},
............{type="item", name="rail", amount=1},
............{type="item", name="water-barrel", amount=1},
............{type="fluid", name="water", amount=100},
........}
....},
}

I got your mod to work using this function. It takes the product from format_line() and works for both items and fluids.

local get_product_name=function(product) --Periods added for formatting
....if product.type=="fluid" then
........local fluid=data.raw["fluid"][product.name]
........if fluid then
............if fluid.localised_name then
................return fluid.localised_name
............end
........end
........return {"fluid-name." .. product.name}
....else
........local item=data.raw["item"][product.name]
........if item then
............if item.localised_name then
................return item.localised_name
............elseif item.place_result then
................return {"entity-name." .. item.place_result}
............elseif item.placed_as_equipment_result then
................return {"equipment-name." .. item.placed_as_equipment_result}
............end
........end
........return {"item-name." .. product.name}
....end
end

EDIT: Whoops! I forgot that fluids can have localized names too. The code should be correct now

6 years ago

Damn! I found another problem with my code. Not all items live in data.raw["item"]. For example, "automation-science-pack" lives in data.raw["tool"]. I think you'll have to search every data.raw subtable that can contain items. Try this code:

local item=data.raw["item"][product.name]
if not item then
....local item_types={
........"ammo",
........"capsule",
........"gun",
........"item-with-entity-data",
........"item-with-label",
........"item-with-inventory",
........"blueprint-book",
........"item-with-tags",
........"selection-tool",
........"blueprint",
........"copy-paste-tool",
........"deconstruction-item",
........"upgrade-item",
........"module",
........"rail-planner",
........"tool",
........"armor",
........"mining-tool",
........"repair-tool",
....}
....for _,item_type in pairs(item_types) do
........item=data.raw[item_type][product.name]
........if item then
............break
........end
....end
end

6 years ago

Yea, dummy recipe does the job too. I didn't know barrels had dynamic definitions.
I think accounting for recipes to contain every theoretically possible kind of items would be just impractical generalization for the sake of generalization, or rather solving a problem that does not exist. I appreciate the effort tho.

Anyhow, everything seems to work nicely and update is up there.
Again thanks for your help.

New response