Class StructuredDataContainer
java.lang.Object
com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer
Loosely represents Minecraft's data component patch, but may also be used for an item's full data components.
The most commonly used methods will ignore empty data (aka empty overrides that remove item defaults) since those will rarely be needed. These are:
get(StructuredDataKey)
set(StructuredDataKey, Object)
set(StructuredDataKey)
getNonEmptyData(StructuredDataKey)
hasValue(StructuredDataKey)
getData(StructuredDataKey)
and has(StructuredDataKey)
) will handle both empty and non-empty data.-
Constructor Summary
ConstructorDescriptionStructuredDataContainer
(StructuredData<?>[] dataArray) StructuredDataContainer
(Map<StructuredDataKey<?>, StructuredData<?>> data) -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Map<StructuredDataKey<?>,
StructuredData<?>> data()
<T> @Nullable T
get
(StructuredDataKey<T> key) Returns the non-empty value by id if present.<T> @Nullable StructuredData<T>
getData
(StructuredDataKey<T> key) Returns structured data by id if present, either empty or non-empty.<T> @Nullable StructuredData<T>
getNonEmptyData
(StructuredDataKey<T> key) Returns non-empty structured data by id if present.boolean
has
(StructuredDataKey<?> key) Returns whether there is data for the given key, either empty or non-empty.boolean
hasEmpty
(StructuredDataKey<?> key) Returns whether the structured data has an empty patch/override.boolean
hasValue
(StructuredDataKey<?> key) Returns whether there is non-empty data for the given key.void
remove
(StructuredDataKey<?> key) Removes data by the given key.<T,
V> void replace
(StructuredDataKey<T> key, StructuredDataKey<V> toKey, Function<T, @Nullable V> valueMapper) <T> void
replace
(StructuredDataKey<T> key, Function<T, @Nullable T> valueMapper) Updates the structured data by id if not empty.<T> void
replaceKey
(StructuredDataKey<T> key, StructuredDataKey<T> toKey) void
set
(StructuredDataKey<Unit> key) <T> void
set
(StructuredDataKey<T> key, T value) void
setEmpty
(StructuredDataKey<?> key) void
setIdLookup
(Protocol<?, ?, ?, ?> protocol, boolean mappedNames) Sets the lookup for serializer ids.toString()
void
-
Constructor Details
-
StructuredDataContainer
-
StructuredDataContainer
-
StructuredDataContainer
public StructuredDataContainer()
-
-
Method Details
-
get
Returns the non-empty value by id if present.- Type Parameters:
T
- data type- Parameters:
key
- serializer id- Returns:
- structured data
- See Also:
-
getData
Returns structured data by id if present, either empty or non-empty.- Type Parameters:
T
- data type- Parameters:
key
- serializer id- Returns:
- structured data
-
getNonEmptyData
Returns non-empty structured data by id if present.- Type Parameters:
T
- data type- Parameters:
key
- serializer id- Returns:
- non-empty structured data
-
set
-
set
-
setEmpty
-
replace
Updates the structured data by id if not empty.- Type Parameters:
T
- data type- Parameters:
key
- serializer idvalueMapper
- function to update existing data
-
replaceKey
-
replace
public <T,V> void replace(StructuredDataKey<T> key, StructuredDataKey<V> toKey, Function<T, @Nullable V> valueMapper) -
remove
Removes data by the given key.- Parameters:
key
- data key- See Also:
-
has
Returns whether there is data for the given key, either empty or non-empty.- Parameters:
key
- data key- Returns:
- whether there data for the given key
- See Also:
-
hasValue
Returns whether there is non-empty data for the given key.- Parameters:
key
- data key- Returns:
- whether there is non-empty data for the given key
-
hasEmpty
Returns whether the structured data has an empty patch/override.- Parameters:
key
- serializer id- Returns:
- whether the structured data has an empty patch/override
-
setIdLookup
Sets the lookup for serializer ids. Required to call most of the other methods.- Parameters:
protocol
- protocol to retreive the id of the serializer frommappedNames
- if the names are mapped (true if structures from the mapped version are added, false for the unmapped version)
-
updateIds
public void updateIds(Protocol<?, ?, ?, ?> protocol, it.unimi.dsi.fastutil.ints.Int2IntFunction rewriter) -
copy
-
data
-
toString
-