Infinite chest mod: give me some pointers please!

Place to get help with not working mods / modding interface.
ZorbaTHut
Burner Inserter
Burner Inserter
Posts: 11
Joined: Wed Mar 11, 2015 5:03 am
Contact:

Infinite chest mod: give me some pointers please!

Post 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!

User avatar
Xecutor
Filter Inserter
Filter Inserter
Posts: 260
Joined: Mon Jun 23, 2014 10:15 am
Contact:

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

Post 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.

ZorbaTHut
Burner Inserter
Burner Inserter
Posts: 11
Joined: Wed Mar 11, 2015 5:03 am
Contact:

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

Post by ZorbaTHut »

Xecutor wrote: every answer imaginable
Just what I needed! Thank you very much :)

User avatar
Gandalf
Filter Inserter
Filter Inserter
Posts: 294
Joined: Fri Dec 19, 2014 10:15 pm
Contact:

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

Post by Gandalf »

Image
https://xkcd.com/138/
Couldn't resist.
OS: Linux Mint 19 x64 | desktop: Awesome 4.2  |  Intel Core i5 8600k  |  16GB DDR4  |  NVidia GTX 1050 Ti (driver version: 410.104)    (2019-03)

hoho
Filter Inserter
Filter Inserter
Posts: 681
Joined: Sat Jan 18, 2014 11:23 am
Contact:

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

Post 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

Post Reply

Return to “Modding help”