Class VirtualStorage

java.lang.Object
com.trevlar.slotkit.api.storage.VirtualStorage
All Implemented Interfaces:
Storage

public class VirtualStorage extends Object implements Storage
Storage backed by a read function and a write function, so a consumer can bring any external data source into the Storage interface.

Implements plain Storage, not PersistentStorage: saving is up to the external source.

Replaces the old MKContainerSource and LiveContainerSource, where consumers supplied their own read and write callbacks.

  • Constructor Details

    • VirtualStorage

      public VirtualStorage(int size, IntFunction<net.minecraft.world.item.ItemStack> getter, BiConsumer<Integer, net.minecraft.world.item.ItemStack> setter, Runnable dirtyCallback)
      Parameters:
      size - number of slots
      getter - (localIndex) -> stack at that index
      setter - (localIndex, stack) -> write stack at that index
      dirtyCallback - called when markDirty() is invoked
    • VirtualStorage

      public VirtualStorage(int size, IntFunction<net.minecraft.world.item.ItemStack> getter, BiConsumer<Integer, net.minecraft.world.item.ItemStack> setter)
      With a dirty callback that does nothing.
  • Method Details

    • getStack

      public net.minecraft.world.item.ItemStack getStack(int localIndex)
      Description copied from interface: Storage
      Returns the stack at the given local index.
      Specified by:
      getStack in interface Storage
    • setStack

      public void setStack(int localIndex, net.minecraft.world.item.ItemStack stack)
      Description copied from interface: Storage
      Sets the stack at the given local index.
      Specified by:
      setStack in interface Storage
    • size

      public int size()
      Description copied from interface: Storage
      Returns the number of slots in this storage.
      Specified by:
      size in interface Storage
    • markDirty

      public void markDirty()
      Description copied from interface: Storage
      Marks this storage as changed.
      Specified by:
      markDirty in interface Storage