Page 1 of 1

Infinite chest mod: give me some pointers please!

Posted: Wed Mar 11, 2015 5:17 am
by ZorbaTHut
I'm working on my first Factorio mod but I'm having trouble figuring out the not-quite-basics of the modding system. So here's a pile of questions! Note that I'm happy to read existing mods in order to find answers, so if your answer is "Mod X does that" then I can probably untangle it from there.

I'm looking to create a chest that automatically spawns/despawns items inside it for the purpose of testing layouts. I basically want a Requester chest that, at all times, contains exactly the requested items. As near as I can tell it's not possible to add the Request chest UI easily to an existing chest (is that true?), so I was planning to just make another chest with the logistics settings of a Requester chest and let the game code take care of that. (Is that reasonable?)

However, this means I'll either need to track every time an item is removed from one of my chests (is that possible? I don't think so) or update all of my chests every once in a while. The latter seems reasonable to me, but I can't find any way to list all entities of a given type (is there one?)

It seems like the expected way to do this is to store a list of all entities of this type when they're placed, and clean them up when they're removed (is that true?) but I can't figure out how to do that, nor what exactly I should be storing in a list (positions? actual entity handles?). Also, if I do do this, I'll need some way to serialize that list on shutdown, and I'm having trouble untangling how the save/load systems work.

I'm also not 100% sure it's possible for me to retrieve the list of requested items from a chest, but I haven't even gotten that far yet; at least it seems easy to add/remove things from a chest.

So if anyone can point me at a small mod or two that do similar things, or give me the necessary keywords to look for in order to find out more, I'd be eternally grateful!

Re: Infinite chest mod: give me some pointers please!

Posted: Wed Mar 11, 2015 7:32 am
by Xecutor
ZorbaTHut wrote: I'm looking to create a chest that automatically spawns/despawns items inside it for the purpose of testing layouts. I basically want a Requester chest that, at all times, contains exactly the requested items. As near as I can tell it's not possible to add the Request chest UI easily to an existing chest (is that true?),
true
ZorbaTHut wrote:so I was planning to just make another chest with the logistics settings of a Requester chest and let the game code take care of that. (Is that reasonable?)
This chest still will work as requester chest. If you don't care, than it's basically the only way to go.
ZorbaTHut wrote: However, this means I'll either need to track every time an item is removed from one of my chests (is that possible? I don't think so)
Yes, it's impossible atm.
ZorbaTHut wrote: or update all of my chests every once in a while. The latter seems reasonable to me, but I can't find any way to list all entities of a given type (is there one?)
No, there isn't.
ZorbaTHut wrote:It seems like the expected way to do this is to store a list of all entities of this type when they're placed, and clean them up when they're removed (is that true?)
true
ZorbaTHut wrote:but I can't figure out how to do that, nor what exactly I should be storing in a list (positions? actual entity handles?).
There are game events for entities placing, mining, destruction. Look carefully at events on wiki. here.
IMO the best way is position (as text) as a key and entity as value.
ZorbaTHut wrote: Also, if I do do this, I'll need some way to serialize that list on shutdown, and I'm having trouble untangling how the save/load systems work.
Everything stored in 'glob' global variable is serialized on save and deserialized on load. Including entities, but only as values, not as keys.
ZorbaTHut wrote:I'm also not 100% sure it's possible for me to retrieve the list of requested items from a chest, but I haven't even gotten that far yet; at least it seems easy to add/remove things from a chest.
It is possible to get/set requested items of requester chest. (get|set)requestslot method of entity.here.

Re: Infinite chest mod: give me some pointers please!

Posted: Wed Mar 11, 2015 10:56 am
by ZorbaTHut
Xecutor wrote: every answer imaginable
Just what I needed! Thank you very much :)

Re: Infinite chest mod: give me some pointers please!

Posted: Wed Mar 11, 2015 11:00 pm
by Gandalf
Image
https://xkcd.com/138/
Couldn't resist.

Re: Infinite chest mod: give me some pointers please!

Posted: Thu Mar 12, 2015 6:16 am
by hoho
If you want to see how other people have solved this you can have a look at the creative mode chest mod here:
https://forums.factorio.com/forum/vie ... =14&t=8976