Class DataMapType<R,T>

java.lang.Object
net.neoforged.neoforge.registries.datamaps.DataMapType<R,T>
Direct Known Subclasses:
AdvancedDataMapType

public sealed class DataMapType<R,T> extends Object permits AdvancedDataMapType<R,T,VR>
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:
  • Field Details

    • registryKey

      private final ResourceKey<Registry<R>> registryKey
    • id

      private final ResourceLocation id
    • codec

      private final com.mojang.serialization.Codec<T> codec
    • networkCodec

      @Nullable private final @Nullable com.mojang.serialization.Codec<T> 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 map
      R - the registry the data is for
      Parameters:
      id - the ID of the data map
      registry - the key of the registry the data map is for
      codec - the codec used to deserialize the values from JSON
      Returns:
      a data map type builder
    • registryKey

      public ResourceKey<Registry<R>> registryKey()
      Returns the key of the registry this data map is for.
      Returns:
      the key of the registry this data map is for
    • id

      public ResourceLocation id()
      Returns the ID of this data map.
      Returns:
      the ID of this data map
    • codec

      public com.mojang.serialization.Codec<T> codec()
      Returns the codec used to decode values.
      Returns:
      the codec used to decode values
    • networkCodec

      @Nullable public @Nullable com.mojang.serialization.Codec<T> networkCodec()
      Returns the codec used to sync values.
      Returns:
      the codec used to sync values
    • mandatorySync

      public boolean mandatorySync()
      Returns true if this data map must be present on the client, and false otherwise.
      Returns:
      true if this data map must be present on the client, and false otherwise