diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/BackendManagerImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/BackendManagerImpl.java index 75133adeb..f88e5fb74 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/BackendManagerImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/BackendManagerImpl.java @@ -17,8 +17,6 @@ public final class BackendManagerImpl { .supported(() -> true) .register(Flywheel.rl("off")); - public static final Backend DEFAULT_BACKEND = findDefaultBackend(); - private static Backend backend = OFF_BACKEND; private BackendManagerImpl() { @@ -41,7 +39,7 @@ private static ArrayList backendsByPriority() { return backends; } - private static Backend findDefaultBackend() { + public static Backend defaultBackend() { var backendsByPriority = backendsByPriority(); if (backendsByPriority.isEmpty()) { // This probably shouldn't happen, but fail gracefully. diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java index 923053663..c60df1239 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/FlwApiLinkImpl.java @@ -42,7 +42,7 @@ public Backend getOffBackend() { @Override public Backend getDefaultBackend() { - return BackendManagerImpl.DEFAULT_BACKEND; + return BackendManagerImpl.defaultBackend(); } @Override diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java index 061371a35..6027df0a4 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java @@ -100,17 +100,7 @@ public void fromJson(JsonElement json) { readBackend(object); readLimitUpdates(object); readWorkerThreads(object); - readFlwBackend(object); - } - - private void readFlwBackend(JsonObject object) { - var flwBackendJson = object.get("flw_backend"); - - if (flwBackendJson instanceof JsonObject flwBackendObject) { - backendConfig.fromJson(flwBackendObject); - } else { - FlwImpl.CONFIG_LOGGER.warn("'flw_backend' value must be an object"); - } + readFlwBackends(object); } private void readBackend(JsonObject object) { @@ -174,6 +164,16 @@ private void readWorkerThreads(JsonObject object) { workerThreads = WORKER_THREADS_DEFAULT; } + private void readFlwBackends(JsonObject object) { + var flwBackendsJson = object.get("flw_backends"); + + if (flwBackendsJson instanceof JsonObject flwBackendsObject) { + backendConfig.fromJson(flwBackendsObject); + } else { + FlwImpl.CONFIG_LOGGER.warn("'flw_backends' value must be an object"); + } + } + public JsonObject toJson() { JsonObject object = new JsonObject(); object.addProperty("backend", Backend.REGISTRY.getIdOrThrow(backend).toString()); @@ -206,10 +206,10 @@ public void fromJson(JsonObject object) { } private void readLightSmoothness(JsonObject object) { - var backendJson = object.get("lightSmoothness"); + var lightSmoothnessJson = object.get("lightSmoothness"); String msg = null; - if (backendJson instanceof JsonPrimitive primitive && primitive.isString()) { + if (lightSmoothnessJson instanceof JsonPrimitive primitive && primitive.isString()) { var value = primitive.getAsString(); for (var item : LightSmoothness.values()) { @@ -221,7 +221,7 @@ private void readLightSmoothness(JsonObject object) { } msg = "Unknown 'lightSmoothness' value: " + value; - } else if (backendJson != null) { + } else if (lightSmoothnessJson != null) { msg = "'lightSmoothness' value must be a string"; } diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java b/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java index cd1994453..2b50aadb1 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java +++ b/forge/src/main/java/dev/engine_room/flywheel/impl/ForgeFlwConfig.java @@ -83,7 +83,7 @@ public static class ClientConfig { private ClientConfig(ForgeConfigSpec.Builder builder) { backend = builder.comment("Select the backend to use.") - .define("backend", Backend.REGISTRY.getIdOrThrow(BackendManager.defaultBackend()).toString()); + .define("backend", () -> Backend.REGISTRY.getIdOrThrow(BackendManager.defaultBackend()).toString(), o -> o != null && String.class.isAssignableFrom(o.getClass())); limitUpdates = builder.comment("Enable or disable instance update limiting with distance.") .define("limitUpdates", true);