I've been refactoring and upgrading one of my mods, and one of the changes I wanted to make was to move from the old IInventory to the newer capabilities system. I must admit that I've been having a hard time grasping the new concepts, but I think I've managed to at least get the basics related to my use-case. That is, I have an entity which has an associated inventory, that can be accesed through a GUI when right-clicking such entity. Given this simple goal, I decided to use the provided ItemStackHandler implementation of IItemHandler, and I've sucessfully done the required changes for the core things/GUI to work (overridenhasCapability/getCapability, changed Slot to SlotItemHandler in the Container, persistency with NBT, ...).
However, I'm now facing a problem. The entity's inventory is not a generic storage, but more of a group of specific slots. That is, slot # can only hold one kind of item, and the entity must update some of its variables depending on the slot being filled or not. In the IInventory version, I had the Entity class implement the IInventoryChangedListener, and then I performed the corresponding checks and updates in the onInventoryChanged() method whenever the IInventory was modified. Now with capabilities I'm unsure of the approach to take. The ItemStackHandler class does contain a onContentsChanged() method that gets called on inventory update, but overriding it doesn't make sense right now as I'd need to access the entity's update methods from the ItemStackHandler class, which does not have access to the entity (or does it somehow?)
The possible solution I see right now would be to create my own implementation of IItemHandler, very similar to ItemStackHandler but taking the entity as an input parameter so I can then use it to call the entitiy's update methods in the onContentsChanged() call. But I feel this ain't the right approach, or is it? Is there any listener similar to IInventoryChangedListener in the new capability system, or am I missing anything else in general?
Thanks in advance!