All item types, all entity types in data stage

Place to get help with not working mods / modding interface.
Post Reply
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

All item types, all entity types in data stage

Post by darkfrei »

Is here easy way to get all item types and entity types by the data stage?
Almost(?) all entity prototypes have collision boxes, but is it by them only?

Pi-C
Smart Inserter
Smart Inserter
Posts: 1656
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: All item types, all entity types in data stage

Post by Pi-C »

darkfrei wrote: ↑
Fri Jan 31, 2020 8:07 am
Is here easy way to get all item types and entity types by the data stage?
Almost(?) all entity prototypes have collision boxes, but is it by them only?
Do you mean the item/entity names? That could be done this way:

Code: Select all

local all = data.raw
log("Getting items:")
for _,item in pairs(all.item) do
    log(item.name)
end

log("Getting entities:")
for _,x in pairs(all) do
    for _, entity in pairs(x) do
        log(entity.name .. ":\t" .. entity.type)
    end
end
EDIT: Removed unnecessary calls of tostring(), they were a remnant of another test I did before.
Last edited by Pi-C on Fri Jan 31, 2020 9:24 am, edited 1 time in total.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: All item types, all entity types in data stage

Post by Honktown »

darkfrei wrote: ↑
Fri Jan 31, 2020 8:07 am
Is here easy way to get all item types and entity types by the data stage?
Almost(?) all entity prototypes have collision boxes, but is it by them only?
I would say anything which has stack_size constitutes an item (my stack changing mod has to search odd categories sometimes). Some of the "item" categories include capsules, modules... Logically, doing:
code
Should get you all the types of things which can be held in inventory:
result
For entities you have to be careful: explosions, acid splashes, arrow indicators are entities. There are strange things that are entities. For practical things, a checking for a collision box sounds good. Do it and see what you get.
I have mods! I guess!
Link

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: All item types, all entity types in data stage

Post by Honktown »

Pi-C wrote: ↑
Fri Jan 31, 2020 9:18 am
...
items only exist in items YOU'D LIKE TO* THINK SO WOULDN'T YOU!?!

And that second one isn't good. It'll get you literally everything with a name. Like achievements (first category I ran into after accumulator that has a name).
I have mods! I guess!
Link

Pi-C
Smart Inserter
Smart Inserter
Posts: 1656
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: All item types, all entity types in data stage

Post by Pi-C »

Honktown wrote: ↑
Fri Jan 31, 2020 9:28 am
Pi-C wrote: ↑
Fri Jan 31, 2020 9:18 am
...
items only exist in items YOU'D LIKE TO* THINK SO WOULDN'T YOU!?!
What's wrong with that assumption?
And that second one isn't good. It'll get you literally everything with a name. Like achievements (first category I ran into after accumulator that has a name).
See the original request:
darkfrei wrote: ↑
Fri Jan 31, 2020 8:07 am
Is here easy way to get all item types and entity types by the data stage?
That's just what the code does. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: All item types, all entity types in data stage

Post by Honktown »

Pi-C wrote: ↑
Fri Jan 31, 2020 9:33 am
Honktown wrote: ↑
Fri Jan 31, 2020 9:28 am
Pi-C wrote: ↑
Fri Jan 31, 2020 9:18 am
...
items only exist in items YOU'D LIKE TO* THINK SO WOULDN'T YOU!?!
What's wrong with that assumption?
And that second one isn't good. It'll get you literally everything with a name. Like achievements (first category I ran into after accumulator that has a name).
See the original request:
darkfrei wrote: ↑
Fri Jan 31, 2020 8:07 am
Is here easy way to get all item types and entity types by the data stage?
That's just what the code does. :-)
1) Items exist in other places. Yeah. The devs did that.

2) I'll assume you're being an idiotwrong on purpose.
I have mods! I guess!
Link

Pi-C
Smart Inserter
Smart Inserter
Posts: 1656
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: All item types, all entity types in data stage

Post by Pi-C »

Honktown wrote: ↑
Fri Jan 31, 2020 10:15 am
1) Items exist in other places. Yeah. The devs did that.
Could you give an example? Why would the devs do that? Of course, I could imagine some mod deepcopying (parts of) item to another name so you'd find things of type = "item" somewhere below data.raw.something-not-item…
2) I'll assume you're being an idiotwrong on purpose.
Why? Don't assume that people would want to compile a list of entity names only for processing it in their code. It may be helpful to see what entities exist during development, just for information. If you're really only interested in entities with a collision_mask, it shouldn't be too hard to check for that as well and only output the name of entities that have a collision_mask.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: All item types, all entity types in data stage

Post by eradicator »

