Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d7aa7581d | ||
|
|
8611edb92c | ||
|
|
58c420d35f | ||
|
|
270db37dba | ||
|
|
2968111445 | ||
|
|
136cfe6a9a |
@@ -7,9 +7,10 @@
|
||||
ΩConfig is a hyper-minimal config library based on [Auto Config](https://github.com/shedaniel/AutoConfig). It aims to
|
||||
achieve the following goals:
|
||||
|
||||
- Be lightweight (<10 KB) for JIJ usage
|
||||
- Be lightweight (<25 KB) for JIJ usage
|
||||
- Exceedingly simple design & API for developers
|
||||
- Intuition and usability for players
|
||||
- Bonus annotations for advanced config options (syncing values)
|
||||
|
||||
The following is an example of a simple ΩConfig setup:
|
||||
|
||||
@@ -39,6 +40,67 @@ public class MyModInitializer {
|
||||
}
|
||||
```
|
||||
|
||||
Looking for a simple config screen? Talk about easy!
|
||||
```java
|
||||
public class ClientInitializer implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// Make sure you implement getModid in your config class!
|
||||
OmegaConfigGui.registerConfigScreen(MainInitializer.CONFIG);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Pulling Omega Config into Development
|
||||
|
||||
To use Omega Config, you will have to add it to your build.gradle file.
|
||||
|
||||
What you pull in depends on whether you want GUI functionality. For basic config files using the base module (~20KB),
|
||||
you can use the following gradle declarations:
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
include("com.github.Draylar.omega-config:omega-config-base:${project.omega_config_version}")
|
||||
modImplementation("com.github.Draylar.omega-config:omega-config-base:${project.omega_config_version}")
|
||||
}
|
||||
```
|
||||
|
||||
Easy - you now have a bundled configuration library. Use the examples in the first section to implement your config.
|
||||
|
||||
If you want to add GUI functionality (most likely Mod Menu support), you can pull in the GUI module (~25 KB):
|
||||
```groovy
|
||||
repositories {
|
||||
...
|
||||
|
||||
// Needed to retrieve Cloth Config Lite for Omega Config in development environments.
|
||||
maven {
|
||||
name = "Shedaniel's Maven"
|
||||
url = "https://maven.shedaniel.me/"
|
||||
}
|
||||
|
||||
// Optional dependency for Mod Menu - recommended for viewing your screen in development
|
||||
maven {
|
||||
name = "TerraformersMC"
|
||||
url = "https://maven.terraformersmc.com/releases/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
... (including the base declarations)
|
||||
|
||||
include("com.github.Draylar.omega-config:omega-config-gui:${project.omega_config_version}")
|
||||
modImplementation("com.github.Draylar.omega-config:omega-config-gui:${project.omega_config_version}")
|
||||
modRuntimeOnly ("com.terraformersmc:modmenu:${project.modmenu_version}") // 3.0.1 for 1.18.1
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Extra API Utilities
|
||||
@@ -52,8 +114,11 @@ MyModInitializer.CONFIG.value=false;
|
||||
MyModInitializer.CONFIG.save(); // writes the new value to disk
|
||||
```
|
||||
|
||||
|
||||
**@Syncing** - *configuration options marked with this annotation will automatically sync to the client when they join a server.*
|
||||
|
||||
---
|
||||
|
||||
### 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 MIT. Omega Config will bundle the MIT license inside the jar you pull as a dependency, which means you can distribute it as a bundled dependency without any additional steps.
|
||||
+1
-8
@@ -33,18 +33,13 @@ subprojects {
|
||||
allprojects {
|
||||
apply plugin: "fabric-loom"
|
||||
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
|
||||
version = project.mod_version
|
||||
version = project.mod_version + "-" + project.minecraft_version
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "FabricMC"
|
||||
url = "https://maven.fabricmc.net"
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "TerraformersMC"
|
||||
url = "https://maven.terraformersmc.com/releases/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -52,8 +47,6 @@ allprojects {
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
+4
-4
@@ -3,13 +3,13 @@ org.gradle.jvmargs=-Xmx2G
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/versions.html
|
||||
minecraft_version=1.18.1
|
||||
yarn_mappings=1.18.1+build.2
|
||||
loader_version=0.12.11
|
||||
yarn_mappings=1.18.1+build.12
|
||||
loader_version=0.12.12
|
||||
|
||||
#Fabric api
|
||||
fabric_version=0.44.0+1.18
|
||||
fabric_version=0.45.0+1.18
|
||||
# Mod Properties
|
||||
mod_version=1.2.0
|
||||
mod_version=1.2.2
|
||||
maven_group=draylar
|
||||
archives_base_name=omega-config
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import draylar.omegaconfig.api.Comment;
|
||||
import draylar.omegaconfig.api.Config;
|
||||
import draylar.omegaconfig.gson.SyncableExclusionStrategy;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
@@ -30,7 +31,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class OmegaConfig {
|
||||
public class OmegaConfig implements ModInitializer {
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final Identifier CONFIG_SYNC_PACKET = new Identifier("omegaconfig", "sync");
|
||||
@@ -38,7 +39,8 @@ public class OmegaConfig {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> server.execute(() -> {
|
||||
PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer());
|
||||
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "omega-config",
|
||||
"version": "1.1.0",
|
||||
"version": "${version}",
|
||||
"name": "OmegaConfig",
|
||||
"description": "The last config solution you will ever use.",
|
||||
"authors": [
|
||||
"Draylar",
|
||||
"Frqnny"
|
||||
],
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"draylar.omegaconfig.OmegaConfig"
|
||||
]
|
||||
},
|
||||
"contact": {
|
||||
"homepage": "https://github.com/Draylar/omega-config",
|
||||
"sources": "https://github.com/Draylar/omega-config",
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
repositories {
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven {
|
||||
name = "Shedaniel's Maven"
|
||||
url = "https://maven.shedaniel.me/"
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "TerraformersMC"
|
||||
url = "https://maven.terraformersmc.com/releases/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":omega-config-base")
|
||||
|
||||
// Mod Menu
|
||||
modCompileOnly ("com.terraformersmc:modmenu:${project.modmenu_version}") {
|
||||
transitive(false)
|
||||
}
|
||||
modRuntime ("com.terraformersmc:modmenu:${project.modmenu_version}") {
|
||||
transitive(false)
|
||||
}
|
||||
|
||||
// Cloth Config Lite
|
||||
include "me.shedaniel.cloth:cloth-config-lite-fabric:2.0.6"
|
||||
modApi ("me.shedaniel.cloth:cloth-config-lite-fabric:2.0.6") {
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
|
||||
@@ -2,21 +2,52 @@ package draylar.omegaconfiggui;
|
||||
|
||||
import draylar.omegaconfig.OmegaConfig;
|
||||
import draylar.omegaconfig.api.Config;
|
||||
import draylar.omegaconfiggui.api.screen.OmegaModMenu;
|
||||
import draylar.omegaconfiggui.api.screen.OmegaScreenFactory;
|
||||
import me.shedaniel.clothconfiglite.api.ConfigScreen;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class OmegaConfigGui {
|
||||
|
||||
private static final Map<Config, OmegaScreenFactory<Screen>> REGISTERED_CONFIGURATIONS = new HashMap<>();
|
||||
public static boolean modMenuInitialized = false;
|
||||
|
||||
/**
|
||||
* Registers a ModMenu configuration screen for the given {@link Config} instance.
|
||||
*
|
||||
* @param config registered config to create a ModMenu screen for
|
||||
* @param <T> config type
|
||||
*/
|
||||
public static <T extends Config> void registerConfigScreen(T config) {
|
||||
if(FabricLoader.getInstance().isModLoaded("modmenu")) {
|
||||
// Ensure the config has a valid modid.
|
||||
if(config.getModid() != null) {
|
||||
OmegaScreenFactory<Screen> factory = OmegaConfigGui.getConfigScreenFactory(config);
|
||||
|
||||
if(modMenuInitialized) {
|
||||
OmegaModMenu.injectScreen(config, factory);
|
||||
} else {
|
||||
REGISTERED_CONFIGURATIONS.put(config, factory);
|
||||
}
|
||||
} else {
|
||||
OmegaConfig.LOGGER.warn(String.format("Skipping config screen registration for '%s' - you must implement getModid() in your config class!", config.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a factory which provides new Cloth Config Lite {@link Screen} instances for the given {@link Config}.
|
||||
*
|
||||
* @param config Omega Config instance to create the screen factory for
|
||||
* @return a factory which provides new Cloth Config Lite {@link Screen} instances for the given {@link Config}.
|
||||
*/
|
||||
@@ -60,4 +91,8 @@ public class OmegaConfigGui {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
public static Map<Config, OmegaScreenFactory<Screen>> getConfigScreenFactories() {
|
||||
return REGISTERED_CONFIGURATIONS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,54 +3,20 @@ package draylar.omegaconfiggui.api.screen;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import draylar.omegaconfig.api.Config;
|
||||
import draylar.omegaconfiggui.OmegaConfigGui;
|
||||
import draylar.omegaconfiggui.mixin.modmenu.ModMenuAccessor;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class OmegaModMenu {
|
||||
|
||||
private static final Map<Config, ConfigScreenFactory<Screen>> REGISTERED_CONFIGURATIONS = new HashMap<>();
|
||||
public static boolean modMenuInitialized = false;
|
||||
|
||||
/**
|
||||
* Registers a ModMenu configuration screen for the given {@link Config} instance.
|
||||
*
|
||||
* @param config registered config to create a ModMenu screen for
|
||||
* @param <T> config type
|
||||
*/
|
||||
public static <T extends Config> void registerConfigScreen(T config) {
|
||||
if(FabricLoader.getInstance().isModLoaded("modmenu")) {
|
||||
OmegaScreenFactory<Screen> factory = OmegaConfigGui.getConfigScreenFactory(config);
|
||||
|
||||
if(modMenuInitialized) {
|
||||
OmegaModMenu.injectScreen(config, factory::get);
|
||||
} else {
|
||||
addConfiguration(config, factory::get);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Config> void injectScreen(T config, ConfigScreenFactory<Screen> factory) {
|
||||
public static <T extends Config> void injectScreen(T config, OmegaScreenFactory<Screen> factory) {
|
||||
// they will suspect nothing
|
||||
ModMenuAccessor.setConfigScreenFactories(
|
||||
new ImmutableMap.Builder<String, ConfigScreenFactory<?>>()
|
||||
.putAll(ModMenuAccessor.getConfigScreenFactories())
|
||||
.put(config.getModid(), factory)
|
||||
.put(config.getModid(), factory::get)
|
||||
.build());
|
||||
}
|
||||
|
||||
public static Map<Config, ConfigScreenFactory<Screen>> getRegisteredConfigurations() {
|
||||
return REGISTERED_CONFIGURATIONS;
|
||||
}
|
||||
|
||||
public static void addConfiguration(Config config, ConfigScreenFactory<Screen> screen) {
|
||||
REGISTERED_CONFIGURATIONS.put(config, screen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package draylar.omegaconfiggui.mixin;
|
||||
|
||||
import com.terraformersmc.modmenu.ModMenu;
|
||||
import draylar.omegaconfiggui.OmegaConfigGui;
|
||||
import draylar.omegaconfiggui.api.screen.OmegaModMenu;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
@@ -15,9 +16,9 @@ public class ModMenuMixin {
|
||||
|
||||
@Inject(method = "onInitializeClient", at = @At("RETURN"), remap = false)
|
||||
private void addOmegaConfigurationScreens(CallbackInfo ci) {
|
||||
OmegaModMenu.modMenuInitialized = true;
|
||||
OmegaConfigGui.modMenuInitialized = true;
|
||||
|
||||
// Add loaded configuration screens to mod menu.
|
||||
OmegaModMenu.getRegisteredConfigurations().forEach(OmegaModMenu::injectScreen);
|
||||
OmegaConfigGui.getConfigScreenFactories().forEach(OmegaModMenu::injectScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package draylar.omegatest;
|
||||
|
||||
import draylar.omegaconfiggui.api.screen.OmegaModMenu;
|
||||
import draylar.omegaconfiggui.OmegaConfigGui;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@@ -10,7 +10,7 @@ public class OmegaTestClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
OmegaModMenu.registerConfigScreen(OmegaTestMain.CONFIG);
|
||||
OmegaConfigGui.registerConfigScreen(OmegaTestMain.CONFIG);
|
||||
|
||||
HudRenderCallback.EVENT.register((stack, delta) -> {
|
||||
MinecraftClient.getInstance().textRenderer.draw(stack, new LiteralText(String.valueOf(OmegaTestMain.CONFIG.v)), 15, 15, 0xffffff);
|
||||
|
||||
Reference in New Issue
Block a user