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: libraries/config/README.md
+83-30Lines changed: 83 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,10 @@ The Config API provides a framework for building and storing configs for your mo
4
4
5
5
## Creating a config
6
6
7
-
The easiest way to create a config is to extend the `net.ornithemc.osl.config.api.config.BaseConfig` class:
7
+
The easiest way to create a config is to extend the `net.ornithemc.osl.config.api.config.BaseConfig` class.
8
+
In order to make serialization work, you must register all your options in the `init` method. With the `registerOptions(String group, Option... options)` method, you can register an entire option group at once.
9
+
An option group is a collection of options with a name. It's a useful tool to categoryize your options if you have
10
+
many. You can of course also add all your options in just one group.
8
11
9
12
```java
10
13
packagecom.example;
@@ -90,6 +93,11 @@ The API allows you to provide custom option types, so long as you register the r
90
93
Network serializers must be provided, as well as file serializers for the type your config uses.
91
94
These serializers should be registered in your mod's entrypoint.
92
95
96
+
Custom options of immutable types are the most straightforward. Immutable types are classes that do not
97
+
allow their data to be modified. Immutable types include primitives such as `boolean`, `float`, and `int`,
98
+
but classes such as `String`, `UUID`, and `Path` are also examples of immutable types. Options for these
99
+
types should made by extending the `BaseOption` class.
100
+
93
101
```java
94
102
packagecom.example;
95
103
@@ -108,66 +116,111 @@ public class CookieOption extends BaseOption<Cookie> {
108
116
}
109
117
}
110
118
```
119
+
120
+
Custom options of mutable types are more involved. Mutable types are classes that allow their data to be modified.
121
+
Mutable types include collections like `List` and `Map`, but classes such as Minecraft's `NbtList` and `NbtCompound`
122
+
are also examples of mutable types. Options for these types should be made by extending the `ModifiableOption` class.
123
+
Using this class does require that your objects of your custom type can be converted to a 'modifiable view' (which it
124
+
most likely is by default) and an 'unmodifiable view'. The reason for this is that the config should be able keep track
125
+
of when the option's value is modified. Providing an unmodifiable view allows the option to force modifications to happen
0 commit comments