Class ExpandDataComponentHolder

java.lang.Object
com.blamejared.crafttweaker.natives.component.ExpandDataComponentHolder

@ZenRegister public class ExpandDataComponentHolder extends Object
An interface that stores DataComponents
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    getComponent(net.minecraft.core.component.DataComponentHolder internal, Class<T> tClass, net.minecraft.core.component.DataComponentType<T> type)
    Gets the data identified by the given DataComponentType.
    static net.minecraft.core.component.DataComponentMap
    getComponents(net.minecraft.core.component.DataComponentHolder internal)
    Gets the internal map of ComponentType -> Data
    static IData
    getJsonComponent(net.minecraft.core.component.DataComponentHolder internal, net.minecraft.core.component.DataComponentType type)
    Get an arbitrary component by type.
    static <T> T
    getOrDefault(net.minecraft.core.component.DataComponentHolder internal, Class<T> tClass, net.minecraft.core.component.DataComponentType<T> type, T defaultValue)
    Gets the data identified by the given DataComponentType.
    static boolean
    has(net.minecraft.core.component.DataComponentHolder internal, net.minecraft.core.component.DataComponentType<?> type)
    Checks whether the holder contains the given DataComponent, which is indentified by the type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExpandDataComponentHolder

      public ExpandDataComponentHolder()
  • Method Details

    • getComponents

      public static net.minecraft.core.component.DataComponentMap getComponents(net.minecraft.core.component.DataComponentHolder internal)
      Gets the internal map of ComponentType -> Data
      Returns:
      The internal map.
    • has

      public static boolean has(net.minecraft.core.component.DataComponentHolder internal, net.minecraft.core.component.DataComponentType<?> type)
      Checks whether the holder contains the given DataComponent, which is indentified by the type.
      Parameters:
      type - The componenttype to check for.
      Returns:
      Whether the holder contains the DataComponent.
      DocParam:
      type invalid input: '<'componenttype:minecraft:stack_size>
    • getOrDefault

      public static <T> T getOrDefault(net.minecraft.core.component.DataComponentHolder internal, Class<T> tClass, net.minecraft.core.component.DataComponentType<T> type, T defaultValue)
      Gets the data identified by the given DataComponentType. If the ComponentHolder does not have the Component, then the default value is returned.
      Type Parameters:
      T - The type of the ComponentType
      Parameters:
      tClass - The type of the class stored within the component.
      type - The componenttype to get
      defaultValue - The default value to return in the event that the holder does not have the component.
      Returns:
      The value if it exists or the default value.
      DocParam:
      int?, type invalid input: '<'componenttype:minecraft:stack_size>, defaultValue 64
    • getComponent

      public static <T> T getComponent(net.minecraft.core.component.DataComponentHolder internal, Class<T> tClass, net.minecraft.core.component.DataComponentType<T> type)
      Gets the data identified by the given DataComponentType. If the ComponentHolder does not have the Component, then null is returned.
      Type Parameters:
      T - The type of the class stored within the component.
      Parameters:
      type - The componenttype to get
      Returns:
      The value if it exists or null.
      DocParam:
      int?, type invalid input: '<'componenttype:minecraft:stack_size>, defaultValue 64
    • getJsonComponent

      public static IData getJsonComponent(net.minecraft.core.component.DataComponentHolder internal, net.minecraft.core.component.DataComponentType type)
      Get an arbitrary component by type. This is useful to interact with components added by mods that do not have a CraftTweaker method. If the ComponentAccess does not have the type, an exception is thrown. If the ComponentAccess is not serializable, an exception is thrown.
      Parameters:
      type - The componenttype to target.
      Returns:
      A IData representation of the Serialized DataComponent
      DocParam:
      type invalid input: '<'componenttype:minecraft:stack_size>