Class SingleFluidStorage

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

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

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

  • Constructor Details

    • SingleFluidStorage

      public SingleFluidStorage()
  • Method Details

    • withFixedCapacity

      public static SingleFluidStorage withFixedCapacity(long capacity, Runnable onChange)
      Create a fluid storage with a fixed capacity and a change handler.
      Parameters:
      capacity - Fixed capacity of the fluid storage. Must be non-negative.
      onChange - Change handler, generally for markDirty() or similar calls. May not be null.
    • getBlankVariant

      protected final FluidVariant 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<FluidVariant>
    • readData

      public void readData(ReadView data)
      Simple implementation of reading from ReadView, to match what is written by writeData(net.minecraft.storage.WriteView). Other formats are allowed, this is just a suggestion.
    • writeData

      public void writeData(WriteView data)
      Simple implementation of writing to WriteView. Other formats are allowed, this is just a convenient suggestion.