Interface TransferVariant<O>

Type Parameters:
O - The type of the immutable object instance, for example Item or Fluid.
All Superinterfaces:
net.minecraft.core.component.DataComponentGetter, net.minecraft.core.component.DataComponentHolder, net.minecraft.core.TypedInstance<O>
All Known Subinterfaces:
FluidVariant, ItemVariant

public interface TransferVariant<O> extends net.minecraft.core.component.DataComponentHolder, net.minecraft.core.TypedInstance<O>
An immutable association of an immutable object instance (for example Item or Fluid) and data components.

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 components.

  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    componentsMatch(net.minecraft.core.component.DataComponentPatch other)
    Return true if the tag of this variant matches the passed tag, and false otherwise.
    net.minecraft.core.component.DataComponentMap
     
    net.minecraft.core.component.DataComponentPatch
     
    Return the immutable object instance of this variant.
    default boolean
    Return true if this variant has a component patch.
    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.
    withComponents(net.minecraft.core.component.DataComponentPatch patch)
    Creates a copy of this TransferVariant with the provided component patch applied.

    Methods inherited from interface net.minecraft.core.component.DataComponentGetter

    getTyped

    Methods inherited from interface net.minecraft.core.component.DataComponentHolder

    get, getAllOfType, getOrDefault, has

    Methods inherited from interface net.minecraft.core.TypedInstance

    is, is, is, is, is, tags, typeHolder
  • 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.
    • getComponentsPatch

      net.minecraft.core.component.DataComponentPatch getComponentsPatch()
      Returns:
      The DataComponentPatch of this variant.
    • getComponents

      net.minecraft.core.component.DataComponentMap getComponents()
      Specified by:
      getComponents in interface net.minecraft.core.component.DataComponentHolder
      Returns:
      The DataComponentMap of this variant.
    • hasComponents

      default boolean hasComponents()
      Return true if this variant has a component patch.
    • componentsMatch

      default boolean componentsMatch(net.minecraft.core.component.DataComponentPatch 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.
    • withComponents

      default TransferVariant<O> withComponents(net.minecraft.core.component.DataComponentPatch patch)
      Creates a copy of this TransferVariant with the provided component patch applied.
      Parameters:
      patch - the patch to apply
      Returns:
      the new variant with the patch applied