darkfrei wrote: ↑
Fri Jan 31, 2020 8:07 am
Is here easy way to get all item types and entity types by the data stage?
Almost(?) all entity prototypes have collision boxes, but is it by them only?
Just the types? Indeed very easy. Just fucking hardcode the list, it almost never changes anyway. Every"smart" solution you try will just be a buggy mess that randomly fails on modded entities that are different than you "expect", and nobody will bother sending you bug reports about it.

Code: Select all

local hardcoded_classes = {

  --A *HARDCODED* classification of all known prototype types
  --
  --Current Version: base-0.17.53
  --
  
  item = { --ITEMS
    'item', 'armor'    , 'mining-tool'   , 'item-with-tags'     , 'item-with-inventory'  ,
    'ammo', 'module'   , 'repair-tool'   , 'selection-tool'     , 'item-with-entity-data',
    'gun' , 'capsule'  , 'rail-planner'  , 'item-with-label'    , 'copy-paste-tool'      ,
    'tool', 'blueprint', 'blueprint-book', 'deconstruction-item', 'upgrade-item'          },

  building = { --ENTITIES (BUILDINGS)  
    'lab'    , 'inserter'   , 'solar-panel'     , 'rail-chain-signal'        ,
    'gate'   , 'roboport'   , 'fluid-turret'    , 'assembling-machine'       ,
    'lamp'   , 'splitter'   , 'mining-drill'    , 'decider-combinator'       ,
    'pipe'   , 'container'  , 'power-switch'    , 'infinity-container'       ,
    'pump'   , 'generator'  , 'storage-tank'    , 'logistic-container'       ,
    'wall'   , 'heat-pipe'  , 'electric-pole'   , 'constant-combinator'      ,
    'radar'  , 'land-mine'  , 'offshore-pump'   , 'programmable-speaker'     ,
    'beacon' , 'train-stop' , 'simple-entity'   , 'arithmetic-combinator'    ,
    'boiler' , 'accumulator', 'straight-rail'   , 'simple-entity-with-force' ,
    'loader' , 'ammo-turret', 'pipe-to-ground'  , 'simple-entity-with-owner' ,
    'market' , 'curved-rail', 'transport-belt'  , 'electric-energy-interface',
    'turret' , 'player-port', 'electric-turret' , 'heat-interface'           ,
    'furnace', 'rail-signal', 'artillery-turret', 'infinity-pipe'            ,
    'reactor', 'rocket-silo', 'underground-belt' },
    
  robot = { --ENTITY (ROBOTS)
    'combat-robot', 'logistic-robot', 'construction-robot' },
    
  special_entity = { --ENTITIES (SPECIAL)
    'beam'  , 'stream'     , 'entity-ghost'    , 'item-request-proxy'        ,
    'fire'  , 'sticker'    , 'unit-spawner'    , 'rocket-silo-rocket'        ,
    'fish'  , 'particle'   , 'leaf-particle'   , 'smoke-with-trigger'        ,
    'unit'  , 'explosion'  , 'rail-remnants'   , 'artillery-projectile'      ,
    'arrow' , 'projectile' , 'trivial-smoke'   , 'flame-thrower-explosion'   ,
    'smoke' , 'tile-ghost' , 'artillery-flare' , 'rocket-silo-rocket-shadow' ,
    'corpse', 'flying-text', 'particle-source' , 'deconstructible-tile-proxy', 
    'character', 'item-entity', 'character-corpse' },
  
  map_entity = { --ENTITIES (MAP)
    'cliff', 'resource', 'tree', 'tile', 'decorative', 'optimized-decorative' },
    
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: ζ—₯本θͺž, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: All item types, all entity types in data stage

Post by darkfrei »

For better understanding:
Item - the thing, that can be produced or used in the recipes, but not fluid.
Entity - the thing, that can be placed on the map by the player without control.lua, but not tile.
Tile - all things in data.raw.tile.

In the data stage we have multiple item types, multiple entity types. In the control stage we can get all of them via item_prototypes and entity_prototypes.

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

Re: All item types, all entity types in data stage

Post by darkfrei »

eradicator wrote: ↑
Fri Jan 31, 2020 11:03 am
Just the types? Indeed very easy. Just fucking hardcode the list, it almost never changes anyway. Every"smart" solution you try will just be a buggy mess that randomly fails on modded entities that are different than you "expect", and nobody will bother sending you bug reports about it.

Code: Select all

local hardcoded_classes = {

  --A *HARDCODED* classification of all known prototype types
  --
  --Current Version: base-0.17.53
  --
  
  item = { --ITEMS
    'item', 'armor'    , 'mining-tool'   , 'item-with-tags'     , 'item-with-inventory'  ,
    'ammo', 'module'   , 'repair-tool'   , 'selection-tool'     , 'item-with-entity-data',
    'gun' , 'capsule'  , 'rail-planner'  , 'item-with-label'    , 'copy-paste-tool'      ,
    'tool', 'blueprint', 'blueprint-book', 'deconstruction-item', 'upgrade-item'          },

  building = { --ENTITIES (BUILDINGS)  
    'lab'    , 'inserter'   , 'solar-panel'     , 'rail-chain-signal'        ,
    'gate'   , 'roboport'   , 'fluid-turret'    , 'assembling-machine'       ,
    'lamp'   , 'splitter'   , 'mining-drill'    , 'decider-combinator'       ,
    'pipe'   , 'container'  , 'power-switch'    , 'infinity-container'       ,
    'pump'   , 'generator'  , 'storage-tank'    , 'logistic-container'       ,
    'wall'   , 'heat-pipe'  , 'electric-pole'   , 'constant-combinator'      ,
    'radar'  , 'land-mine'  , 'offshore-pump'   , 'programmable-speaker'     ,
    'beacon' , 'train-stop' , 'simple-entity'   , 'arithmetic-combinator'    ,
    'boiler' , 'accumulator', 'straight-rail'   , 'simple-entity-with-force' ,
    'loader' , 'ammo-turret', 'pipe-to-ground'  , 'simple-entity-with-owner' ,
    'market' , 'curved-rail', 'transport-belt'  , 'electric-energy-interface',
    'turret' , 'player-port', 'electric-turret' , 'heat-interface'           ,
    'furnace', 'rail-signal', 'artillery-turret', 'infinity-pipe'            ,
    'reactor', 'rocket-silo', 'underground-belt' },
    
  robot = { --ENTITY (ROBOTS)
    'combat-robot', 'logistic-robot', 'construction-robot' },
    
  special_entity = { --ENTITIES (SPECIAL)
    'beam'  , 'stream'     , 'entity-ghost'    , 'item-request-proxy'        ,
    'fire'  , 'sticker'    , 'unit-spawner'    , 'rocket-silo-rocket'        ,
    'fish'  , 'particle'   , 'leaf-particle'   , 'smoke-with-trigger'        ,
    'unit'  , 'explosion'  , 'rail-remnants'   , 'artillery-projectile'      ,
    'arrow' , 'projectile' , 'trivial-smoke'   , 'flame-thrower-explosion'   ,
    'smoke' , 'tile-ghost' , 'artillery-flare' , 'rocket-silo-rocket-shadow' ,
    'corpse', 'flying-text', 'particle-source' , 'deconstructible-tile-proxy', 
    'character', 'item-entity', 'character-corpse' },
  
  map_entity = { --ENTITIES (MAP)
    'cliff', 'resource', 'tree', 'tile', 'decorative', 'optimized-decorative' },
    
Car and 1x1 loader?

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: All item types, all entity types in data stage

Post by Honktown »

Pi-C wrote: ↑
Fri Jan 31, 2020 10:44 am
Why? Don't assume that people would want to compile a list of entity names only for processing it in their code. It may be helpful to see what entities exist during development, just for information. If you're really only interested in entities with a collision_mask, it shouldn't be too hard to check for that as well and only output the name of entities that have a collision_mask.
Everything has a name, unless I missed some niche category. The game will refuse to get past the data stage if the value of name in data.raw.category[name][name] isn't the same, and thing.type has to match the category.

Code: Select all

log("Getting entities:")
for _,x in pairs(all) do
    for _, entity in pairs(x) do
        log(entity.name .. ":\t" .. entity.type)
    end
end
That gets everything. I though you were being a dick because technically, all entities and items are in their somewhere, you just grabbed literally everything.
I have mods! I guess!
Link

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: All item types, all entity types in data stage

Post by Honktown »

darkfrei wrote: ↑
Fri Jan 31, 2020 11:28 am
Car and 1x1 loader?
cars are in item_with_entity_data, and I dunno about 1x1 loaders, but normal loaders are in item.
I have mods! I guess!
Link

Pi-C
Smart Inserter
Smart Inserter
Posts: 1656
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: All item types, all entity types in data stage

Post by Pi-C »

Honktown wrote: ↑
Fri Jan 31, 2020 1:17 pm
That gets everything. I though you were being a dick because technically, all entities and items are in their somewhere, you just grabbed literally everything.
You can look for recipes in data.raw.recipe, and for items in data.raw.item, but as far as I know, you can't look for entities in data.raw.entity because it doesn't exist. To quote from the Factorio wiki:
Entity is basically everything that can be on the map (except tiles).
Sometimes I just want to see a dump of what's available. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: All item types, all entity types in data stage

Post by eradicator »

darkfrei wrote: ↑
Fri Jan 31, 2020 11:28 am
Car and 1x1 loader?
Do you have any actual questions besides not reading the "Current Version:" comment at the top? Cos i doubt you're too stupid to add two more entries for this list that you're not even telling what you want it for.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: ζ—₯本θͺž, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: All item types, all entity types in data stage

Post by darkfrei »

eradicator wrote: ↑
Fri Jan 31, 2020 1:48 pm
darkfrei wrote: ↑
Fri Jan 31, 2020 11:28 am
Car and 1x1 loader?
Do you have any actual questions besides not reading the "Current Version:" comment at the top? Cos i doubt you're too stupid to add two more entries for this list that you're not even telling what you want it for.
Please don't be angry about my stupidity.
I've noticed that here at least two entities are not presented in this hardcoded entity types list. How can I sure that here are all of them?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: All item types, all entity types in data stage

Post by eradicator »

darkfrei wrote: ↑
Fri Jan 31, 2020 5:09 pm
How can I sure that here are all of them?
Your opening post couldn't be more vague about what you actually hope to achieve with this, so i posted a snippet i thought might be relevant, that's it. Just to give you an idea. My own code assigns a category to every key of data.raw. On startup it automatically checks if a new factorio version a) has any keys that are not in my list, or b) the list has keys that don't exist in the engine anymore. As i haven't touched 0.18 yet new stuff like 1x1-loader is obviously not included.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: ζ—₯本θͺž, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: All item types, all entity types in data stage

