Entity Modification
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Entity Modification
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
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Entity Modification
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: 

I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
Thank you for the suggestion.
_DiegoPro77
_DiegoPro77
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Entity Modification
So that example, data.raw["container"]["iron-chest"] rather than data.raw.entity["iron-chest"]
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
Yeah i know now how to do it
, thank you already

Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
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)
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)
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Entity Modification
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
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
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?
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?
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Entity Modification
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 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.
Code: Select all
string.format('%s-oxigen-%s', result_item, ore_name)
edit: oh and you'd want data:extend{...} not just the table, that way it actually gets created and added.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Entity Modification
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:
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.
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
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.
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
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

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
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Entity Modification
my code is wrong anyway, I've been spending too much time looking at the game's source, which is C++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
the second line should be:
Code: Select all
local name = ore_name .. "-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
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
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
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
_DiegoPro77
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Entity Modification
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
Last edited by darkfrei on Wed Sep 05, 2018 10:32 am, edited 1 time in total.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Entity Modification
Yes. Or as darkfrei suggested if you're doing it for multiple types, do a loop within a loop.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
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
What an interesting thing, i'll try it in FactorioPlus Refining. Thank you for all.
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
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
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
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Entity Modification
You can get whole list of resource items: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
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
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
Not items as ores and Ore Patches, i mean items as plates.
Sorry, my bad.
Sorry, my bad.
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Entity Modification
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...
):
Could you help me please?
_DiegoPro77

in 0.17 Factorio gives me this error: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
Could you help me please?
_DiegoPro77
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.