Hi. I'm trying to make chests whose slots can be filtered to only allow some kind of items just like cargo wagons, and it's my first time modding so I have no idea what I'm doing. I have several potential approaches in mind, and frequently switch whenever the current one hits a roadblock:
1) Use some metatable magic change the inventory of chests to some other inventory that allows filters: if this worked, it would have been really easy but it seems to be impossible because metatables are protected.
2) Somehow merge the chest and cargo wagon definitions of data.raw, something like a cargo wagon with the bounding boxes and sprites of the chests. I feel like this is unlikely to work, and even if it did, it would most likely have weird unexpected behaviors.
3) Do it like you would without modding (i.e. with a constant combinator for the allowed context, with a small circuit that tells the inserters to only inserts when doing so respects the filter), possibly with some things hidden via custom versions of combinators etc. added to data.raw. This looks like a very unstable way of doing this.
4) Hijack both the the behavior of inserters, and the gui that are opened when opening chests to open the gui of a cargo wagon whose content is synchronized with the chest.
The inserter part looks fairly easy: replace stack inserter by filter stack inserters that have the skin of stack inserters, and whose filter is automatically recomputed at each tick (iterating through the items that can be inserted without going over the limit).
The gui part felt harder: I found how to prevent de default gui from opening, and how to add other gui elements, but not how to reuse the "normal" ui. Is there some way, given a chest entity, to open the corresponding gui? Or does one have to recreate the whole ui? I would have expected GuiStyles to be for that purpose, but it seems to only define the style of the layers of the normal gui, but to not have anything to build a part of the gui with all its descendants.
Is there a simpler method I'm missing? Which method to you think is best?
Trying to make a mod that allows filtering chest inventories
Re: Trying to make a mod that allows filtering chest inventories
Cargo wagon would be problematic as those can only be placed on rails (AFAIK scripting can't ignore that restriction, but i might be wrong). A non-moving, passengerless, fuelless, belt-immune, chest-shaped car would seem to be the better choice, as the inventory is still filterable but they can be freely placed. You do lose the bar to limit inventory size, but easy enough to use filters to limit the size instead.
It shouldn't need much in the way of shenanigans I can think of. The GUI/tooltip may look a little strange but that's gonna end up the case for most implementations.
The API is really only setup to either make your own GUI for something from scratch, or use the vanilla GUI with your own addition stuck to one of the sides using a relative element. See an example here. In fact I suppose you could easily add a relative GUI to the car-chest to give a way to set the last 'X' filters to some item that doesn't exist to simulate the bar chests/wagons have.
It shouldn't need much in the way of shenanigans I can think of. The GUI/tooltip may look a little strange but that's gonna end up the case for most implementations.
The API is really only setup to either make your own GUI for something from scratch, or use the vanilla GUI with your own addition stuck to one of the sides using a relative element. See an example here. In fact I suppose you could easily add a relative GUI to the car-chest to give a way to set the last 'X' filters to some item that doesn't exist to simulate the bar chests/wagons have.
Re: Trying to make a mod that allows filtering chest inventories
Same problem here and the car thing seems to be the way to go. Let me know if you implement this assuming your license would allow reusing it for my own projects.
Or maybe make a suggestion of a new chest type that allows filtering slots. I bugs me that this isn't a flag in the chest prototype.
Or maybe make a suggestion of a new chest type that allows filtering slots. I bugs me that this isn't a flag in the chest prototype.
Re: Trying to make a mod that allows filtering chest inventories
I'll try cars. Thank you for your help 
If I get this to work, I intend on putting a very permissive license on it. I'll let you know if it happens.

If I get this to work, I intend on putting a very permissive license on it. I'll let you know if it happens.