Interface FabricComponentMapBuilder


@NonExtendable public interface FabricComponentMapBuilder
Fabric-provided extensions for ComponentMap.Builder.

Note: This interface is automatically implemented on all component map builders via Mixin and interface injection.

  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    getOrCreate(ComponentType<T> type, Supplier<@NotNull T> fallback)
    Gets the current value for the component type in the builder, or creates and adds a new value if it is not present.
    default <T> T
    getOrDefault(ComponentType<T> type, T defaultValue)
    Gets the current value for the component type in the builder, or creates and adds a new value if it is not present.
    default <T> List<T>
    For list component types specifically, returns a mutable list of values currently held in the builder for the given component type.
  • Method Details

    • getOrCreate

      default <T> T getOrCreate(ComponentType<T> type, Supplier<@NotNull T> fallback)
      Gets the current value for the component type in the builder, or creates and adds a new value if it is not present.
      Type Parameters:
      T - The type of the component data
      Parameters:
      type - The component type
      fallback - The supplier for the default data value if the type is not in this map yet. The value given by this supplier may not be null.
      Returns:
      Returns the current value in the map builder, or the default value provided by the fallback if not present
      See Also:
    • getOrDefault

      default <T> T getOrDefault(ComponentType<T> type, @NotNull T defaultValue)
      Gets the current value for the component type in the builder, or creates and adds a new value if it is not present.
      Type Parameters:
      T - The type of the component data
      Parameters:
      type - The component type
      defaultValue - The default data value if the type is not in this map yet
      Returns:
      Returns the current value in the map builder, or the default value if not present
    • getOrEmpty

      default <T> List<T> getOrEmpty(ComponentType<List<T>> type)
      For list component types specifically, returns a mutable list of values currently held in the builder for the given component type. If the type is not registered to this builder yet, this will create and add a new empty list to the builder for the type, and return that.
      Type Parameters:
      T - The type of the component entry data
      Parameters:
      type - The component type. The component must be a list-type.
      Returns:
      Returns a mutable list of values for the type.