Page 1 of 2
Entity Modification
Posted: Thu Aug 30, 2018 12:12 pm
by DiegoPro77
I usually use the command data.raw for edit things: how can i do it with entities? 'Cause it doesn't work if i write data.raw.entity
Re: Entity Modification
Posted: Thu Aug 30, 2018 12:58 pm
by Bilka
Use the type of the entity, for example "container" for the chests. You can find the type of vanilla entities and items on the wiki in the infobox:

Re: Entity Modification
Posted: Thu Aug 30, 2018 7:23 pm
by DiegoPro77
Thank you for the suggestion.
_DiegoPro77
Re: Entity Modification
Posted: Fri Aug 31, 2018 8:19 am
by bobingabout
So that example, data.raw["container"]["iron-chest"] rather than data.raw.entity["iron-chest"]
Re: Entity Modification
Posted: Fri Aug 31, 2018 11:01 am
by DiegoPro77
Yeah i know now how to do it

, thank you already
Re: Entity Modification
Posted: Fri Aug 31, 2018 11:08 am
by DiegoPro77
Ah another question: i'm implementing ore's duplication, triplication...ex, so i need always to add the same recipe for every ore: is there a faster way to do it?
Ex. One of the processing i've already implemented is this:
Ore (ex iron, but it could be any other ore) ==> Crusher ==> Dust (of that specific ore)
Re: Entity Modification
Posted: Fri Aug 31, 2018 12:10 pm
by darkfrei
DiegoPro77 wrote:Ah another question: i'm implementing ore's duplication, triplication...ex, so i need always to add the same recipe for every ore: is there a faster way to do it?
Ex. One of the processing i've already implemented is this:
Ore (ex iron, but it could be any other ore) ==> Crusher ==> Dust (of that specific ore)
Code: Select all
for i, ore_name in pairs ({"i-ore", "c-ore", "d-ore"}) do
-- your code here
end
Re: Entity Modification
Posted: Sun Sep 02, 2018 1:39 pm
by DiegoPro77
So if i need to create the same recipe for some ores, i'll need to write something like this:
for i, ore_name in pairs ({"i-ore", "c-ore", "d-ore"}) do
{
type = "recipe", category = "enriching",
name = "(What here?)",
enabled = "true",
energy_requied = 3,
ingredients =
{
{"(What here?)", 1},
{type="fluid", name="oxigen", amount= 150},
},
result = "(What here?)",
result_count = 3
}
end
but what i must put in name and ingredients?
Re: Entity Modification
Posted: Sun Sep 02, 2018 2:00 pm
by FreeER
well you should already know the result since you're duplicating recipes to produce something with different ore types, the ingredients of course will be a table of
ore_name plus whatever other ingredients the recipe would use and the name would probably be something like
Code: Select all
string.format('%s-oxigen-%s', result_item, ore_name)
to generate something like 'iron-plate-oxigen-iron-ore-dust'
edit: oh and you'd want data:extend{...} not just the table, that way it actually gets created and added.
Re: Entity Modification
Posted: Mon Sep 03, 2018 8:26 am
by bobingabout
note: It's spelled Oxygen, with a Y, not an I.
if you know the name up front like that, it might not be best to include -ore on the end... because:
iron-ore-dust vs iron-dust, it depends what you're after.
Either way... you probably want something like this:
Code: Select all
for i, ore_name in pairs ({"i-ore", "c-ore", "d-ore"}) do
local name = ore_name + "-dust"
data:extend({
{
type = "recipe", category = "enriching",
name = name,
enabled = "true",
energy_requied = 3,
ingredients =
{
{ore_name, 1},
{type="fluid", name="oxigen", amount= 150},
},
results = {name, 3},
}
})
end
Results from this function will create recipes for i-ore-dust, c-ore-dust and d-ore-dust, but not their items.
If you want to drop the -ore from the end, you can do more string manipulation to find it and remove it, but that's a little more advanced for something off the top of my head.
Re: Entity Modification
Posted: Mon Sep 03, 2018 10:04 am
by DiegoPro77
I know, i've left it wrong in the program only 'cause it was late and i haven't wanted to correct that

, but in the locale i've corrected it.
And thank you for the string of program. Probably i'll resolve the thing with iron_ore_dust in the locale file, after all the important thing is what is showed in the game interface, isn't it?
_DiegoPro77
Re: Entity Modification
Posted: Tue Sep 04, 2018 8:57 am
by bobingabout
DiegoPro77 wrote:I know, i've left it wrong in the program only 'cause it was late and i haven't wanted to correct that

