https://github.com/ephys/cookiecore
Utils for my mods
https://github.com/ephys/cookiecore
Last synced: 12 months ago
JSON representation
Utils for my mods
- Host: GitHub
- URL: https://github.com/ephys/cookiecore
- Owner: ephys
- Created: 2014-07-29T11:01:05.000Z (almost 12 years ago)
- Default Branch: 1.18.2
- Last Pushed: 2022-07-18T17:02:53.000Z (almost 4 years ago)
- Last Synced: 2025-04-07T17:11:36.555Z (about 1 year ago)
- Language: Java
- Size: 449 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CookieCore
Library mod for ephys' mods.
## Config Generation
In the constructor of your mod, add `ConfigSynchronizer.synchronizeConfig();` (`be.ephys.cookiecore.config.ConfigSynchronizer`) to launch config synchronization for your mod.
Then in any class, you can declare static configuration fields:
```java
class MyFeature {
@Config(name = "myfeature.enabled", description = "Enable 'MyFeature'")
@Config.BooleanDefault(value = true)
public static ForgeConfigSpec.BooleanValue enabled;
}
```
Fields annotated with `@Config` + `@Config.Default` will be set to an instance of `ForgeConfigSpec.ConfigValue` that you can use.
One of the `@Config.Default` annotations *must* be specified.
### Supported config types
**string:**
```java
class MyFeature {
@Config(name = "namespace.subnamespace.key")
@Config.StringDefault("default value")
public static ForgeConfigSpec.ConfigValue myConfigValue;
}
```
**string list:**
*important*: Due to limitations in both the TOML parser, and Java annotations, the `StringListDefault` accepts an ARRAY of strings,
but the `ForgeConfigSpec.ConfigValue<>` must use a `List` as its generic!
```java
class MyFeature {
@Config(name = "namespace.subnamespace.key")
@Config.StringListDefault({"value1", "value2"})
public static ForgeConfigSpec.ConfigValue> myConfigValue;
}
```
**boolean:**
```java
class MyFeature {
@Config(name = "myfeature.enabled", description = "Enable 'MyFeature'")
@Config.BooleanDefault(value = true)
public static ForgeConfigSpec.BooleanValue enabled;
}
```
**int:**
```java
class MyFeature {
@Config(name = "range_computation.base_range", description = "What is the beacon base range?")
@Config.IntDefault(10)
public static ForgeConfigSpec.IntValue baseRange;
}
```
**long:**
```java
class MyFeature {
@Config(name = "range_computation.base_range", description = "What is the beacon base range?")
@Config.LongDefault(10)
public static ForgeConfigSpec.LongValue baseRange;
}
```
**double:**
```java
class MyFeature {
@Config(name = "range_computation.base_range", description = "What is the beacon base range?")
@Config.DoubleDefault(10.5)
public static ForgeConfigSpec.DoubleValue baseRange;
}
```
*enum:**
```java
class MyFeature {
@Config(name = "range_computation.vertical_range_type")
@Config.EnumDefault(value = "FullHeight", enumType = BeaconVerticalRangeType.class)
// BeaconVerticalRangeType is an enum
public static ForgeConfigSpec.EnumValue verticalRangeType;
}
```
### Escape hatch
If you need to build part of the config object yourself, you can use `@OnBuildConfig` on a *static* method.
```java
class MyFeature {
public static ForgeConfigSpec.IntValue configValue;
@OnBuildConfig()
public static onBuildConfig(ForgeConfigSpec.Builder rootBuilder) {
configValue = rootBuilder.defineInRange("my_config_value", 5, 0, 10);
}
}
```