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 setChanged() 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 setChanged() 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>
    • readValue

      public void readValue(net.minecraft.world.level.storage.ValueInput value)
      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 value)
      Simple implementation of writing to ValueOutput. Other formats are allowed, this is just a convenient suggestion.