Interface DataComponentMap
- All Superinterfaces:
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).
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interface -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic DataComponentMapapplyPatch(DataComponentMap prototype, DataComponentMap patch) Resolves a component patch against a prototype into an absolute component map.static DataComponentMap.Builderbuilder()static Codec<DataComponentMap> codec(IntFunction<DataComponent<?>> idToType, Function<String, DataComponent<?>> nameToType) Creates a network type for the given component type.static DataComponentMapdiff(DataComponentMap prototype, DataComponentMap patch) Minimizes a component patch relative to a prototype without changing its resolved result.entrySet()<T> Tget(DataComponentMap prototype, DataComponent<T> component) Does a 'patch'ed get against the given prototype.booleanhas(DataComponentMap prototype, DataComponent<?> component) Does a 'patch'ed has against the given prototype.booleanisEmpty()static NetworkBuffer.Type<DataComponentMap> networkType(IntFunction<DataComponent<?>> idToType) static Codec<DataComponentMap> patchCodec(IntFunction<DataComponent<?>> idToType, Function<String, DataComponent<?>> nameToType) Creates a network type for the given component type.static NetworkBuffer.Type<DataComponentMap> patchNetworkType(IntFunction<DataComponent<?>> idToType, boolean trusted) Creates a network type for the given component type.remove(DataComponent<?> component) Removes the component from the map (or patch).reset(DataComponent<?> component) Removes the explicit override for a component from this patch.default DataComponentMapset(DataComponent<Unit> component) <T> DataComponentMapset(DataComponent<T> component, T value) Adds the component, overwriting any prior value if present.Methods inherited from interface DataComponent.Holder
get, get, has
-
Field Details
-
EMPTY
-
-
Method Details
-
builder
-
patchBuilder
-
networkType
@Internal static NetworkBuffer.Type<DataComponentMap> networkType(IntFunction<DataComponent<?>> idToType) -
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
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 againstpatch- the component overrides to minimize- Returns:
- the minimal equivalent patch, or
EMPTYwhen no explicit overrides are needed
-
applyPatch
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 againstpatch- the component overrides to apply- Returns:
- the resolved component map, or
prototypewhen the patch is empty
-
isEmpty
boolean isEmpty() -
has
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 tocomponent- The component to check- Returns:
- True if the component is present (taking into account the prototype).
-
get
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 tocomponent- The component to get- Returns:
- The value of the component, or null if not present (taking into account the prototype).
-
set
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 setvalue- value of T- Returns:
- A new map with the component set to the value
-
set
-
remove
Removes the component from the map (or patch).- Parameters:
component- The component to remove- Returns:
- A new map with the component removed
-
reset
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
Collection<DataComponent.Value> entrySet() -
toBuilder
DataComponentMap.Builder toBuilder() -
toPatchBuilder
DataComponentMap.PatchBuilder toPatchBuilder()
-