Class DataMapType<R,T>
java.lang.Object
net.neoforged.neoforge.registries.datamaps.DataMapType<R,T>
- Direct Known Subclasses:
AdvancedDataMapType
A registry data map contains data-driven object that can be attached to a registry object.
Data maps are registered to the RegisterDataMapTypesEvent
.
They are loaded from JSON files located at:
<map namespace>/data_maps/<registry namespace>/<registry path>/<map path>.json
The registry namespace
is omitted if it is "minecraft".
The structure of the json file is as follows:
{
"replace": false // If true, all previous data will be cleared.
// The values object is a map of registry entry ID / tag to data map values.
"values": {
"someobject:someid": {}, // The object being attached
"#somepath:sometag": {} // Tags are also supported. All objects in the tag will then receieve the same value
},
// Optional object. Entries specified here will be removed after the data of the current json file is attached
"remove": ["minecraft:carrot", "#minecraft:logs"]
}
Data maps support conditions both JSON-level and attachment-level through the "neoforge:value" object.
Data maps may be synced by specifying a networkCodec()
. If the map is mandatory
,
then vanilla clients (or any client that doesn't support this map) will not be able to connect.
Both datapack registries and normal, built-in registries support data maps.
You can access a data map using IRegistryExtension.getDataMap(DataMapType)
and IWithData.getData(DataMapType)
.
You can usually go through IWithData.getData(DataMapType) Holder} implementations in order to get the data of an object directly.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.mojang.serialization.Codec<T>
private final ResourceLocation
private final boolean
private final @Nullable com.mojang.serialization.Codec<T>
private final ResourceKey<Registry<R>>
-
Constructor Summary
ConstructorsConstructorDescriptionDataMapType
(ResourceKey<Registry<R>> registryKey, ResourceLocation id, com.mojang.serialization.Codec<T> codec, @Nullable com.mojang.serialization.Codec<T> networkCodec, boolean mandatorySync) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
R> DataMapType.Builder<T, R> builder
(ResourceLocation id, ResourceKey<Registry<R>> registry, com.mojang.serialization.Codec<T> codec) Returns a data map type builder.com.mojang.serialization.Codec<T>
codec()
Returns the codec used to decode values.id()
Returns the ID of this data map.boolean
Returnstrue
if this data map must be present on the client, andfalse
otherwise.@Nullable com.mojang.serialization.Codec<T>
Returns the codec used to sync values.Returns the key of the registry this data map is for.
-
Field Details
-
registryKey
-
id
-
codec
-
networkCodec
-
mandatorySync
private final boolean mandatorySync
-
-
Constructor Details
-
DataMapType
DataMapType(ResourceKey<Registry<R>> registryKey, ResourceLocation id, com.mojang.serialization.Codec<T> codec, @Nullable @Nullable com.mojang.serialization.Codec<T> networkCodec, boolean mandatorySync)
-
-
Method Details
-
builder
public static <T,R> DataMapType.Builder<T,R> builder(ResourceLocation id, ResourceKey<Registry<R>> registry, com.mojang.serialization.Codec<T> codec) Returns a data map type builder.- Type Parameters:
T
- the type of the data mapR
- the registry the data is for- Parameters:
id
- the ID of the data mapregistry
- the key of the registry the data map is forcodec
- the codec used to deserialize the values from JSON- Returns:
- a data map type builder
-
registryKey
Returns the key of the registry this data map is for.- Returns:
- the key of the registry this data map is for
-
id
Returns the ID of this data map.- Returns:
- the ID of this data map
-
codec
Returns the codec used to decode values.- Returns:
- the codec used to decode values
-
networkCodec
Returns the codec used to sync values.- Returns:
- the codec used to sync values
-
mandatorySync
public boolean mandatorySync()Returnstrue
if this data map must be present on the client, andfalse
otherwise.- Returns:
true
if this data map must be present on the client, andfalse
otherwise
-