Item storage refactoring - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Development (https://forum.cuberite.org/forum-13.html) +--- Thread: Item storage refactoring (/thread-831.html) |
Item storage refactoring - xoft - 03-26-2013 It's about time we had yet another refactoring 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. RE: Item storage refactoring - keyboard - 03-26-2013 Yeah, that sounds like a great idea. I'm all for that. RE: Item storage refactoring - xoft - 03-26-2013 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 RE: Item storage refactoring - xoft - 04-11-2013 I've started working on this, so far I have the grid object and I've converted chests to use it (rev 1380). |