Item storage refactoring
#1
It's about time we had yet another refactoring Smile

It seems that there are places in MineCraft where an item storage of a kind is used more and more. First the player inventory and chests, then minecarts-with-chests, then dispensers and droppers, hoppers etc. All of these use some form of item storage in a XY grid.

Therefore it would be beneficial if all these shared the same interface to that item storage management.

What I'm proposing is making the cInventory class more generic - add variable width and height, and make all those objects use this storage model. Then all the handling functions will be shared among all of the objects, making interaction and scripting easier.
Reply
Thanks given by:
#2
Yeah, that sounds like a great idea. I'm all for that.
Reply
Thanks given by:
#3
Now the question is, what functions can we put in this "interface". Besides the obvious SetSlot and GetSlot (and of course GetWidth, GetHeight), can it do anything more involved? I'm thinking it could, so here's a quick list, feel free to add suggestions:
Code:
int HowManyCanFit(const cItem & a_ItemStack);  // Returns number of items out of a_ItemStack that can fit in the storage
bool AddItem(cItem & a_ItemStack);  // Adds as many items out of a_ItemStack as can fit; the rest is left in a_ItemStack; returns true if {any?|all?} items fit.
bool AddItems(cItems & a_ItemStackList);  // Same as AddItem, but works on an entire list of item stacks
int GetFirstEmptySlot(void) const;  // Returns the index of the first empty slot
int GetLastEmptySlot(void) const;  // ^^ last ^^
Reply
Thanks given by:
#4
I've started working on this, so far I have the grid object and I've converted chests to use it (rev 1380).
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)