After banging my head into a wall for a few days, I've come here to ask for some assistance in a project of mine. Up-to-date documentation and best practices are often difficult to find, so please correct me if I've made terrible blunders in my code - especially if I'm terribly over-complicating things.
My main goals:
1. Create an item that contains data and an inventory.
2. Create a GUI that allows a user to swap items and see data.
3. Persist instance data while the given ItemStack exists.
My approach so far:
1. Create a custom Capability (impl, storage, provider) implementing IInventory.
2. Use initCapabilities to return my custom provider.
3. Trigger player.openGui() on item right click.
My issue(s) with this approach:
1. The inventory will wipe itself occasionally during play, and consistently upon reloading the world.
2. Bizarrely, the numeric data persists correctly.
Additional questions:
- As I understand it, IInventory is deprecated. Is there a better way to meet my goals without it?
Notes:
- The issue seems potentially related to my storage of slots in an NBTTagList. The first minimum-impl I was going to submit used a raw ItemStack for internal storage and a lone NBTTagCompound for serialization, and did not exhibit the noted issues. My actual implementation is much like the one now present.
Linked is a minimum implementation that exhibits these issues.
Main Class Capability Capability: Impl Capability: Provider Capability: Storage Example Container Example GuiContainer Example GuiHandler Example Item
2017-07-01 11:45
Capability (2)
Capability: Impl (2)
Capability: Provider (2)
Capability: Storage (2)