Update README.MD

This commit is contained in:
2025-11-07 16:51:03 +01:00
parent 21c1aadb31
commit 50b56ee5c4

View File

@@ -17,21 +17,31 @@ dependencies {
``` ```
Then add dacl_version to your `gradle.properties`, you can check the version on the [versions page](https://modrinth.com/mod/dacl/versions). Then add dacl_version to your `gradle.properties`, you can check the version on the [versions page](https://modrinth.com/mod/dacl/versions).
If you do not want to include this library in your mods folder, replace `modCompileOnly` with `modImplementation`, it is then included inside your mod. If you want to bundle this library with your mod, replace `modCompileOnly` with `modImplementation`.
## Creating options ## Creating options
Start by creating a new Config class, you can then add your options as public static classes to this class to access them later. You can create options like so: Start by creating your mod entrypoint, make sure it implements ModInitializer. You can then add your options as public static fields to this class to access them later. You can create options like so:
```java ```java
public static final BoolOption TEST_BOOL_OPT = new BoolOption("Test boolean option", "test_bool_opt", false); public static final BoolOption TEST_BOOL_OPT = new BoolOption(Text.literal("Test boolean option"), "test_bool_opt", false);
public static final IntOption TEST_INT_OPT = new IntOption("Test integer option", "test_int_opt", 1); public static final IntOption TEST_INT_OPT = new IntOption(Text.literal("Test integer option"), "test_int_opt", 1);
public static final FloatOption TEST_FLOAT_OPT = new FloatOption("Test float option", "test_float_opt", 1.F); public static final FloatOption TEST_FLOAT_OPT = new FloatOption(Text.literal("Test float option"), "test_float_opt", 1.F);
``` ```
The first parameter is the text displayed in the config UI, the second parameter is the unique identifier of the option and the third parameter is the default value. The first parameter is the text displayed in the config UI, the second parameter is the unique identifier of the option and the third parameter is the default value.
Then add this class to your `fabric.mod.json` so it loads at start:
```json
"entrypoints": {
"main": [
"com.kasetoatz.mymod.MyMod"
]
}
```
You can replace main with client or server if your mod is client/server side only.
## Validators ## Validators
For options with an input field you can add a fourth parameter with an `AbstractValidator` to add restrictions to the option's value. To create an integer option that must be between 1 and 100 we can do that like this: For options with an input field you can add a fourth parameter with an `AbstractValidator` to add restrictions to the option's value. To create an integer option that must be between 1 and 100 we can do that like this:
```java ```java
public static final IntOption CLAMPED_INT_OPT = new IntOption("Clamped integer option", "clamp_int_opt", 50, new RangeValidator<>(1, 100)); public static final IntOption CLAMPED_INT_OPT = new IntOption(Text.literal("Clamped integer option"), "clamp_int_opt", 50, new RangeValidator<>(1, 100));
``` ```
You can also pass null to either the lower or higher bound in `RangeValidator` to remove that restriction. You can also pass null to either the lower or higher bound in `RangeValidator` to remove that restriction.
@@ -53,7 +63,7 @@ bool enabled = TEST_BOOL_OPT.getValue();
## Sub options ## Sub options
You can also add sub options that are basically an entirely new screen with it's own options. To create this we can use the `builder` method of the `SubOption` class. We will use CLAMPED_INT_OPT as one of the sub options. You can also add sub options that are basically an entirely new screen with it's own options. To create this we can use the `builder` method of the `SubOption` class. We will use CLAMPED_INT_OPT as one of the sub options.
```java ```java
public static final SubOption TEST_SUB_OPT = SubOption.builder("Sub Screen Title", "sub_opt") public static final SubOption TEST_SUB_OPT = SubOption.builder(Text.literal("Sub Screen Title"), "sub_opt")
.withOption(CLAMPED_INT_OPT) .withOption(CLAMPED_INT_OPT)
.build(); .build();
``` ```
@@ -62,35 +72,40 @@ We can now add this option to the config builder aswell. We can nest these sub o
## Modmenu support ## Modmenu support
To add our newly created config screen to `modmenu`, we must first add it as a dependency to our mod, you can read how to do so [here](https://modrinth.com/mod/modmenu). To add our newly created config screen to `modmenu`, we must first add it as a dependency to our mod, you can read how to do so [here](https://modrinth.com/mod/modmenu).
Now we can modify our `fabric.mod.json` to set our class as a `modmenu` entrypoint: Now we create a new class for our mod menu integration, implement `ModMenuApi` into this class and override `getModConfigScreenFactory` to return our config UI.
```json
"entrypoints": {
"client": ...,
"server": ...,
"modmenu": [
"com.kasetoatz.mymod.MyConfig"
]
}
```
We can then implement `ModMenuApi` into our class and override `getModConfigScreenFactory` to return our config UI.
```java ```java
public class ModMenuIntegration implements ModMenuApi
{
@Override @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() public ConfigScreenFactory<?> getModConfigScreenFactory()
{ {
return CONFIG::getUI; return CONFIG::getUI;
} }
}
``` ```
## Example Now we can modify our `fabric.mod.json` to set our new class as a `modmenu` entrypoint:
```java ```json
public class MyConfig implements ModMenuApi "entrypoints": {
{ "main": [
public static final BoolOption TEST_BOOL_OPT = new BoolOption("Test boolean option", "test_bool_opt", false); "com.kasetoatz.mymod.MyMod"
public static final IntOption TEST_INT_OPT = new IntOption("Test integer option", "test_int_opt", 1); ],
public static final FloatOption TEST_FLOAT_OPT = new FloatOption("Test float option", "test_float_opt", 1.F); "modmenu": [
"com.kasetoatz.mymod.ModMenuIntegration"
]
}
```
public static final IntOption CLAMPED_INT_OPT = new IntOption("Clamped integer option", "clamp_int_opt", 50, new RangeValidator<>(1, 100)); ## Full Example
public static final SubOption TEST_SUB_OPT = SubOption.builder("Sub Screen Title", "sub_opt") ```java
public class MyMod implements ModInitializer
{
public static final BoolOption TEST_BOOL_OPT = new BoolOption(Text.literal("Test boolean option"), "test_bool_opt", false);
public static final IntOption TEST_INT_OPT = new IntOption(Text.literal("Test integer option"), "test_int_opt", 1);
public static final FloatOption TEST_FLOAT_OPT = new FloatOption(Text.literal("Test float option"), "test_float_opt", 1.F);
public static final IntOption CLAMPED_INT_OPT = new IntOption(Text.literal("Clamped integer option"), "clamp_int_opt", 50, new RangeValidator<>(1, 100));
public static final SubOption TEST_SUB_OPT = SubOption.builder(Text.literal("Sub Screen Title"), "sub_opt")
.withOption(CLAMPED_INT_OPT) .withOption(CLAMPED_INT_OPT)
.build(); .build();
@@ -101,6 +116,17 @@ public class MyConfig implements ModMenuApi
.withOption(TEST_SUB_OPT) .withOption(TEST_SUB_OPT)
.build() .build()
@Override
public void onInitialize()
{
...
}
}
```
```java
public class ModMenuIntegration implements ModMenuApi
{
@Override @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() public ConfigScreenFactory<?> getModConfigScreenFactory()
{ {