Post by darkfrei »

I've collected all result item names from recipes. Than I've checked add prototype types if they have this items as subtable name.

Code: Select all

all_types [84]: 
all_types = {"noise-layer", "furnace", "transport-belt", "boiler", "container", "electric-pole", "generator", "offshore-pump", "inserter", "pipe", "radar", "lamp", "pipe-to-ground", "assembling-machine", "wall", "lab", "splitter", "underground-belt", "loader", "car", "roboport", "logistic-container", "construction-robot", "gate", "electric-energy-interface", "mining-drill", "resource", "ammo-turret", "ammo", "armor", "gun", "item", "capsule", "repair-tool", "tool", "item-with-entity-data", "item-subgroup", "recipe", "autoplace-control", "tile", "ammo-category", "fuel-category", "recipe-category", "resource-category", "technology", "projectile", "solar-panel", "locomotive", "cargo-wagon", "fluid-wagon", "artillery-wagon", "player-port", "land-mine", "train-stop", "rail-signal", "rail-chain-signal", "logistic-robot", "rocket-silo", "storage-tank", "pump", "accumulator", "beacon", "arithmetic-combinator", "decider-combinator", "constant-combinator", "power-switch", "programmable-speaker", "reactor", "heat-pipe", "burner-generator", "artillery-turret", "electric-turret", "fluid-turret", "rail-planner", "module", "night-vision-equipment", "energy-shield-equipment", "battery-equipment", "solar-panel-equipment", "generator-equipment", "active-defense-equipment", "movement-bonus-equipment", "roboport-equipment", "belt-immunity-equipment"}
Only some of them are entities, some are items, some have other type, not entities or items.

