Interface KeyedStorage
- All Superinterfaces:
Storage
Storage that knows its own persistent identity. Implementing
KeyedStorage is the opt-in path for making a custom-panel slot
resolvable by M1's persistent-state machinery — once the resolver can
map the slot's container back to a PersistentContainerKey, the
full SlotStateChannel API works against that slot the same way
it works against vanilla containers.
Why this lives in menukit-containers (MKC), not menukit:
PersistentContainerKey itself lives in MKC because slot-state
persistence is an MKC-side concern (M1, the per-slot state mechanism,
is a container-extension feature). Adding the keyed-storage default to
the MK-side Storage interface would force MK to import an MKC
type — a direct §0042 partition violation. Keeping KeyedStorage
here, as a sibling interface in MKC, leaves Storage minimal in
MK and puts the persistence variant in the module that owns the key
type. Consumers who want their custom-storage slots to participate in
M1 persistence implement KeyedStorage (which extends
Storage) instead of Storage directly.
Resolution path: the
ContainerKeyResolver sees that
the slot's container is a StorageContainerAdapter, inspects the
adapter's backing Storage, and — if it's a KeyedStorage
— uses storageKey() as the persistent identity. Non-keyed
storages fall through to the existing resolution table (player
inventory, ender chest, block entity, modded resolvers).
Key choice: the implementer picks the
PersistentContainerKey variant that matches the storage's
natural ownership scope. A player-attached storage typically returns a
PersistentContainerKey.Modded key with the player UUID encoded
in the payload; a block-entity-backed storage would return a
PersistentContainerKey.BlockEntityKey; etc.
-
Method Summary
Modifier and TypeMethodDescriptionReturns this storage's persistent identity.
-
Method Details
-
storageKey
PersistentContainerKey storageKey()Returns this storage's persistent identity. Used by M1 to look up per-slot state in the attachment scoped to this owner.Implementations should return a stable, equality-comparable key — two calls on the same logical storage instance must produce keys that compare
equals, even if invoked across the session/network boundary (server vs client sides of the same menu).- Returns:
- the persistent key for this storage; must not be
null.
-