Compare commits
29
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3cde2c8e7 | ||
|
|
6fa8e58665 | ||
|
|
ed4e9f6c19 | ||
|
|
24c0d9a039 | ||
|
|
6db4f12eed | ||
|
|
6ed97d4e00 | ||
|
|
3ecbae5593 | ||
|
|
d15fcd0732 | ||
|
|
bd2cc57eb9 | ||
|
|
539d3ee1af | ||
|
|
ebfaac9fb9 | ||
|
|
fbc0a2b354 | ||
|
|
3da79e7860 | ||
|
|
228c1bb7e6 | ||
|
|
e09f903332 | ||
|
|
1fe4d53565 | ||
|
|
48f5962f57 | ||
|
|
6099b30f3d | ||
|
|
09658ffee6 | ||
|
|
b6b7a67866 | ||
|
|
73730feced | ||
|
|
f468546eea | ||
|
|
c2d7cacdab | ||
|
|
c21e5ff3ff | ||
|
|
a6d2e3b1f8 | ||
|
|
0ff71f0a09 | ||
|
|
1b636fa0d8 | ||
|
|
1e3e886346 | ||
|
|
8b42f5a9c5 |
@@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
*The last config library you will ever use.*
|
*The last config library you will ever use.*
|
||||||
|
|
||||||
ΩConfig is a hyper-minimal config library based on [Auto Config](https://github.com/shedaniel/AutoConfig). It aims to achieve
|
ΩConfig is a hyper-minimal config library based on [Auto Config](https://github.com/shedaniel/AutoConfig). It aims to
|
||||||
the following goals:
|
achieve the following goals:
|
||||||
|
|
||||||
- Be lightweight (<10 KB) for JIJ usage
|
- Be lightweight (<10 KB) for JIJ usage
|
||||||
- Exceedingly simple design & API for developers
|
- Exceedingly simple design & API for developers
|
||||||
- Intuition and usability for players
|
- Intuition and usability for players
|
||||||
|
|
||||||
The following is an example of a simple ΩConfig setup:
|
The following is an example of a simple ΩConfig setup:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class TestConfig implements Config {
|
public class TestConfig implements Config {
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ public class TestConfig implements Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class MyModInitializer {
|
public class MyModInitializer {
|
||||||
|
|
||||||
@@ -35,7 +38,9 @@ public class MyModInitializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Extra API Utilities
|
### Extra API Utilities
|
||||||
|
|
||||||
ΩConfig provides several utility methods for developers.
|
ΩConfig provides several utility methods for developers.
|
||||||
@@ -48,6 +53,7 @@ MyModInitializer.CONFIG.save(); // writes the new value to disk
|
|||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### License
|
### License
|
||||||
ΩConfig is available under Public Domain.
|
|
||||||
You are encouraged to utilize the code in this repository in any way you wish.
|
ΩConfig is available under Public Domain. You are encouraged to utilize the code in this repository in any way you wish.
|
||||||
+20
-19
@@ -5,17 +5,16 @@ import java.nio.charset.StandardCharsets
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
jcenter()
|
|
||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.guardsquare:proguard-gradle:7.0.1'
|
classpath 'com.guardsquare:proguard-gradle:7.1.0-beta4'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "fabric-loom" version "0.7-SNAPSHOT"
|
id "fabric-loom" version "0.10-SNAPSHOT"
|
||||||
id "maven-publish"
|
id "maven-publish"
|
||||||
id "java-library"
|
id "java-library"
|
||||||
}
|
}
|
||||||
@@ -137,7 +136,7 @@ subprojects {
|
|||||||
allprojects {
|
allprojects {
|
||||||
apply plugin: "fabric-loom"
|
apply plugin: "fabric-loom"
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_16
|
||||||
version = System.getenv("TRAVIS_TAG") ?: project.mod_version
|
version = System.getenv("TRAVIS_TAG") ?: project.mod_version
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -155,10 +154,20 @@ allprojects {
|
|||||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
modRuntime "com.terraformersmc:modmenu:1.16.8"
|
|
||||||
modCompileOnly "com.terraformersmc:modmenu:1.16.8"
|
modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||||
|
modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from(rootProject.file("LICENSE.md")) {
|
||||||
|
rename { "LICENSE_${project.archivesBaseName.replace('-', '_')}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
processResources {
|
processResources {
|
||||||
// this will ensure that this task is redone when there"s a change
|
// this will ensure that this task is redone when there"s a change
|
||||||
inputs.property "version", mod_version
|
inputs.property "version", mod_version
|
||||||
@@ -176,12 +185,6 @@ allprojects {
|
|||||||
exclude "fabric.mod.json"
|
exclude "fabric.mod.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
|
||||||
from(rootProject.file("LICENSE.md")) {
|
|
||||||
rename { "LICENSE_${project.archivesBaseName.replace('-', '_')}"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
@@ -207,10 +210,10 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(":omega-config-base")
|
implementation project(path: ":omega-config-base", configuration: "namedElements")
|
||||||
compile project(":omega-config-gui")
|
implementation project(path: ":omega-config-gui", configuration: "namedElements")
|
||||||
modRuntime "com.terraformersmc:modmenu:1.16.8"
|
modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||||
modCompileOnly "com.terraformersmc:modmenu:1.16.8"
|
modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
testmodImplementation sourceSets.main.output
|
testmodImplementation sourceSets.main.output
|
||||||
@@ -220,9 +223,7 @@ dependencies {
|
|||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
artifact(file("${project.buildDir}/libs/${archivesBaseName}-${project.mod_version}.jar")) {
|
from components.java
|
||||||
builtBy(remapJar)
|
|
||||||
}
|
|
||||||
|
|
||||||
pom.withXml {
|
pom.withXml {
|
||||||
def depsNode = asNode().appendNode("dependencies")
|
def depsNode = asNode().appendNode("dependencies")
|
||||||
|
|||||||
+9
-10
@@ -1,17 +1,16 @@
|
|||||||
# Done to increase the memory available to gradle.
|
# Done to increase the memory available to gradle.
|
||||||
org.gradle.jvmargs=-Xmx1G
|
org.gradle.jvmargs=-Xmx2G
|
||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://fabricmc.net/versions.html
|
||||||
minecraft_version=1.16.5
|
minecraft_version=1.18.1
|
||||||
yarn_mappings=1.16.5+build.5
|
yarn_mappings=1.18.1+build.2
|
||||||
loader_version=0.11.2
|
loader_version=0.12.11
|
||||||
|
|
||||||
|
#Fabric api
|
||||||
|
fabric_version=0.44.0+1.18
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.0.4
|
mod_version=1.1.0
|
||||||
maven_group=draylar
|
maven_group=draylar
|
||||||
archives_base_name=omega-config
|
archives_base_name=omega-config
|
||||||
|
|
||||||
# Dependencies
|
modmenu_version=3.0.0
|
||||||
# check this on https://modmuss50.me/fabric.html
|
|
||||||
fabric_version=0.32.0+1.16
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
before_install:
|
||||||
|
- wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
|
||||||
|
- source install-jdk.sh --feature 17
|
||||||
|
- jshell --version
|
||||||
@@ -4,14 +4,13 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import draylar.omegaconfig.api.Comment;
|
import draylar.omegaconfig.api.Comment;
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
import draylar.omegaconfig.exception.NoValidConstructorException;
|
|
||||||
import draylar.omegaconfig.gson.SyncableExclusionStrategy;
|
import draylar.omegaconfig.gson.SyncableExclusionStrategy;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.NbtList;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -24,25 +23,28 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class OmegaConfig {
|
public class OmegaConfig {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
|
||||||
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
|
|
||||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
public static final Identifier CONFIG_SYNC_PACKET = new Identifier("omegaconfig", "sync");
|
public static final Identifier CONFIG_SYNC_PACKET = new Identifier("omegaconfig", "sync");
|
||||||
public static final Gson SYNC_ONLY_GSON = new GsonBuilder().addSerializationExclusionStrategy(new SyncableExclusionStrategy()).setPrettyPrinting().create();
|
public static final Gson SYNC_ONLY_GSON = new GsonBuilder().addSerializationExclusionStrategy(new SyncableExclusionStrategy()).setPrettyPrinting().create();
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> server.execute(() -> {
|
||||||
server.execute(() -> {
|
|
||||||
PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer());
|
PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer());
|
||||||
|
|
||||||
// list of configurations that are synced
|
// list of configurations that are synced
|
||||||
CompoundTag root = new CompoundTag();
|
NbtCompound root = new NbtCompound();
|
||||||
ListTag configurations = new ListTag();
|
NbtList configurations = new NbtList();
|
||||||
|
|
||||||
// Iterate over each configuration.
|
// Iterate over each configuration.
|
||||||
// Find values that should be synced and send the value over.
|
// Find values that should be synced and send the value over.
|
||||||
@@ -54,10 +56,9 @@ public class OmegaConfig {
|
|||||||
|
|
||||||
// save to packet and send to user
|
// save to packet and send to user
|
||||||
root.put("Configurations", configurations);
|
root.put("Configurations", configurations);
|
||||||
packet.writeCompoundTag(root);
|
packet.writeNbt(root);
|
||||||
handler.sendPacket(ServerPlayNetworking.createS2CPacket(CONFIG_SYNC_PACKET, packet));
|
handler.sendPacket(ServerPlayNetworking.createS2CPacket(CONFIG_SYNC_PACKET, packet));
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends Config> T register(Class<T> configClass) {
|
public static <T extends Config> T register(Class<T> configClass) {
|
||||||
@@ -70,7 +71,7 @@ public class OmegaConfig {
|
|||||||
// 1. serialize to disk if the config does not already exist
|
// 1. serialize to disk if the config does not already exist
|
||||||
// 2. read from disk if it does exist
|
// 2. read from disk if it does exist
|
||||||
if (!configExists(config)) {
|
if (!configExists(config)) {
|
||||||
writeConfig(configClass, config);
|
config.save();
|
||||||
REGISTERED_CONFIGURATIONS.add(config);
|
REGISTERED_CONFIGURATIONS.add(config);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -82,18 +83,20 @@ public class OmegaConfig {
|
|||||||
T object = GSON.fromJson(res.toString(), configClass);
|
T object = GSON.fromJson(res.toString(), configClass);
|
||||||
|
|
||||||
// re-write the config to add new values
|
// re-write the config to add new values
|
||||||
writeConfig(configClass, object);
|
object.save();
|
||||||
REGISTERED_CONFIGURATIONS.add(object);
|
REGISTERED_CONFIGURATIONS.add(object);
|
||||||
return object;
|
return object;
|
||||||
} catch (IOException ioException) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(ioException);
|
LOGGER.error(e);
|
||||||
LOGGER.info(String.format("Read error, using default values for config %s.", configClass.toString()));
|
LOGGER.info(String.format("Encountered an error while reading %s config, falling back to default values.", config.getName()));
|
||||||
|
LOGGER.info(String.format("If this problem persists, delete the config file %s and try again.", config.getName() + "." + config.getExtension()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||||
throw new NoValidConstructorException();
|
exception.printStackTrace();
|
||||||
|
throw new RuntimeException("No valid constructor found for: " + configClass.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,10 +114,9 @@ public class OmegaConfig {
|
|||||||
addFieldComments(field, keyToComments);
|
addFieldComments(field, keyToComments);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get inner-class fields
|
// "flattens" all the inner classes of the Config class into a single list
|
||||||
// TODO: recursively get inner classes?
|
for (Class<?> clazz : flatten(configClass.getDeclaredClasses())) {
|
||||||
for(Class<?> innerClass : configClass.getDeclaredClasses()) {
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
for(Field field : innerClass.getDeclaredFields()) {
|
|
||||||
addFieldComments(field, keyToComments);
|
addFieldComments(field, keyToComments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,14 +124,18 @@ public class OmegaConfig {
|
|||||||
// Find areas we should insert comments into...
|
// Find areas we should insert comments into...
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
String at = lines.get(i);
|
String at = lines.get(i);
|
||||||
|
String startingWhitespace = getStartingWhitespace(at);
|
||||||
|
|
||||||
// Check if we should insert comment
|
|
||||||
for (Map.Entry<String, String> entry : keyToComments.entrySet()) {
|
for (Map.Entry<String, String> entry : keyToComments.entrySet()) {
|
||||||
String key = entry.getKey();
|
|
||||||
String comment = entry.getValue();
|
String comment = entry.getValue();
|
||||||
|
// Check if we should insert comment
|
||||||
if (at.trim().startsWith(String.format("\"%s\"", key))) {
|
if (at.trim().startsWith(String.format("\"%s\"", entry.getKey()))) {
|
||||||
insertions.put(i + insertions.size(), String.format("%s//%s", getStartingWhitespace(at), comment));
|
if (comment.contains("\n")) {
|
||||||
|
comment = startingWhitespace + "//" + String.join(String.format("\n%s//", startingWhitespace), comment.split("\n"));
|
||||||
|
} else {
|
||||||
|
comment = String.format("%s//%s", startingWhitespace, comment);
|
||||||
|
}
|
||||||
|
insertions.put(i + insertions.size(), comment);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,7 +158,29 @@ public class OmegaConfig {
|
|||||||
Files.write(configPath, res.toString().getBytes());
|
Files.write(configPath, res.toString().getBytes());
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
LOGGER.error(ioException);
|
LOGGER.error(ioException);
|
||||||
LOGGER.info(String.format("Write error, using default values for config %s.", configClass.toString()));
|
LOGGER.info(String.format("Write error, using default values for config %s.", configClass));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Class<?>> flatten(Class<?>[] array) {
|
||||||
|
List<Class<?>> list = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Class<?> clazz : array) {
|
||||||
|
populateRecursively(list, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void populateRecursively(List<Class<?>> list, Class<?> aClass) {
|
||||||
|
list.add(aClass);
|
||||||
|
|
||||||
|
Class<?>[] classes = aClass.getDeclaredClasses();
|
||||||
|
|
||||||
|
if (classes.length != 0) {
|
||||||
|
for (Class<?> clazz : classes) {
|
||||||
|
populateRecursively(list, clazz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package draylar.omegaconfig.api;
|
package draylar.omegaconfig.api;
|
||||||
|
|
||||||
import draylar.omegaconfig.OmegaConfig;
|
import draylar.omegaconfig.OmegaConfig;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -16,8 +16,8 @@ public interface Config {
|
|||||||
OmegaConfig.writeConfig((Class<Config>) getClass(), this);
|
OmegaConfig.writeConfig((Class<Config>) getClass(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompoundTag writeSyncingTag() {
|
default NbtCompound writeSyncingTag() {
|
||||||
CompoundTag tag = new CompoundTag();
|
NbtCompound tag = new NbtCompound();
|
||||||
tag.putString("ConfigName", getName());
|
tag.putString("ConfigName", getName());
|
||||||
|
|
||||||
// all config vs. individual fields
|
// all config vs. individual fields
|
||||||
@@ -67,7 +67,7 @@ public interface Config {
|
|||||||
* modids for configuration screen instances in their menu.
|
* modids for configuration screen instances in their menu.
|
||||||
* If you are intending for this config to have a ModMenu config
|
* If you are intending for this config to have a ModMenu config
|
||||||
* screen, this method should return the modid specified in your fabric.mod.json.
|
* screen, this method should return the modid specified in your fabric.mod.json.
|
||||||
*
|
* <p>
|
||||||
* If this method is not overridden, null will be returned, which
|
* If this method is not overridden, null will be returned, which
|
||||||
* means this config is not explicitly associated with any particular mod.
|
* means this config is not explicitly associated with any particular mod.
|
||||||
*
|
*
|
||||||
@@ -99,7 +99,7 @@ public interface Config {
|
|||||||
* By default, a config such as 'my_config' will appear at /config/my_config.json.
|
* By default, a config such as 'my_config' will appear at /config/my_config.json.
|
||||||
* If this method specifies a directory, such as 'configurations',
|
* If this method specifies a directory, such as 'configurations',
|
||||||
* the config file will appear at /config/configurations/my_config.json.
|
* the config file will appear at /config/configurations/my_config.json.
|
||||||
*
|
* <p>
|
||||||
* Nested directories can be specified by using a string such as 'configurations/client'.
|
* Nested directories can be specified by using a string such as 'configurations/client'.
|
||||||
*
|
*
|
||||||
* @return the directory of this config
|
* @return the directory of this config
|
||||||
|
|||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
package draylar.omegaconfig.exception;
|
|
||||||
|
|
||||||
public class NoValidConstructorException extends RuntimeException {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,13 +3,12 @@ package draylar.omegaconfig.mixin;
|
|||||||
import draylar.omegaconfig.OmegaConfig;
|
import draylar.omegaconfig.OmegaConfig;
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
import draylar.omegaconfig.api.Syncing;
|
import draylar.omegaconfig.api.Syncing;
|
||||||
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
import net.fabricmc.fabric.api.util.NbtType;
|
import net.fabricmc.fabric.api.util.NbtType;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.RunArgs;
|
import net.minecraft.client.RunArgs;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.NbtList;
|
||||||
import net.minecraft.nbt.ListTag;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -31,15 +30,15 @@ public class ClientMixin {
|
|||||||
method = "<init>",
|
method = "<init>",
|
||||||
at = @At("RETURN"))
|
at = @At("RETURN"))
|
||||||
private void onReturn(RunArgs args, CallbackInfo ci) {
|
private void onReturn(RunArgs args, CallbackInfo ci) {
|
||||||
ClientSidePacketRegistry.INSTANCE.register(OmegaConfig.CONFIG_SYNC_PACKET, (context, buffer) -> {
|
ClientPlayNetworking.registerGlobalReceiver(OmegaConfig.CONFIG_SYNC_PACKET, (client, handler, buf, responseSender) -> {
|
||||||
CompoundTag tag = buffer.readCompoundTag();
|
NbtCompound tag = buf.readNbt();
|
||||||
savedClientConfig.clear();
|
savedClientConfig.clear();
|
||||||
|
|
||||||
context.getTaskQueue().execute(() -> {
|
client.execute(() -> {
|
||||||
if (tag != null && tag.contains("Configurations")) {
|
if (tag != null && tag.contains("Configurations")) {
|
||||||
ListTag list = tag.getList("Configurations", NbtType.COMPOUND);
|
NbtList list = tag.getList("Configurations", NbtType.COMPOUND);
|
||||||
list.forEach(compound -> {
|
list.forEach(compound -> {
|
||||||
CompoundTag syncedConfiguration = (CompoundTag) compound;
|
NbtCompound syncedConfiguration = (NbtCompound) compound;
|
||||||
String name = syncedConfiguration.getString("ConfigName");
|
String name = syncedConfiguration.getString("ConfigName");
|
||||||
String json = syncedConfiguration.getString("Serialized");
|
String json = syncedConfiguration.getString("Serialized");
|
||||||
boolean allSync = syncedConfiguration.getBoolean("AllSync");
|
boolean allSync = syncedConfiguration.getBoolean("AllSync");
|
||||||
@@ -79,7 +78,7 @@ public class ClientMixin {
|
|||||||
@Inject(
|
@Inject(
|
||||||
method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V",
|
method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V",
|
||||||
at = @At("RETURN"))
|
at = @At("RETURN"))
|
||||||
private void restoreConfigurations(Screen screen, CallbackInfo ci) {
|
private void restoreConfigurations(CallbackInfo ci) {
|
||||||
for (Config config : savedClientConfig) {
|
for (Config config : savedClientConfig) {
|
||||||
for (Config potentiallySynced : OmegaConfig.getRegisteredConfigurations()) {
|
for (Config potentiallySynced : OmegaConfig.getRegisteredConfigurations()) {
|
||||||
if (config.getName().equals(potentiallySynced.getName())) {
|
if (config.getName().equals(potentiallySynced.getName())) {
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "omega-config",
|
"id": "omega-config",
|
||||||
"version": "${version}",
|
"version": "1.1.0",
|
||||||
"name": "OmegaConfig",
|
"name": "OmegaConfig",
|
||||||
"description": "The last config solution you will ever use.",
|
"description": "The last config solution you will ever use.",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Draylar"
|
"Draylar",
|
||||||
|
"Frqnny"
|
||||||
],
|
],
|
||||||
"contact": {},
|
"contact": {
|
||||||
|
"homepage": "https://github.com/Draylar/omega-config",
|
||||||
|
"sources": "https://github.com/Draylar/omega-config",
|
||||||
|
"issues": "https://github.com/Draylar/omega-config/issues"
|
||||||
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
@@ -17,5 +22,10 @@
|
|||||||
"fabricloader": "*",
|
"fabricloader": "*",
|
||||||
"fabric": "*",
|
"fabric": "*",
|
||||||
"minecraft": "*"
|
"minecraft": "*"
|
||||||
|
},
|
||||||
|
"custom": {
|
||||||
|
"modmenu": {
|
||||||
|
"badges": [ "library" ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "draylar.omegaconfig.mixin",
|
"package": "draylar.omegaconfig.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_16",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"ClientMixin"
|
"ClientMixin"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":omega-config-base")
|
implementation project(":omega-config-base")
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ public class OmegaConfigGui {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a ModMenu configuration screen for the given {@link Config} instance.
|
* Registers a ModMenu configuration screen for the given {@link Config} instance.
|
||||||
|
*
|
||||||
* @param config registered config to create a ModMenu screen for
|
* @param config registered config to create a ModMenu screen for
|
||||||
* @param <T> config type
|
* @param <T> config type
|
||||||
*/
|
*/
|
||||||
|
|||||||
+17
-16
@@ -5,19 +5,16 @@ import draylar.omegaconfig.api.Config;
|
|||||||
import draylar.omegaconfiggui.api.screen.widget.LabelWidget;
|
import draylar.omegaconfiggui.api.screen.widget.LabelWidget;
|
||||||
import draylar.omegaconfiggui.api.screen.widget.TypeWidgets;
|
import draylar.omegaconfiggui.api.screen.widget.TypeWidgets;
|
||||||
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.gui.Drawable;
|
|
||||||
import net.minecraft.client.gui.Element;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
import net.minecraft.client.render.BufferBuilder;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import net.minecraft.client.render.Tessellator;
|
import net.minecraft.client.render.Tessellator;
|
||||||
|
import net.minecraft.client.render.VertexFormat;
|
||||||
import net.minecraft.client.render.VertexFormats;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.Pair;
|
import net.minecraft.util.Pair;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -32,7 +29,7 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
|||||||
private static final List<Class<?>> validClasses = Arrays.asList(Double.class, String.class, Boolean.class);
|
private static final List<Class<?>> validClasses = Arrays.asList(Double.class, String.class, Boolean.class);
|
||||||
private final T config;
|
private final T config;
|
||||||
private final Screen parent;
|
private final Screen parent;
|
||||||
private final Map<Field, Pair<WidgetSupplier<Object, AbstractButtonWidget>, AbstractButtonWidget>> fieldWidgets = new HashMap<>();
|
private final Map<Field, Pair<WidgetSupplier<Object, ClickableWidget>, ClickableWidget>> fieldWidgets = new HashMap<>();
|
||||||
|
|
||||||
public OmegaConfigScreen(T config, Screen parent) {
|
public OmegaConfigScreen(T config, Screen parent) {
|
||||||
super(new LiteralText(""));
|
super(new LiteralText(""));
|
||||||
@@ -54,15 +51,15 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
|||||||
Class<?> unbox = TypeWidgets.unbox(field.getType());
|
Class<?> unbox = TypeWidgets.unbox(field.getType());
|
||||||
|
|
||||||
// label
|
// label
|
||||||
addChild(new LabelWidget(150, 15 + height / 6 + 20 * over, new LiteralText(field.getName())));
|
addDrawable(new LabelWidget(150, 15 + height / 6 + 20 * over, new LiteralText(field.getName())));
|
||||||
|
|
||||||
// get value
|
// get value
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object value = field.get(config);
|
Object value = field.get(config);
|
||||||
|
|
||||||
// button / interact
|
// button / interact
|
||||||
AbstractButtonWidget button;
|
ClickableWidget button;
|
||||||
WidgetSupplier<Object, AbstractButtonWidget> widgetSupplier = (WidgetSupplier<Object, AbstractButtonWidget>) TypeWidgets.get(unbox);
|
WidgetSupplier<Object, ClickableWidget> widgetSupplier = (WidgetSupplier<Object, ClickableWidget>) TypeWidgets.get(unbox);
|
||||||
if (widgetSupplier != null) {
|
if (widgetSupplier != null) {
|
||||||
button = widgetSupplier.create(this, 250, 5 + height / 6 + 25 * over, 100, 20, new LiteralText(field.getName()), value);
|
button = widgetSupplier.create(this, 250, 5 + height / 6 + 25 * over, 100, 20, new LiteralText(field.getName()), value);
|
||||||
} else {
|
} else {
|
||||||
@@ -71,7 +68,7 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
|||||||
|
|
||||||
fieldWidgets.put(field, new Pair<>(widgetSupplier, button));
|
fieldWidgets.put(field, new Pair<>(widgetSupplier, button));
|
||||||
|
|
||||||
addButton(button);
|
addSelectableChild(button);
|
||||||
|
|
||||||
over++;
|
over++;
|
||||||
}
|
}
|
||||||
@@ -92,15 +89,17 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
|||||||
|
|
||||||
config.save();
|
config.save();
|
||||||
});
|
});
|
||||||
addButton(save);
|
addSelectableChild(save);
|
||||||
addButton(exit);
|
addSelectableChild(exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
renderBackground(matrices);
|
renderBackground(matrices);
|
||||||
|
|
||||||
for (AbstractButtonWidget button : this.buttons) {
|
//TODO make this work. for Drawables (children) it works in parent method
|
||||||
|
/*
|
||||||
|
for (ClickableWidget button : this.) {
|
||||||
button.render(matrices, mouseX, mouseY, delta);
|
button.render(matrices, mouseX, mouseY, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,11 +108,13 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
|||||||
((Drawable) element).render(matrices, mouseX, mouseY, delta);
|
((Drawable) element).render(matrices, mouseX, mouseY, delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
client.openScreen(parent);
|
client.setScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -129,9 +130,9 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
|
|||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||||
this.client.getTextureManager().bindTexture(OPTIONS_BACKGROUND_TEXTURE);
|
this.client.getTextureManager().bindTexture(OPTIONS_BACKGROUND_TEXTURE);
|
||||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
|
||||||
bufferBuilder.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
|
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
|
||||||
bufferBuilder.vertex(x, height + y, 0.0D).texture(0.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
|
bufferBuilder.vertex(x, height + y, 0.0D).texture(0.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
|
||||||
bufferBuilder.vertex(width + x, height + y, 0.0D).texture((float) width / 32.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
|
bufferBuilder.vertex(width + x, height + y, 0.0D).texture((float) width / 32.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
|
||||||
bufferBuilder.vertex(width + x, y, 0.0D).texture((float) width / 32.0F, (float) vOffset).color(r, g, b, 255).next();
|
bufferBuilder.vertex(width + x, y, 0.0D).texture((float) width / 32.0F, (float) vOffset).color(r, g, b, 255).next();
|
||||||
|
|||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
package draylar.omegaconfiggui.api.screen.widget;
|
package draylar.omegaconfiggui.api.screen.widget;
|
||||||
|
|
||||||
import draylar.omegaconfiggui.mixin.AbstractButtonWidgetAccessor;
|
import draylar.omegaconfiggui.mixin.ClickableWidgetInvoker;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
@@ -20,8 +20,8 @@ public class BaseTextFieldWidget extends TextFieldWidget {
|
|||||||
public void setTextFieldFocused(boolean focused) {
|
public void setTextFieldFocused(boolean focused) {
|
||||||
// unfocus all others
|
// unfocus all others
|
||||||
parent.children().forEach(element -> {
|
parent.children().forEach(element -> {
|
||||||
if(element instanceof AbstractButtonWidget) {
|
if (element instanceof ClickableWidget) {
|
||||||
((AbstractButtonWidgetAccessor) element).callSetFocused(false);
|
((ClickableWidgetInvoker) element).callSetFocused(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -13,12 +13,10 @@ public class DoubleFieldWidget extends BaseTextFieldWidget {
|
|||||||
@Override
|
@Override
|
||||||
public void write(String string) {
|
public void write(String string) {
|
||||||
try {
|
try {
|
||||||
if(string.equals(".") && !getText().contains(".")) {
|
if (!string.equals(".") || getText().contains(".")) {
|
||||||
super.write(string);
|
|
||||||
} else {
|
|
||||||
Double.parseDouble(string);
|
Double.parseDouble(string);
|
||||||
super.write(string);
|
|
||||||
}
|
}
|
||||||
|
super.write(string);
|
||||||
|
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -30,6 +30,10 @@ public class TypeWidgets {
|
|||||||
PRIMITIVE_TO_BOXED.put(void.class, Void.class);
|
PRIMITIVE_TO_BOXED.put(void.class, Void.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TypeWidgets() {
|
||||||
|
// NO-OP
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static <T> WidgetSupplier<T, ?> get(Class<T> typeClass) {
|
public static <T> WidgetSupplier<T, ?> get(Class<T> typeClass) {
|
||||||
return (WidgetSupplier<T, ?>) CLASS_WIDGETS.get(unbox(typeClass));
|
return (WidgetSupplier<T, ?>) CLASS_WIDGETS.get(unbox(typeClass));
|
||||||
@@ -38,8 +42,4 @@ public class TypeWidgets {
|
|||||||
public static Class<?> unbox(Class<?> c) {
|
public static Class<?> unbox(Class<?> c) {
|
||||||
return PRIMITIVE_TO_BOXED.getOrDefault(c, c);
|
return PRIMITIVE_TO_BOXED.getOrDefault(c, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypeWidgets() {
|
|
||||||
// NO-OP
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1,10 +1,11 @@
|
|||||||
package draylar.omegaconfiggui.api.screen.widget;
|
package draylar.omegaconfiggui.api.screen.widget;
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
|
|
||||||
public interface WidgetSupplier<T, A extends AbstractButtonWidget> {
|
public interface WidgetSupplier<T, A extends ClickableWidget> {
|
||||||
AbstractButtonWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, T value);
|
ClickableWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, T value);
|
||||||
|
|
||||||
T get(A widget);
|
T get(A widget);
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@ import draylar.omegaconfiggui.api.screen.widget.BaseTextFieldWidget;
|
|||||||
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
package draylar.omegaconfiggui.mixin;
|
package draylar.omegaconfiggui.mixin;
|
||||||
|
|
||||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
@Mixin(AbstractButtonWidget.class)
|
@Mixin(ClickableWidget.class)
|
||||||
public interface AbstractButtonWidgetAccessor {
|
public interface ClickableWidgetInvoker {
|
||||||
@Invoker
|
@Invoker
|
||||||
void callSetFocused(boolean focused);
|
void callSetFocused(boolean focused);
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,11 @@
|
|||||||
"authors": [
|
"authors": [
|
||||||
"Draylar"
|
"Draylar"
|
||||||
],
|
],
|
||||||
"contact": {},
|
"contact": {
|
||||||
|
"homepage": "https://github.com/Draylar/omega-config",
|
||||||
|
"sources": "https://github.com/Draylar/omega-config",
|
||||||
|
"issues": "https://github.com/Draylar/omega-config/issues"
|
||||||
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
@@ -17,5 +21,10 @@
|
|||||||
"fabricloader": "*",
|
"fabricloader": "*",
|
||||||
"fabric": "*",
|
"fabric": "*",
|
||||||
"minecraft": "*"
|
"minecraft": "*"
|
||||||
|
},
|
||||||
|
"custom": {
|
||||||
|
"modmenu": {
|
||||||
|
"badges": [ "library" ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "draylar.omegaconfiggui.mixin",
|
"package": "draylar.omegaconfiggui.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_16",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"AbstractButtonWidgetAccessor",
|
"ClickableWidgetInvoker",
|
||||||
"ModMenuAccessor"
|
"ModMenuAccessor"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
|
|||||||
@@ -1,131 +0,0 @@
|
|||||||
package draylar.omegatest;
|
|
||||||
|
|
||||||
import draylar.omegaconfig.api.Comment;
|
|
||||||
import draylar.omegaconfig.api.Config;
|
|
||||||
|
|
||||||
public class NewTestConfig implements Config {
|
|
||||||
@Comment("Mo' Structures feature toggles.")
|
|
||||||
public Features features = new Features();
|
|
||||||
|
|
||||||
@Comment("Chances are once per the number of chunks. A Chance 500 makes a feature spawn every 500 chunks. Affected by biomes it spawns in and the chunk, so not all are proportional.")
|
|
||||||
public FeatureChances feature_chances = new FeatureChances();
|
|
||||||
|
|
||||||
@Comment("Structure toggles. These do not have chances, but in the future they may. ")
|
|
||||||
public Structures structures = new Structures();
|
|
||||||
|
|
||||||
@Comment("Structure chances. Seperation is the least amount of chunks that a structure will spawn from itself. Spacing is the maximum amount of chunks, and both are used to randomly spawn structures and can be tweaked.")
|
|
||||||
public StructureChances structureChances = new StructureChances();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "mostructures-config-v2";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Features {
|
|
||||||
@Comment("Airplanes & Air Balloons")
|
|
||||||
public boolean air_features = true;
|
|
||||||
@Comment("Fallen Trees")
|
|
||||||
public boolean fallen_trees = true;
|
|
||||||
@Comment("Desert Features")
|
|
||||||
public boolean desert_features = true;
|
|
||||||
@Comment("Ruins")
|
|
||||||
public boolean ruins = true;
|
|
||||||
@Comment("Lamppost")
|
|
||||||
public boolean lamppost = true;
|
|
||||||
@Comment("Boulder")
|
|
||||||
public boolean boulder = true;
|
|
||||||
@Comment("Volcanic Vent")
|
|
||||||
public boolean volcanic_vent = true;
|
|
||||||
@Comment("Beach Features")
|
|
||||||
public boolean beach_features = true;
|
|
||||||
@Comment("Boats")
|
|
||||||
public boolean boats = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class FeatureChances {
|
|
||||||
@Comment("Airplanes & Air Balloons")
|
|
||||||
public int air_feature_chance = 4600;
|
|
||||||
@Comment("Fallen Trees")
|
|
||||||
public int fallen_trees_chance = 17;
|
|
||||||
@Comment("Desert Features")
|
|
||||||
public int desert_features_chance = 555;
|
|
||||||
@Comment("Ruins")
|
|
||||||
public int ruins_chance = 3500;
|
|
||||||
@Comment("Lamppost")
|
|
||||||
public int lamppost_chance = 100;
|
|
||||||
@Comment("Boulder")
|
|
||||||
public int boulder_chance = 4000;
|
|
||||||
@Comment("Volcanic Vent")
|
|
||||||
public int volcanic_vent_chance = 85;
|
|
||||||
@Comment("Beach Features")
|
|
||||||
public int beach_features_chance = 75;
|
|
||||||
@Comment("Boats")
|
|
||||||
public int boats_chance = 4000;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Structures {
|
|
||||||
@Comment("Barnhouse")
|
|
||||||
public boolean barn_house = true;
|
|
||||||
@Comment("Jungle Pyramid")
|
|
||||||
public boolean jungle_pyramid = true;
|
|
||||||
@Comment("Big Pyramid")
|
|
||||||
public boolean big_pyramid = true;
|
|
||||||
@Comment("The Castle In The Sky")
|
|
||||||
public boolean the_castle_in_the_sky = true;
|
|
||||||
@Comment("Villager Tower")
|
|
||||||
public boolean villager_tower = true;
|
|
||||||
@Comment("Abandoned Churches")
|
|
||||||
public boolean abandoned_churches = true;
|
|
||||||
@Comment("Villager Market")
|
|
||||||
public boolean villager_market = true;
|
|
||||||
@Comment("Pillager Factory")
|
|
||||||
public boolean pillager_factory = true;
|
|
||||||
@Comment("Ice Tower")
|
|
||||||
public boolean ice_tower = true;
|
|
||||||
@Comment("Boar Hat Tavern")
|
|
||||||
public boolean tavern = true;
|
|
||||||
@Comment("Killer Bunny Castle")
|
|
||||||
public boolean killer_bunny_castle = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class StructureChances {
|
|
||||||
@Comment("Barn House")
|
|
||||||
public int barn_house_seperation = 16;
|
|
||||||
public int barn_house_spacing = 40;
|
|
||||||
@Comment("Big Pyramid")
|
|
||||||
public int big_pyramid_seperation = 5;
|
|
||||||
public int big_pyramid_spacing = 25;
|
|
||||||
@Comment("Jungle Pyramid")
|
|
||||||
public int jungle_pyramid_seperation = 5;
|
|
||||||
public int jungle_pyramid_spacing = 25;
|
|
||||||
@Comment("The Castle In The Sky")
|
|
||||||
public int the_castle_in_the_sky_seperation = 8;
|
|
||||||
public int the_castle_in_the_sky_spacing = 32;
|
|
||||||
@Comment("Villager Tower")
|
|
||||||
public int villager_tower_seperation = 16;
|
|
||||||
public int villager_tower_spacing = 40;
|
|
||||||
@Comment("Abandoned Church")
|
|
||||||
public int abandoned_church_seperation = 16;
|
|
||||||
public int abandoned_church_spacing = 40;
|
|
||||||
@Comment("Villager Market")
|
|
||||||
public int villager_market_seperation = 27;
|
|
||||||
public int villager_market_spacing = 50;
|
|
||||||
@Comment("Pillager Factory")
|
|
||||||
public int pillager_factory_seperation = 27;
|
|
||||||
public int pillager_factory_spacing = 50;
|
|
||||||
@Comment("Ice Tower")
|
|
||||||
public int ice_tower_seperation = 8;
|
|
||||||
public int ice_tower_spacing = 32;
|
|
||||||
@Comment("Boar Hat Tavern")
|
|
||||||
public int tavern_seperation = 16;
|
|
||||||
public int tavern_spacing = 46;
|
|
||||||
@Comment("Killer Bunny Castle")
|
|
||||||
public int killer_bunny_castle_seperation = 25;
|
|
||||||
public int killer_bunny_castle_spacing = 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getExtension() {
|
|
||||||
return "json5";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,20 @@
|
|||||||
package draylar.omegatest;
|
package draylar.omegatest;
|
||||||
|
|
||||||
import draylar.omegaconfig.OmegaConfig;
|
import draylar.omegaconfig.OmegaConfig;
|
||||||
|
import draylar.omegatest.config.ClassConfigTest;
|
||||||
|
import draylar.omegatest.config.CommentedNestedClassConfig;
|
||||||
|
import draylar.omegatest.config.NestedConfigTest;
|
||||||
|
import draylar.omegatest.config.SimpleConfigTest;
|
||||||
|
import draylar.omegatest.config.StructuresConfigTest;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
public class OmegaTestMain implements ModInitializer {
|
public class OmegaTestMain implements ModInitializer {
|
||||||
|
|
||||||
public static final TestConfig CONFIG = OmegaConfig.register(TestConfig.class);
|
public static final SimpleConfigTest CONFIG = OmegaConfig.register(SimpleConfigTest.class);
|
||||||
public static final NewTestConfig MO_CONFIG = OmegaConfig.register(NewTestConfig.class);
|
public static final StructuresConfigTest MO_CONFIG = OmegaConfig.register(StructuresConfigTest.class);
|
||||||
public static final NestedConfig NESTED = OmegaConfig.register(NestedConfig.class);
|
public static final NestedConfigTest NESTED = OmegaConfig.register(NestedConfigTest.class);
|
||||||
|
public static final ClassConfigTest CLASS = OmegaConfig.register(ClassConfigTest.class);
|
||||||
|
public static final CommentedNestedClassConfig COMMENTED_NESTED_CLASS = OmegaConfig.register(CommentedNestedClassConfig.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClassConfigTest implements Config {
|
||||||
|
|
||||||
|
public List<TestClass> l = Arrays.asList(
|
||||||
|
new TestClass(true, 1, "hello")
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "class-config";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestClass {
|
||||||
|
public final boolean a;
|
||||||
|
public final int b;
|
||||||
|
public String c;
|
||||||
|
|
||||||
|
public TestClass(boolean a, int b, String c) {
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Comment;
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
|
||||||
|
public class CommentedNestedClassConfig implements Config {
|
||||||
|
|
||||||
|
@Comment("Very nested test")
|
||||||
|
public First first = new First();
|
||||||
|
|
||||||
|
@Comment("True")
|
||||||
|
public boolean test = false;
|
||||||
|
|
||||||
|
@Comment("First-Level")
|
||||||
|
public VeryNested veryNested = new VeryNested();
|
||||||
|
|
||||||
|
public static class First {
|
||||||
|
@Comment("Cucumbers")
|
||||||
|
public boolean cucumbers = true;
|
||||||
|
|
||||||
|
@Comment("InnerFirst")
|
||||||
|
public InnerFirst innerFirst = new InnerFirst();
|
||||||
|
|
||||||
|
@Comment("InnerSecond")
|
||||||
|
public InnerSecond innerSecond = new InnerSecond();
|
||||||
|
|
||||||
|
public static class InnerFirst {
|
||||||
|
@Comment("Number of Tomatoes")
|
||||||
|
public int numberOfTomatoes = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InnerSecond {
|
||||||
|
@Comment("Inner Second First")
|
||||||
|
public InnerSecondFirst innerSecondFirst = new InnerSecondFirst();
|
||||||
|
|
||||||
|
public static class InnerSecondFirst {
|
||||||
|
@Comment("Olive Oil")
|
||||||
|
public String oliveOil = "oliveOil";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class VeryNested {
|
||||||
|
@Comment("Second-Level")
|
||||||
|
public Very very = new Very();
|
||||||
|
public static class Very {
|
||||||
|
@Comment("Third-Level")
|
||||||
|
public VeryVery veryVery = new VeryVery();
|
||||||
|
public static class VeryVery {
|
||||||
|
@Comment("Forth-Level")
|
||||||
|
public VeryVeryVery veryVeryVery = new VeryVeryVery();
|
||||||
|
public static class VeryVeryVery {
|
||||||
|
@Comment("Fifth-Level")
|
||||||
|
public VeryVeryVeryVery veryVeryVeryVery = new VeryVeryVeryVery();
|
||||||
|
public static class VeryVeryVeryVery {
|
||||||
|
@Comment("Sixth-Level")
|
||||||
|
public String last = "last";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "commented-inner-classes";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExtension() {
|
||||||
|
return "json5";
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
package draylar.omegatest;
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
|
|
||||||
public class NestedConfig implements Config {
|
public class NestedConfigTest implements Config {
|
||||||
|
|
||||||
public boolean test = false;
|
public boolean test = false;
|
||||||
|
|
||||||
+11
-11
@@ -1,4 +1,4 @@
|
|||||||
package draylar.omegatest;
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
import draylar.omegaconfig.api.Comment;
|
import draylar.omegaconfig.api.Comment;
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
@@ -6,25 +6,19 @@ import draylar.omegaconfig.api.Syncing;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@Syncing
|
@Syncing
|
||||||
public class TestConfig implements Config {
|
public class SimpleConfigTest implements Config {
|
||||||
|
|
||||||
@Comment(value = "Hello!")
|
@Comment(value = "Hello!")
|
||||||
boolean v = false;
|
public boolean v = false;
|
||||||
|
|
||||||
@Comment(value = "I'm a double.")
|
@Comment(value = "I'm a double.")
|
||||||
double doubleTest = 0.0;
|
public double doubleTest = 0.0;
|
||||||
|
|
||||||
String stringTest = "Hello, world!";
|
public String stringTest = "Hello, world!";
|
||||||
|
|
||||||
@Comment(value = "This is an inner static class.")
|
@Comment(value = "This is an inner static class.")
|
||||||
public Test test = new Test();
|
public Test test = new Test();
|
||||||
|
|
||||||
public static class Test {
|
|
||||||
|
|
||||||
@Comment(value = "This is the value inside the class!")
|
|
||||||
public boolean innerTest = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "test-config";
|
return "test-config";
|
||||||
@@ -34,4 +28,10 @@ public class TestConfig implements Config {
|
|||||||
public @Nullable String getModid() {
|
public @Nullable String getModid() {
|
||||||
return "omega-config-test";
|
return "omega-config-test";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Test {
|
||||||
|
|
||||||
|
@Comment(value = "This is the value inside the class!")
|
||||||
|
public boolean innerTest = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StructureConfigEntry {
|
||||||
|
|
||||||
|
public final boolean activated;
|
||||||
|
public final int separation;
|
||||||
|
public final int spacing;
|
||||||
|
public final int salt;
|
||||||
|
|
||||||
|
private StructureConfigEntry(int separation, int spacing, int salt) {
|
||||||
|
this.activated = true;
|
||||||
|
this.spacing = spacing;
|
||||||
|
this.separation = separation;
|
||||||
|
this.salt = salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StructureConfigEntry of(int separation, int spacing, int salt) {
|
||||||
|
return new StructureConfigEntry(separation, spacing, salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void computeConfigMap(Map<String, StructureConfigEntry> map) {
|
||||||
|
map.computeIfAbsent("abandoned_church", (id) -> of(14, 38, 66996840));
|
||||||
|
map.computeIfAbsent("barn_house", (id) -> of(8, 38, 165757306));
|
||||||
|
map.computeIfAbsent("big_pyramid", (id) -> of(5, 25, 239284294));
|
||||||
|
map.computeIfAbsent("jungle_pyramid", (id) -> of(5, 25, 312178642));
|
||||||
|
map.computeIfAbsent("the_castle_in_the_sky", (id) -> of(8, 30, 423494938));
|
||||||
|
map.computeIfAbsent("killer_bunny_castle", (id) -> of(25, 45, 48123900));
|
||||||
|
map.computeIfAbsent("villager_tower", (id) -> of(16, 34, 550292492));
|
||||||
|
map.computeIfAbsent("villager_market", (id) -> of(16, 36, 784939542));
|
||||||
|
map.computeIfAbsent("pillager_factory", (id) -> of(16, 36, 839204924));
|
||||||
|
map.computeIfAbsent("ice_tower", (id) -> of(8, 28, 964058305));
|
||||||
|
map.computeIfAbsent("tavern", (id) -> of(12, 32, 19296726));
|
||||||
|
map.computeIfAbsent("pirate_ship", (id) -> of(16, 40, 583957395));
|
||||||
|
map.computeIfAbsent("lighthouse", (id) -> of(16, 32, 29502322));
|
||||||
|
map.computeIfAbsent("volcanic_vent", (id) -> of(4, 8, 84981094));
|
||||||
|
map.computeIfAbsent("moai", (id) -> of(4, 8, 12994829));
|
||||||
|
map.computeIfAbsent("air_balloon", (id) -> of(1, 6, 29483148));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Comment;
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
//taken straight out of Mo' Structures
|
||||||
|
public class StructuresConfigTest implements Config {
|
||||||
|
|
||||||
|
@Comment("""
|
||||||
|
Welcome to Mo'Structures Config!
|
||||||
|
|
||||||
|
Here, you can turn off structures, change their chance, and also change their salt.
|
||||||
|
|
||||||
|
To turn off a structure, simply go to the corresponding entry and set `activated` to false.
|
||||||
|
|
||||||
|
Mo' Structures uses the vanilla structure spawning system. That is-
|
||||||
|
- Seperation is the minimum chunks between structures
|
||||||
|
- Spacing is the average chunks between structures
|
||||||
|
|
||||||
|
Salt is a special field that gives structures unique spawning positions. DO NOT TOUCH IT, ONLY ADVANCED TROUBLESHOOTING!
|
||||||
|
|
||||||
|
""")
|
||||||
|
public final Map<String, StructureConfigEntry> structureConfigEntries = new HashMap<>(17);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "mostructures-config-v2";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExtension() {
|
||||||
|
return "json5";
|
||||||
|
}
|
||||||
|
|
||||||
|
public StructureConfigEntry get(Identifier id) {
|
||||||
|
|
||||||
|
|
||||||
|
for (Map.Entry<String, StructureConfigEntry> entry : structureConfigEntries.entrySet()) {
|
||||||
|
if (entry.getKey().equals(id.getPath())) {
|
||||||
|
return entry.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NullPointerException("Tried StructureConfigEntry with id: " + id + ", but it was null!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
StructureConfigEntry.computeConfigMap(structureConfigEntries);
|
||||||
|
Config.super.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user