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

invalid @link
#equals
, never by reference!
invalid @link
#hashCode
is guaranteed to be correct and constant time independently of the size of the NBT.
  • Method Summary

    Modifier and Type
    Method
    Description
    default @Nullable net.minecraft.nbt.NbtCompound
    Return a copy of the tag of this variant, or null if this variant doesn't have a tag.
    @Nullable net.minecraft.nbt.NbtCompound
    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
    nbtMatches(@Nullable net.minecraft.nbt.NbtCompound other)
    Return true if the tag of this variant matches the passed tag, and false otherwise.
    net.minecraft.nbt.NbtCompound
    Save this variant into an NBT compound tag.
    void
    toPacket(net.minecraft.network.PacketByteBuf buf)
    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

      @Nullable @Nullable net.minecraft.nbt.NbtCompound 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 net.minecraft.nbt.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 net.minecraft.nbt.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.

    • toNbt

      net.minecraft.nbt.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(net.minecraft.network.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.