Entity Migration

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Entity Migration

Post by Ranakastrasz »

I am trying to replace the "stone" doodad entity with a tree entity, so that it can be picked up with robots, mined, show it's loot, hardness, etc, etc.

However, while I made the new prototype, I cannot set the old one to nil, since it causes an error. I cannot name the new one "stone" as well, as it causes another error, and it claims to create a collision rather than overriding it since the type is different. As a result, it ended up named "stone2".

I looked over the migration script guide, but it doesn't clearly state how to override one entity with another one.
I was then going to search for all matching entities and replace them, but I cannot find a filter with no area argument.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Entity Migration

Post by Ranakastrasz »

Code: Select all

for _, surface in ipairs(game.surfaces) do
    for _, entity in ipairs(game.surface.find_entities_filtered{
        area={{-1000000, -1000000},
            {1000000, 1000000}},
            name="stone-rock"})
    do
        surface.create_entity{name = "stone-rock-2", position = entity.position, direction = defines.direction.north}
        entity.destroy()
    end
end

My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Rseding91
Factorio Staff
Factorio Staff
Posts: 15882
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Entity Migration

Post by Rseding91 »

https://forums.factorio.com/wiki/inde ... on_scripts

The entity migration part at the bottom.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Entity Migration

Post by Ranakastrasz »

Will that actually work? I thought that only applied if you were renaming something of the same type.

Will check.

Code: Select all

{
 "entity":
 [
  ["stone-rock", "stone-rock-2"],
 ]
}
That did not work
My Prototype definition file

Code: Select all

--data.raw["simple-entity"]["stone-rock"] = nil
data.raw["simple-entity"]["stone-rock"].autoplace = nil
data:extend(
{
  {
    type = "tree",
    name = "stone-rock-2",
    flags = {"placeable-neutral", "placeable-off-grid", "not-on-map"},
    minable =
    {
      count = 25,
      hardness = 0.8,
      mining_particle = "stone-particle",
      mining_time = 5,
      result = "stone"
    },
    icon = "__base__/graphics/icons/stone-rock.png",
    subgroup = "grass",
    order = "b[decorative]-k[stone-rock]-a[big]",
    collision_box = {{-1.1, -1.1}, {1.1, 1.1}},
    selection_box = {{-1.3, -1.3}, {1.3, 1.3}},
    render_layer = "object",
    max_health = 200,
    resistances =
    {
      {
        type = "fire",
        percent = 100
      }
    },
    autoplace =
    {
      order = "a[doodad]-a[rock]",
      peaks =
      {
        {
          influence = 0.0002
        },
        {
          influence = 0.002;
          min_influence = 0,
          elevation_optimal = 30000,
          elevation_range = 23000,
          elevation_max_range = 30000,
        }
      }
    },
    pictures =
    {
      {
        filename = "__base__/graphics/entity/decorative/stone-rock/stone-rock-01.png",
        width = 76,
        height = 60,
        shift = {0.1, 0}
      },
      {
        filename = "__base__/graphics/entity/decorative/stone-rock/stone-rock-02.png",
        width = 83,
        height = 86,
        shift = {0.2, 0}
      },
      {
        filename = "__base__/graphics/entity/decorative/stone-rock/stone-rock-03.png",
        width = 126,
        height = 98,
        shift = {0.7, 0}
      },
      {
        filename = "__base__/graphics/entity/decorative/stone-rock/stone-rock-04.png",
        width = 92,
        height = 108,
        shift = {0.1, 0}
      },
      {
        filename = "__base__/graphics/entity/decorative/stone-rock/stone-rock-05.png",
        width = 140,
        height = 99,
        shift = {0.5, 0}
      }
    }
  }
})
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Rseding91
Factorio Staff
Factorio Staff
Posts: 15882
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Entity Migration

Post by Rseding91 »

You have to put the migration file in the correct location and yes it does work to migrate entity types (chest -> assembling machine) and so on.

It goes in the folder migrations and can have any name normally with the extension: json
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”