MinicraftPlus / minicraft-plus-revived

Minicraft+, an extension of Notch's original minicraft project, with tons more features.
GNU General Public License v3.0
456 stars 92 forks source link

Reorganize Inventory code and add Reward Chest #666

Open BenCheung0422 opened 3 months ago

BenCheung0422 commented 3 months ago

This depends on #630 Originally, Inventory resolves for both bounded and unlimited inventory types for item list menus and container inventories, but this is not the best design. So, Inventory is instead made into an interface and 2 separate subclasses BoundedInventory and UnlimitedInventory are made for the corresponding situations. That said, BoundedInventory only handle inventories that have a size limit while UnlimitedInventory does not make any constrains on the size limit by default. This makes the code neater without concerning about "different unused fields exist for each circumstance", which shall be regarded as bad practice. Then, a RewardChest is added to resolve the original problem that a chest is generated each time rewards are sent. Furthermore, world loading used DeathChest for saving inventory-overflowing items, which may not be well for players, so a RewardChest without timer is used instead. Now, the RewardChest cannot be treated as ordinary chest as items cannot be added and the chest is removed when its inventory is empty. This can reduce the chances players getting more survival-usable chests without any consumption of the desired materials. Also, RewardChest provides an interactive menu, unlike DeathChest. Perhaps, DeathChest should also be made with an interactive menu though.