Class SingleItemStorage

All Implemented Interfaces:
Iterable<StorageView<ItemVariant>>, SingleSlotStorage<ItemVariant>, SlottedStorage<ItemVariant>, Storage<ItemVariant>, StorageView<ItemVariant>, TransactionContext.CloseCallback, TransactionContext.OuterCloseCallback

public abstract class SingleItemStorage extends SingleVariantStorage<ItemVariant>
A storage that can store a single item variant at any given time. Implementors should at least override getCapacity(ItemVariant), and probably SnapshotParticipant.onFinalCommit() as well for setChanged() and similar calls.

This is a convenient specialization of SingleVariantStorage for items that additionally offers methods to deserialize the contents of the storage.

  • Constructor Details

    • SingleItemStorage

      public SingleItemStorage()
  • Method Details

    • getBlankVariant

      protected final ItemVariant getBlankVariant()
      Description copied from class: SingleVariantStorage
      Return the blank variant.

      Note: this is called very early in the constructor. If fields need to be accessed from this function, make sure to re-initialize SingleVariantStorage.variant yourself.

      Specified by:
      getBlankVariant in class SingleVariantStorage<ItemVariant>
    • readValue

      public void readValue(net.minecraft.world.level.storage.ValueInput data)
      Simple implementation of reading from ValueInput, to match what is written by writeValue(ValueOutput). Other formats are allowed, this is just a suggestion.
    • writeValue

      public void writeValue(net.minecraft.world.level.storage.ValueOutput data)
      Simple implementation of writing to ValueOutput. Other formats are allowed, this is just a suggestion.