Lets say i have a machine on map, eg a fancy kind of modded combinator.
How do i enable it for blueprinting so its state is kept in a blueprint in the usual way?
Its state might be complex such as a chunk of its own state.
How to create blueprintable item?
Re: How to create blueprintable item?
Make the machine a constant combinator. Design a compression scheme to fit all the data into combinator signals.
Re: How to create blueprintable item?
Theres no general answer other than "put your data into the existing entity state and have it blueprinted that way" is there?
Eg if I had an assembler that fails every x seconds and needs to store that into the blueprint.id need to encode that into the existing assembler somehow. Right?
Eg if I had an assembler that fails every x seconds and needs to store that into the blueprint.id need to encode that into the existing assembler somehow. Right?
Re: How to create blueprintable item?
Yes, blueprints will only accept existing entities. And assembling machine does not have any spare data fields. Constant combinator is by far the best entity to use.
If your entity is not a constant combinator, make it a constant combinator and add the assembling machine part in on_built().
If your entity is not a constant combinator, make it a constant combinator and add the assembling machine part in on_built().
Re: How to create blueprintable item?
This was where I was headed, thanks.
I'm updating all my mods after hiatus and some new ideas require blueprinting I've never really investigated.
I'm updating all my mods after hiatus and some new ideas require blueprinting I've never really investigated.
-
- Filter Inserter
- Posts: 587
- Joined: Sun Jun 09, 2019 10:40 pm
- Contact:
Re: How to create blueprintable item?
From elsewhere: viewtopic.php?t=49709#p288672
That contains code with (a) a pure Lua implementation of msgpack encoding for Lua tables, and (b) a mechanism (and entity) for packing that into a combinator. The supplied combinator, with 500 slots, means ~ 2K total data storage without anything fancy. Given that, and the relative efficiency of msgpack, you can likely store around 1,500 bytes per entity without having to think about it very much.
I'd strongly recommend that, right now, because it gives you a good, solid way to put structured data into a blueprint. That minimizes the amount of messing about involved. Simply add the entity to your mod based on their template, import the relevant code – which is licensed so you have no significantly increased obligations from doing so, even if this is not mere aggregation – and do the on_build thing.
To increase annoyance, you need to remember that any mod can destroy your entities -- either the combinator, or the machine associated -- without raising any event. So, while `on_destroy` will fire most of the time, you also need to handle the cases where something is missing a part of the whole. (Given the code in the linked thread "add the assembling machine part in on_built()" from DaveMcW above.
....I should turn that into a wiki page or something. It has lots of details from lots of places, and is a fairly common question.
edit: apparently no modding advice like this on the wiki, so I guess this is as close as it gonna get.
That contains code with (a) a pure Lua implementation of msgpack encoding for Lua tables, and (b) a mechanism (and entity) for packing that into a combinator. The supplied combinator, with 500 slots, means ~ 2K total data storage without anything fancy. Given that, and the relative efficiency of msgpack, you can likely store around 1,500 bytes per entity without having to think about it very much.
I'd strongly recommend that, right now, because it gives you a good, solid way to put structured data into a blueprint. That minimizes the amount of messing about involved. Simply add the entity to your mod based on their template, import the relevant code – which is licensed so you have no significantly increased obligations from doing so, even if this is not mere aggregation – and do the on_build thing.
To increase annoyance, you need to remember that any mod can destroy your entities -- either the combinator, or the machine associated -- without raising any event. So, while `on_destroy` will fire most of the time, you also need to handle the cases where something is missing a part of the whole. (Given the code in the linked thread "add the assembling machine part in on_built()" from DaveMcW above.
....I should turn that into a wiki page or something. It has lots of details from lots of places, and is a fairly common question.
edit: apparently no modding advice like this on the wiki, so I guess this is as close as it gonna get.