Interface ComponentHolder

All Known Implementing Classes:
ItemStack

public interface ComponentHolder
An object that holds components. Note that this interface does not expose methods to modify the held components.

Component holders usually have "base" components and the overrides to the base (usually referred to as "changes"). The overrides may set additional components, modify the values from the base-provided default, or "unset"/remove base values. Methods in this interface expose the final value, after applying the changes.

See Also:
Mappings:
Namespace Name
named net/minecraft/component/ComponentHolder
intermediary net/minecraft/class_9322
official kh
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    Returns whether the held components include type.
    default <T> T
    get(DataComponentType<? extends T> type)
    Returns the value for the component type, or null if the component is missing.
     
    default <T> T
    getOrDefault(DataComponentType<? extends T> type, T fallback)
    Returns the value for the component type, or fallback if the component is missing.
  • Method Details

    • getComponents

      ComponentMap getComponents()
      Mappings:
      Namespace Name Mixin selector
      named getComponents Lnet/minecraft/component/ComponentHolder;getComponents()Lnet/minecraft/component/ComponentMap;
      intermediary method_57353 Lnet/minecraft/class_9322;method_57353()Lnet/minecraft/class_9323;
      official a Lkh;a()Lki;
    • get

      @Nullable default <T> T get(DataComponentType<? extends T> type)
      Returns the value for the component type, or null if the component is missing.

      The returned value should never be mutated.

      Returns:
      the value for the component type, or null if the component is missing
      Mappings:
      Namespace Name Mixin selector
      named get Lnet/minecraft/component/ComponentHolder;get(Lnet/minecraft/component/DataComponentType;)Ljava/lang/Object;
      intermediary method_57824 Lnet/minecraft/class_9322;method_57824(Lnet/minecraft/class_9331;)Ljava/lang/Object;
      official a Lkh;a(Lkl;)Ljava/lang/Object;
    • getOrDefault

      default <T> T getOrDefault(DataComponentType<? extends T> type, T fallback)
      Returns the value for the component type, or fallback if the component is missing.

      This method does not initialize the components with fallback. The returned value should never be mutated.

      Returns:
      the value for the component type, or fallback if the component is missing
      Mappings:
      Namespace Name Mixin selector
      named getOrDefault Lnet/minecraft/component/ComponentHolder;getOrDefault(Lnet/minecraft/component/DataComponentType;Ljava/lang/Object;)Ljava/lang/Object;
      intermediary method_57825 Lnet/minecraft/class_9322;method_57825(Lnet/minecraft/class_9331;Ljava/lang/Object;)Ljava/lang/Object;
      official a Lkh;a(Lkl;Ljava/lang/Object;)Ljava/lang/Object;
    • contains

      default boolean contains(DataComponentType<?> type)
      Returns whether the held components include type.
      Returns:
      whether the held components include type
      Implementation Note:
      This is implemented as get(type) != null.
      Mappings:
      Namespace Name Mixin selector
      named contains Lnet/minecraft/component/ComponentHolder;contains(Lnet/minecraft/component/DataComponentType;)Z
      intermediary method_57826 Lnet/minecraft/class_9322;method_57826(Lnet/minecraft/class_9331;)Z
      official b Lkh;b(Lkl;)Z