Code: Select all

local all_item_types = {"ammo", "armor", "gun", "item", "capsule", "repair-tool", "tool", "item-with-entity-data", "item-subgroup", "rail-planner", "module", "night-vision-equipment", "energy-shield-equipment", "battery-equipment", "solar-panel-equipment", "generator-equipment", "active-defense-equipment", "movement-bonus-equipment", "roboport-equipment", "belt-immunity-equipment"}

Code: Select all

local all_entity_types = {"furnace", "transport-belt", "boiler", "container", "electric-pole", "generator", "offshore-pump", "inserter", "pipe", "radar", "lamp", "pipe-to-ground", "assembling-machine", "wall", "lab", "splitter", "underground-belt", "loader", "car", "roboport", "logistic-container", "construction-robot", "gate", "electric-energy-interface", "mining-drill", "resource", "ammo-turret", "solar-panel", "locomotive", "cargo-wagon", "fluid-wagon", "artillery-wagon", "land-mine", "train-stop", "rail-signal", "rail-chain-signal", "logistic-robot", "rocket-silo", "storage-tank", "pump", "accumulator", "beacon", "arithmetic-combinator", "decider-combinator", "constant-combinator", "power-switch", "programmable-speaker", "reactor", "heat-pipe", "burner-generator", "artillery-turret", "electric-turret", "fluid-turret"}

Post Reply

Return to β€œModding help”