Store user-state in entities for copy/paste/blueprints

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

doktorstick
Fast Inserter
Fast Inserter
Posts: 220
Joined: Fri Aug 12, 2016 10:22 pm
Contact:

Store user-state in entities for copy/paste/blueprints

Post by doktorstick »

Howdy. Modders create entities that may not be classically copy-pasted (i.e., SHIFT-RMB, SHIFT-LMB doesn't work). This prevents players from copy/pasting the item's settings and tools like blueprints won't work because there isn't any state being carried along these special entities.

The suggestion is that a modder stores a dictionary in `LuaEntity.set_custom_settings()` and fetches it with `LuaEntity.get_custom_settings()'. If the dictionary is non-nil, then it enables copy-paste on the item. Additionally, the `custom_settings` are carried along for purposes of blueprints and update planner.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14819
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Store user-state in entities for copy/paste/blueprints

Post by Rseding91 »

You can already listen to the copy-paste events and enable copy-paste for any set of entities you wish through the prototype.

As for blueprints: what data are you wanting to store in a blueprint?
If you want to get ahold of me I'm almost always on Discord.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Store user-state in entities for copy/paste/blueprints

Post by Adil »

Well, if one makes some entity with logic implemented in lua and there are certain parameters that player can tweak ingame to define the behavior, then it might be desirable to transmit those parameters around. For example there used to be lua combinators before, had anyone used those, the desire to have their internal state transmitted would be understandable.
Then there are all sorts of automatic assemblers, fluid handlers, teleporters, robot deployers and so on.

Chests are also sometimes used as a base for entity that does stuff to its contents, and then one could add lua data, that defines what stuff exactly to do with contents. And complete absence of the copy-paste for chests might be inconvenient here.

Though I don't really understand the stuff in the op about the dictionary and stuff. I'd personally settle on blueprint event, that would hold a unique identifier per each blueprinted entity, so that when blueprint is placed same identifiers could be obtained and compared to stored ones. (Not unit_numbers, but identifiers, that are generated on the act of blueprinting.)
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
doktorstick
Fast Inserter
Fast Inserter
Posts: 220
Joined: Fri Aug 12, 2016 10:22 pm
Contact:

Re: Store user-state in entities for copy/paste/blueprints

Post by doktorstick »

Thanks for the hint about copy-paste; I got it working[1]. After hunting I found it...? FWIW, Googling "site:lua-api.factorio.com additional_pastable_entities" returns 0 hits, and I couldn't find reference to it in the code base.

Adil covered the why pretty well. For my specific use-case, take my hacked-splitter entity. You can set the side and lane you want to prioritize by hovering over the item and using keybinds to cycle through the modes. You cannot blueprint these settings.

Likewise, since there's no standard way for custom settings, Upgrade Planner cannot communicate to the new item the custom settings of the item it replaced.

[1] I'm not sure the additional_pastable_entities works like described, which I'm thankful for. It appears that it enables copy on the entity and fires the event whenever you paste to the type. For instance, In my "hacked-fast-splitter", I set additional_pastable_entities = { "hacked-fast-splitter" } (i.e., itself not a list of other entities), and the events fire for all five hacked-splitter variants as well as for the vanilla splitters. I could not copy vanilla splitters (as expected).
Post Reply

Return to “Ideas and Suggestions”