Interface DataComponentMap

All Superinterfaces:
DataComponent.Holder

@Experimental public sealed interface DataComponentMap extends DataComponent.Holder

Represents any container of DataComponents.

This type is capable of storing a patch of added and removed components on top of a 'prototype', or existing set of components. See diff(DataComponentMap, DataComponentMap).

  • Field Details

  • Method Details

    • builder

      static DataComponentMap.Builder builder()
    • patchBuilder

      static DataComponentMap.PatchBuilder patchBuilder()
    • networkType

    • codec

      @Internal static Codec<DataComponentMap> codec(IntFunction<DataComponent<?>> idToType, Function<String, DataComponent<?>> nameToType)
      Creates a network type for the given component type. For internal use only, get the value from the target component class.
    • patchNetworkType

      @Internal static NetworkBuffer.Type<DataComponentMap> patchNetworkType(IntFunction<DataComponent<?>> idToType, boolean trusted)
      Creates a network type for the given component type. For internal use only, get the value from the target component class.
    • patchCodec

      @Internal static Codec<DataComponentMap> patchCodec(IntFunction<DataComponent<?>> idToType, Function<String, DataComponent<?>> nameToType)
      Creates a network type for the given component type. For internal use only, get the value from the target component class.
    • diff

      static DataComponentMap diff(DataComponentMap prototype, DataComponentMap patch)
      Minimizes a component patch relative to a prototype without changing its resolved result. Overrides matching the prototype and removals of components absent from the prototype are omitted; components not mentioned by the patch remain inherited from the prototype.
      Parameters:
      prototype - the component defaults to compare against
      patch - the component overrides to minimize
      Returns:
      the minimal equivalent patch, or EMPTY when no explicit overrides are needed
    • applyPatch

      static DataComponentMap applyPatch(DataComponentMap prototype, DataComponentMap patch)
      Resolves a component patch against a prototype into an absolute component map. Components set by the patch replace prototype values, components removed by the patch are omitted, and components not mentioned by the patch retain their prototype values.
      Parameters:
      prototype - the component defaults to resolve against
      patch - the component overrides to apply
      Returns:
      the resolved component map, or prototype when the patch is empty
    • isEmpty

      boolean isEmpty()
    • has

      boolean has(DataComponentMap prototype, DataComponent<?> component)
      Does a 'patch'ed has against the given prototype. That is, this map is treated as the primary source, but if unspecified, the given prototype is used as a fallback.
      Parameters:
      prototype - The prototype to fall back to
      component - The component to check
      Returns:
      True if the component is present (taking into account the prototype).
    • get

      @Nullable <T> T get(DataComponentMap prototype, DataComponent<T> component)
      Does a 'patch'ed get against the given prototype. That is, this map is treated as the primary source, but if unspecified, the given prototype is used as a fallback.
      Type Parameters:
      T - The type of the component
      Parameters:
      prototype - The prototype to fall back to
      component - The component to get
      Returns:
      The value of the component, or null if not present (taking into account the prototype).
    • set

      <T> DataComponentMap set(DataComponent<T> component, T value)
      Adds the component, overwriting any prior value if present.
      Note: DataComponent.freeze(Object) will be called, so identity may be mutated.
      Type Parameters:
      T - the data component type
      Parameters:
      component - component to set
      value - value of T
      Returns:
      A new map with the component set to the value
    • set

      default DataComponentMap set(DataComponent<Unit> component)
    • remove

      DataComponentMap remove(DataComponent<?> component)
      Removes the component from the map (or patch).
      Parameters:
      component - The component to remove
      Returns:
      A new map with the component removed
    • reset

      DataComponentMap reset(DataComponent<?> component)
      Removes the explicit override for a component from this patch.

      This operation is only meaningful for component patches. When the patch is applied to a prototype, the component will resolve to the prototype value.

      Parameters:
      component - the component whose override should be reset
      Returns:
      a new patch without an override for the component, or this patch if none was present
    • entrySet

    • toBuilder

    • toPatchBuilder