Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58c420d35f | ||
|
|
270db37dba | ||
|
|
2968111445 | ||
|
|
136cfe6a9a |
+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 {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ loader_version=0.12.11
|
||||
#Fabric api
|
||||
fabric_version=0.44.0+1.18
|
||||
# Mod Properties
|
||||
mod_version=1.2.0
|
||||
mod_version=1.2.1
|
||||
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());
|
||||
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
"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