Identifying [non] entity prototypes during data stage

Place to get help with not working mods / modding interface.
sparr
Smart Inserter
Smart Inserter
Posts: 1521
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Identifying [non] entity prototypes during data stage

Post by sparr »

Code: Select all

local entity_types = { ["accumulator"] = true, ["arithmetic-combinator"] = true, ["artillery-flare"] = true, ["artillery-projectile"] = true, ["artillery-turret"] = true, ["artillery-wagon"] = true, ["assembling-machine"] = true, ["beacon"] = true, ["boiler"] = true, ["capsule"] = true, ["car"] = true, ["cargo-wagon"] = true, ["character-corpse"] = true, ["cliff"] = true, ["combat-robot"] = true, ["constant-combinator"] = true, ["construction-robot"] = true, ["container"] = true, ["corpse"] = true, ["decider-combinator"] = true, ["electric-pole"] = true, ["electric-turret"] = true, ["entity-ghost"] = true, ["explosion"] = true, ["fire"] = true, ["fish"] = true, ["flame-thrower-explosion"] = true, ["fluid-turret"] = true, ["fluid-wagon"] = true, ["flying-text"] = true, ["furnace"] = true, ["gate"] = true, ["generator"] = true, ["heat-pipe"] = true, ["inserter"] = true, ["lab"] = true, ["lamp"] = true, ["land-mine"] = true, ["loader"] = true, ["locomotive"] = true, ["logistic-container"] = true, ["logistic-robot"] = true, ["mining-drill"] = true, ["monolith"] = true, ["offshore-pump"] = true, ["pipe-to-ground"] = true, ["pipe"] = true, ["player-port"] = true, ["player"] = true, ["power-switch"] = true, ["programmable-speaker"] = true, ["projectile"] = true, ["pump"] = true, ["radar"] = true, ["rail-chain-signal"] = true, ["rail-remnants"] = true, ["rail-signal"] = true, ["reactor"] = true, ["roboport"] = true, ["rocket-silo"] = true, ["solar-panel"] = true, ["splitter"] = true, ["storage-tank"] = true, ["straight-rail"] = true, ["tile"] = true, ["transport-belt"] = true, ["turret"] = true, ["underground-belt"] = true, ["unit-spawner"] = true, ["unit"] = true, ["wall"] = true, }
I have this list in an old mod that I want to update. I am trying to avoid adding/removing from this long list by hand. Is there some way to tell during the data stage whether a prototype type (data.raw.FOO) contains entities or non-entities? Or to tell if a particular prototype is an entity or not?
sparr
Smart Inserter
Smart Inserter
Posts: 1521
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Identifying [non] entity prototypes during data stage

Post by sparr »

Use case: I have a mod for deleting arbitrary prototypes by name or type+name. It is meant to allow players to work around bugs and conflicts in other mods without knowing how to code or waiting for updates that might never come. When an entity prototype is deleted, any item that has place_result of that entity needs to have that field blanked, and that requires knowing which prototypes are entities.
robot256
Smart Inserter
Smart Inserter
Posts: 1322
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Identifying [non] entity prototypes during data stage

Post by robot256 »

You could just iterate through the list of items and look for ones where place_result is not nil, and also equal to your target name. Sure you would do a lot of searching if it wasn't an entity with a corresponding item, but that's okay since it only happens during load.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
sparr
Smart Inserter
Smart Inserter
Posts: 1521
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Identifying [non] entity prototypes during data stage

Post by sparr »

That would not work right when removing a non-entity prototype (like an item or technology) with the same name as an entity. For example, if I am removing data.raw.technology.foo, I do not want to eliminate the place_result of data.raw.item.foo which is "foo" . But if I am removing data.raw.someentitytype.foo then I do need to eliminate that place_result.
Post Reply

Return to “Modding help”