You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/datamaps/index.md
+31-8Lines changed: 31 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
A registry data map contains data-driven, reloadable objects that can be attached to a registry object.
4
4
This system allows more easily data-driving game behaviour, as they provide functionality such as syncing or conflict resolution, leading to a better and more configurable user experience.
5
5
6
-
You can think of tags as entry->boolean maps, while data maps are more flexible entry->object maps.
6
+
You can think of tags as registry object ➜ boolean maps, while data maps are more flexible registry object ➜ object maps.
7
7
8
8
A data map can be attached to both static, built-in, registries and dynamic data-driven datapack registries.
9
9
@@ -12,7 +12,7 @@ Data maps support reloading through the use of the `/reload` command or any othe
12
12
## Registration
13
13
A data map type should be statically created and then registered to the `RegisterDataMapTypesEvent` (which is fired on the mod event bus). The `DataMapType` can be created using a `DataMapType$Builder`, through `DataMapType#builder`.
14
14
15
-
The builder provides a `syced` method which can be used to mark a data map as synced and have it sent to clients.
15
+
The builder provides a `synced` method which can be used to mark a data map as synced and have it sent to clients.
16
16
17
17
A simple `DataMapType` has two generic arguments: `R` (the type of the registry the data map is for) and `T` (the values that are being attached). A data map of `SomeObject`s that are attached to `Item`s can, as such, be represented as `DataMapType<Item, SomeObject>`.
18
18
@@ -48,8 +48,17 @@ A synced data map will have its values synced to clients. A data map can be mark
48
48
The values of the data map will then be synced using the `networkCodec`.
49
49
If the `mandatory` flag is set to `true`, clients that do not support the data map (including Vanilla clients) will not be able to connect to the server, nor vice-versa. A non-mandatory data map is, on the other side, optional, so it will not prevent any clients from joining.
50
50
51
+
:::tip
52
+
A separate network codec allows for packet sizes to be smaller, as you can choose what data to send, and in what format. Otherwise the default codec can be used.
53
+
:::
54
+
51
55
## JSONStructure and location
52
-
Data maps are loaded from a JSON file located at `:mapNamespace/data_maps/:registryNamespace/:registryPath/:mapPath.json`.
56
+
Data maps are loaded from a JSON file located at `:mapNamespace/data_maps/:registryNamespace/:registryPath/:mapPath.json`, where:
57
+
- `mapNamespace` is the namespace of the ID of the data map
58
+
- `mapPath` is the path of the ID of the data map
59
+
- `registryNamespace` is the namespace of the ID of the registry
60
+
- `registryPath` is the path of the ID of the registry
61
+
53
62
For more information, please [check out the dedicated page](./structure.md).
54
63
55
64
## Usage
@@ -83,14 +92,24 @@ Advanced data maps are data maps which have added functionality. Namely, the abi
83
92
`AdvancedDataMapType` have one more generic besides `T` and `R`: `VR extends DataMapValueRemover<R, T>`. This additional generic allows you to datagen remove objects with increased type safety.
84
93
85
94
### Creation
86
-
You create an `AdvancedDataMapType` using `AdvancedDataMapType#builder`. Unlike the normal builder, the builder returned by that method will have two more methods (`merger` and `remover`), and it will return an `AdvancedDataMapType`.
87
-
88
-
Registration methods remain the same.
95
+
You create an `AdvancedDataMapType` using `AdvancedDataMapType#builder`. Unlike the normal builder, the builder returned by that method will have two more methods (`merger` and `remover`), and it will return an `AdvancedDataMapType`. Registration methods remain the same.
89
96
90
97
### Mergers
91
98
An advanced data map can provide a `DataMapValueMerger` through `AdvancedDataMapType#merger`. This merger will be used to handle conflicts between data packs that attempt to attach a value to the same object.
92
99
The merger will be given the two conflicting values, and their sources (as an `Either<TagKey<R>, ResourceKey<R>>` since values can be attached to all entries within a tag, not just individual entries), and is expected to return the value that will actually be attached.
93
-
Generally, mergers should simply merge the values, and should not perform "hard" overwrites unless necessary (i.e. if merging isn't possible).If a pack wants to bypass the merger, it can do so by specifying the object-level `replace` field.
100
+
Generally, mergers should simply merge the values, and should not perform "hard" overwrites unless necessary (i.e. if merging isn't possible).If a pack wants to bypass the merger, it can do so by specifying the object-level `replace` field.
101
+
102
+
Let's imagine a scenario where we have a data map that attaches integers to items:
103
+
```java
104
+
public class IntMerger implements DataMapValueMerger<Item, Integer> {
The above merger will merge the values if two datapacks attach to the same object. So if the first pack attaches the value `12` to `minecraft:carrot`, and the second pack attaches the value `15` to `minecraft:carrot`, the final value will be `27`. However, if the second pack specifies the object-level `replace` field, the final value will be `15` as the merger won't be invoked.
94
113
95
114
We provide some default mergers for merging lists, sets and maps in `DataMapValueMerger`.
96
115
@@ -166,4 +185,8 @@ public class DropHealingGen extends DataMapProvider {
There are `add` overloads that accept raw `ResourceLocation`s if you want to attach values to objects added by optional dependencies. In that case you should also provide [a loading condition](../resources/server/conditional) through the var-args parameter to avoid crashes.
Copy file name to clipboardExpand all lines: docs/datamaps/structure.md
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,9 @@ Examples:
20
20
## Global `replace` field
21
21
The JSON file has an optional, global `replace` field, which is similar to tags, and when `true` will remove all previously attached values of that data map. This is useful for datapacks that want to completely change the entire data map.
22
22
23
+
## Loading conditions
24
+
Data map files support [loading conditions](../resources/server/conditional) both at root-level and at entry-level through a `neoforge:conditions` array.
25
+
23
26
## Adding values
24
27
Values can be attached to objects using the `values` map. Each key will represent either the ID of an individual registry entry to attach the value to, or a tag key, preceeded by `#`. If it is a tag, the same value will be attached to all entries in that tag.
0 commit comments