Interface TransferVariant<O>

Type Parameters:
O - The type of the immutable object instance, for example Item or Fluid. Experimental feature, we reserve the right to remove or change it without further notice. The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
All Known Subinterfaces:
FluidVariant, ItemVariant

@Experimental public interface TransferVariant<O>
An immutable association of an immutable object instance (for example Item or Fluid) and an optional NBT tag.

This is exposed for convenience for code that needs to be generic across multiple transfer variants, but note that a Storage is not necessarily bound to TransferVariant. Its generic parameter can be any immutable object.

Transfer variants must always be compared with equals, never by reference! hashCode is guaranteed to be correct and constant time independently of the size of the NBT.

  • Method Summary

    Modifier and Type
    Method
    Description
    Return a copy of the tag of this variant, or null if this variant doesn't have a tag.
    default NbtCompound
    Return a copy of the tag of this variant, or a new compound if this variant doesn't have a tag.
    Return the underlying tag.
    Return the immutable object instance of this variant.
    default boolean
    Return true if this variant has a tag, false otherwise.
    boolean
    Return true if this variant is blank, and false otherwise.
    default boolean
    isOf(O object)
    Return true if the object of this variant matches the passed fluid.
    default boolean
    Return true if the tag of this variant matches the passed tag, and false otherwise.
    Save this variant into an NBT compound tag.
    void
    Write this variant into a packet byte buffer.
  • Method Details

    • isBlank

      boolean isBlank()
      Return true if this variant is blank, and false otherwise.
    • getObject

      O getObject()
      Return the immutable object instance of this variant.
    • getNbt

      Return the underlying tag.

      NEVER MUTATE THIS NBT TAG, if you need to mutate it you can use copyNbt() to retrieve a copy instead.

    • hasNbt

      default boolean hasNbt()
      Return true if this variant has a tag, false otherwise.
    • nbtMatches

      default boolean nbtMatches(@Nullable @Nullable NbtCompound other)
      Return true if the tag of this variant matches the passed tag, and false otherwise.

      Note: True is returned if both tags are null.

    • isOf

      default boolean isOf(O object)
      Return true if the object of this variant matches the passed fluid.
    • copyNbt

      @Nullable default @Nullable NbtCompound copyNbt()
      Return a copy of the tag of this variant, or null if this variant doesn't have a tag.

      Note: Use nbtMatches(net.minecraft.nbt.NbtCompound) if you only need to check for custom tag equality, or getNbt() if you don't need to mutate the tag.

    • copyOrCreateNbt

      default NbtCompound copyOrCreateNbt()
      Return a copy of the tag of this variant, or a new compound if this variant doesn't have a tag.
    • toNbt

      NbtCompound toNbt()
      Save this variant into an NBT compound tag. Subinterfaces should have a matching static fromNbt.

      Note: This is safe to use for persisting data as objects are saved using their full Identifier.

    • toPacket

      void toPacket(PacketByteBuf buf)
      Write this variant into a packet byte buffer. Subinterfaces should have a matching static fromPacket.

      Implementation note: Objects are saved using their raw registry integer id.