Skip to content

Commit 455ff66

Browse files
committed
Some review comments
1 parent b372542 commit 455ff66

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

docs/datamaps/index.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A registry data map contains data-driven, reloadable objects that can be attached to a registry object.
44
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.
55

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.
77

88
A data map can be attached to both static, built-in, registries and dynamic data-driven datapack registries.
99

@@ -12,7 +12,7 @@ Data maps support reloading through the use of the `/reload` command or any othe
1212
## Registration
1313
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`.
1414

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.
1616

1717
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>`.
1818

@@ -48,8 +48,17 @@ A synced data map will have its values synced to clients. A data map can be mark
4848
The values of the data map will then be synced using the `networkCodec`.
4949
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.
5050

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+
5155
## JSON Structure 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+
5362
For more information, please [check out the dedicated page](./structure.md).
5463

5564
## Usage
@@ -83,14 +92,24 @@ Advanced data maps are data maps which have added functionality. Namely, the abi
8392
`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.
8493
8594
### 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.
8996
9097
### Mergers
9198
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.
9299
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> {
105+
@Override
106+
public Integer merge(Registry<Item> registry, Either<TagKey<Item>, ResourceKey<Item>> first, Integer firstValue, Either<TagKey<Item>, ResourceKey<Item>> second, Integer secondValue) {
107+
//highlight-next-line
108+
return firstValue + secondValue;
109+
}
110+
}
111+
```
112+
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.
94113

95114
We provide some default mergers for merging lists, sets and maps in `DataMapValueMerger`.
96115

@@ -166,4 +185,8 @@ public class DropHealingGen extends DataMapProvider {
166185
.add(Items.ACACIA_BOAT.builtInRegistryHolder(), new DropHealing(1, 0.1f), false);
167186
}
168187
}
169-
```
188+
```
189+
190+
:::tip
191+
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.
192+
:::

docs/datamaps/structure.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Examples:
2020
## Global `replace` field
2121
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.
2222

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+
2326
## Adding values
2427
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.
2528
The key will be the object to attach.

0 commit comments

Comments
 (0)