fix: avoid premature muScript initialization with libjf-config-reflect
This commit is contained in:
parent
5b8164e855
commit
0611e42731
|
@ -2,14 +2,14 @@ package io.gitlab.jfronny.respackopts.integration;
|
||||||
|
|
||||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
|
||||||
import io.gitlab.jfronny.respackopts.RespackoptsClient;
|
import io.gitlab.jfronny.respackopts.RespackoptsClient;
|
||||||
|
import io.gitlab.jfronny.respackopts.RespackoptsConfig;
|
||||||
|
|
||||||
public class ModMenuIntegration implements ModMenuApi {
|
public class ModMenuIntegration implements ModMenuApi {
|
||||||
@Override
|
@Override
|
||||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
return parent -> {
|
return parent -> {
|
||||||
io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory.Built<?> built = io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory.getInstance().create(Respackopts.CONFIG, parent);
|
io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory.Built<?> built = io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory.getInstance().create(RespackoptsConfig.configInstance, parent);
|
||||||
built.onSave(() -> {
|
built.onSave(() -> {
|
||||||
if (RespackoptsClient.forcePackReload) {
|
if (RespackoptsClient.forcePackReload) {
|
||||||
RespackoptsClient.forceReloadResources();
|
RespackoptsClient.forceReloadResources();
|
||||||
|
|
|
@ -3,7 +3,6 @@ package io.gitlab.jfronny.respackopts;
|
||||||
import io.gitlab.jfronny.commons.log.Logger;
|
import io.gitlab.jfronny.commons.log.Logger;
|
||||||
import io.gitlab.jfronny.gson.Gson;
|
import io.gitlab.jfronny.gson.Gson;
|
||||||
import io.gitlab.jfronny.gson.GsonBuilder;
|
import io.gitlab.jfronny.gson.GsonBuilder;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.ConfigInstance;
|
|
||||||
import io.gitlab.jfronny.muscript.StandardLib;
|
import io.gitlab.jfronny.muscript.StandardLib;
|
||||||
import io.gitlab.jfronny.muscript.ast.*;
|
import io.gitlab.jfronny.muscript.ast.*;
|
||||||
import io.gitlab.jfronny.muscript.data.Scope;
|
import io.gitlab.jfronny.muscript.data.Scope;
|
||||||
|
@ -82,11 +81,9 @@ public class Respackopts implements ModInitializer, SaveHook {
|
||||||
ServerInstanceHolder.init();
|
ServerInstanceHolder.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigInstance CONFIG;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> onSave(Arguments args) {
|
public CompletableFuture<Void> onSave(Arguments args) {
|
||||||
CONFIG.write();
|
RespackoptsConfig.configInstance.write();
|
||||||
|
|
||||||
if (args.reloadData() && FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
|
if (args.reloadData() && FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
|
||||||
ServerInstanceHolder.reloadResources();
|
ServerInstanceHolder.reloadResources();
|
||||||
|
|
|
@ -4,6 +4,7 @@ import io.gitlab.jfronny.libjf.config.api.v1.ConfigInstance;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.JfCustomConfig;
|
import io.gitlab.jfronny.libjf.config.api.v1.JfCustomConfig;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.dsl.DSL;
|
import io.gitlab.jfronny.libjf.config.api.v1.dsl.DSL;
|
||||||
import io.gitlab.jfronny.respackopts.util.MetaCache;
|
import io.gitlab.jfronny.respackopts.util.MetaCache;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -14,16 +15,21 @@ public class RespackoptsConfig implements JfCustomConfig {
|
||||||
public static boolean ioLogs = false;
|
public static boolean ioLogs = false;
|
||||||
public static boolean dashloaderCompat = true;
|
public static boolean dashloaderCompat = true;
|
||||||
|
|
||||||
|
public static boolean packsInitialized = false;
|
||||||
|
public static ConfigInstance configInstance = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(DSL.Defaulted dsl) {
|
public void register(DSL.Defaulted dsl) {
|
||||||
if (Respackopts.CONFIG != null) return;
|
if (configInstance != null) return;
|
||||||
Respackopts.CONFIG = dsl.register(builder -> builder
|
configInstance = dsl.register(builder -> builder
|
||||||
.value("debugCommands", debugCommands, () -> debugCommands, v -> debugCommands = v)
|
.value("debugCommands", debugCommands, () -> debugCommands, v -> debugCommands = v)
|
||||||
.value("debugLogs", debugLogs, () -> debugLogs, v -> debugLogs = v)
|
.value("debugLogs", debugLogs, () -> debugLogs, v -> debugLogs = v)
|
||||||
.value("ioLogs", ioLogs, () -> ioLogs, v -> ioLogs = v)
|
.value("ioLogs", ioLogs, () -> ioLogs, v -> ioLogs = v)
|
||||||
.value("dashloaderCompat", dashloaderCompat, () -> dashloaderCompat, v -> dashloaderCompat = v)
|
.value("dashloaderCompat", dashloaderCompat, () -> dashloaderCompat, v -> dashloaderCompat = v)
|
||||||
.setPath(Respackopts.FALLBACK_CONF_DIR.resolve("_respackopts.conf"))
|
// Not using Respackopts.FALLBACK_CONF_DIR to avoid premature initialization with libjf-unsafe and libjf-config-reflect
|
||||||
|
.setPath(FabricLoader.getInstance().getConfigDir().resolve("respackopts").resolve("_respackopts.conf"))
|
||||||
.referenceConfig(() -> {
|
.referenceConfig(() -> {
|
||||||
|
if (!packsInitialized) return List.of();
|
||||||
List<ConfigInstance> instances = new LinkedList<>();
|
List<ConfigInstance> instances = new LinkedList<>();
|
||||||
MetaCache.forEach((key, state) -> instances.add(DSL.create(state.packId())
|
MetaCache.forEach((key, state) -> instances.add(DSL.create(state.packId())
|
||||||
.config(cb -> state.configBranch().buildConfig(cb, state.packId(), key.dataLocation()))
|
.config(cb -> state.configBranch().buildConfig(cb, state.packId(), key.dataLocation()))
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class ResourcePackManagerMixin {
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "scanPacks()V")
|
@Inject(at = @At("TAIL"), method = "scanPacks()V")
|
||||||
private void scanPacks(CallbackInfo info) {
|
private void scanPacks(CallbackInfo info) {
|
||||||
|
RespackoptsConfig.packsInitialized = true;
|
||||||
FallbackI18n.clear();
|
FallbackI18n.clear();
|
||||||
Set<Path> newDataLocations = new HashSet<>();
|
Set<Path> newDataLocations = new HashSet<>();
|
||||||
Set<Path> toRemove = new HashSet<>(dataLocations);
|
Set<Path> toRemove = new HashSet<>(dataLocations);
|
||||||
|
|
Loading…
Reference in New Issue