, but in the locale i've corrected it.
And thank you for the string of program. Probably i'll resolve the thing with iron_ore_dust in the locale file, after all the important thing is what is showed in the game interface, isn't it?
_DiegoPro77
my code is wrong anyway, I've been spending too much time looking at the game's source, which is C++
the second line should be:
however, if you actually want iron-ore to become iron-dust...
https://www.lua.org/manual/2.4/node22.html
something I just put together without testing... replace the line with the following block
Code: Select all
local name = ore_name .. "-dust"
local len = strfind (ore_name, "-ore")
if len then
name = strsub (ore_name, 1, len) .. "-dust"
end
it will do the same as before, but then check if it contains "-ore", and if it does, take everything before that only.
stone -> stone-dust
iron-ore -> iron-dust
so all put together should look something like this.
Code: Select all
for i, ore_name in pairs ({"i-ore", "c-ore", "d-ore"}) do
local name = ore_name .. "-dust"
local len = strfind (ore_name, "-ore")
if len then
name = strsub (ore_name, 1, len) .. "-dust"
end
data:extend({
{
type = "recipe", category = "enriching",
name = name,
enabled = "true",
energy_requied = 3,
ingredients =
{
{ore_name, 1},
{type="fluid", name="oxigen", amount= 150},
},
results = {name, 3},
}
})
end
Re: Entity Modification
Posted: Tue Sep 04, 2018 10:30 am
by DiegoPro77
Thank you again for the code. So i can apply this string for ores, dusts, clumps… ex. i need only to change the local, don't i?
_DiegoPro77
Re: Entity Modification
Posted: Tue Sep 04, 2018 7:31 pm
by darkfrei
Some example for enriching chain:
Code: Select all
local ores = {"iron", "copper", "uranium"}
local recipe_chain = {"ore", "dust", "enriched", "deoxidized", "particle", "smelted", "plate"}
for i, ore_name in pairs (ores) do
for j = 2, #recipe_chain do
local name = ore_name .. "-" .. recipe_chain[j]
local ingredient_name = ore_name .. "-" .. recipe_chain[j-1]
data:extend({
{
type = "recipe", category = "enriching",
name = name,
enabled = "true",
energy_requied = 3,
ingredients =
{
{ingredient_name, 4}
},
results = {name, 3},
}
})
end
end
Re: Entity Modification
Posted: Wed Sep 05, 2018 8:24 am
by bobingabout
DiegoPro77 wrote:Thank you again for the code. So i can apply this string for ores, dusts, clumps… ex. i need only to change the local, don't i?
_DiegoPro77
Yes. Or as darkfrei suggested if you're doing it for multiple types, do a loop within a loop.
Re: Entity Modification
Posted: Wed Sep 05, 2018 9:39 am
by DiegoPro77
What an interesting thing, i'll try it in FactorioPlus Refining. Thank you for all.
Re: Entity Modification
Posted: Wed Jan 02, 2019 12:54 pm
by DiegoPro77
Ok, i've tested this method and it works perfectly for now. Could it be expanded to items?
Like this:
Iron and Copper Ores -- Already in the vanilla game.
Iron and Copper Dusts -- Create them only in one command. (like the previous recipes)
Iron and Copper Clumps -- Create them only in one command.
It could be very helpful for me to quickly add and remove items in the code, since i would like to apply this method for many ores.
Thank you already for the help.
_DiegoPro77
Re: Entity Modification
Posted: Wed Jan 02, 2019 1:44 pm
by darkfrei
DiegoPro77 wrote: Wed Jan 02, 2019 12:54 pm
Ok, i've tested this method and it works perfectly for now. Could it be expanded to items?
Like this:
Iron and Copper Ores -- Already in the vanilla game.
Iron and Copper Dusts -- Create them only in one command. (like the previous recipes)
Iron and Copper Clumps -- Create them only in one command.
It could be very helpful for me to quickly add and remove items in the code, since i would like to apply this method for many ores.
Thank you already for the help.
_DiegoPro77
You can get whole list of resource items:
Code: Select all
local resource_items_list = {}
for resource_name, resource in pairs (data.raw.resource) do
if resource.minable and resource.minable.result then
local item_name = resource.minable.result
table.insert (resource_items_list, item_name)
elseif resource.minable and resource.minable.results then
local results = resource.minable.results
-- here handler for multiple results
end
end
You can also add condition for checking if this item_name is not already in the list.
Re: Entity Modification
Posted: Fri Jan 04, 2019 1:00 pm
by DiegoPro77
Not items as ores and Ore Patches, i mean items as plates.
Sorry, my bad.
Re: Entity Modification
Posted: Tue Mar 12, 2019 9:14 pm
by DiegoPro77
Sorry, i was working on my new modpack project, and i've found a problem with this function: (will i ever resolve this mess once for all...

):
darkfrei wrote: Tue Sep 04, 2018 7:31 pm
Some example for enriching chain:
Code: Select all
local ores = {"iron", "copper", "uranium"}
local recipe_chain = {"ore", "dust", "enriched", "deoxidized", "particle", "smelted", "plate"}
for i, ore_name in pairs (ores) do
for j = 2, #recipe_chain do
local name = ore_name .. "-" .. recipe_chain[j]
local ingredient_name = ore_name .. "-" .. recipe_chain[j-1]
data:extend({
{
type = "recipe", category = "enriching",
name = name,
enabled = "true",
energy_requied = 3,
ingredients =
{
{ingredient_name, 4}
},
results = {name, 3},
}
})
end
end
in 0.17 Factorio gives me this error:

- Problem.png (38.74 KiB) Viewed 6123 times
Could you help me please?
_DiegoPro77