Package net.fabricmc.fabric.api.item.v1
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 TypeMethodDescriptiondefault booleancontains(ComponentType<?> type) Checks if a component type has been registered to this builder.default <T> TgetOrCreate(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> TgetOrDefault(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> 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.
-
Method Details
-
getOrCreate
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 typefallback- 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
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 typedefaultValue- 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
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.
-
contains
Checks if a component type has been registered to this builder.- Parameters:
type- The component type to check- Returns:
- Returns true if the type has been registered to this builder, false otherwise
-