Entity Modification

Place to get help with not working mods / modding interface.
User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Entity Modification

Post 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
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.

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Entity Modification

Post 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: Image
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post by DiegoPro77 »

Thank you for the suggestion.
_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.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Entity Modification

Post by bobingabout »

So that example, data.raw["container"]["iron-chest"] rather than data.raw.entity["iron-chest"]
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post by DiegoPro77 »

Yeah i know now how to do it :D, 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.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post 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)
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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Entity Modification

Post 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

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post 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?
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.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Entity Modification

Post 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.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Entity Modification

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post 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 :lol: , 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
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.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Entity Modification

Post 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 :lol: , 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:

Code: Select all

  local name = ore_name .. "-dust"
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
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post 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
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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Entity Modification

Post 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
Last edited by darkfrei on Wed Sep 05, 2018 10:32 am, edited 1 time in total.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Entity Modification

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post by DiegoPro77 »

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.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post 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
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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Entity Modification

Post 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.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post by DiegoPro77 »

Not items as ores and Ore Patches, i mean items as plates.
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.

User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 167
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Entity Modification

Post 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... :x ):
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
Problem.png (38.74 KiB) Viewed 4586 times
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.

Post Reply

Return to “Modding help”