Skip to content

Commit

Permalink
quilt config
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed May 13, 2024
1 parent c9d8e57 commit e28411e
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 324 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
maven { url = "https://maven.gegy.dev/" }
maven { url = "https://maven.terraformersmc.com/releases/" }
maven { url = "https://maven.quiltmc.org/repository/release/" }
maven { url = "https://repo.sleeping.town/" }
}

configurations {
Expand All @@ -26,6 +27,8 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:${project.loader_version}")

modImplementation("com.terraformersmc:modmenu:${project.mod_menu_version}")
implementation("folk.sisby:kaleido-config:0.3.0+1.3.0")
include("folk.sisby:kaleido-config:0.3.0+1.3.0")

Set<String> apiModules = [
"fabric-networking-api-v1",
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/ix0rai/rainglow/Rainglow.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.ix0rai.rainglow;

import com.google.gson.Gson;
import folk.sisby.kaleido.lib.quiltconfig.api.serializers.TomlSerializer;
import folk.sisby.kaleido.lib.quiltconfig.implementor_api.ConfigEnvironment;
import io.ix0rai.rainglow.config.RainglowConfig;
import io.ix0rai.rainglow.data.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
Expand All @@ -26,7 +29,9 @@
public class Rainglow implements ModInitializer {
public static final String MOD_ID = "rainglow";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final RainglowConfig CONFIG = new RainglowConfig();
private static final String FORMAT = "toml";
private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(FabricLoader.getInstance().getConfigDir(), FORMAT, TomlSerializer.INSTANCE);
public static final RainglowConfig CONFIG = RainglowConfig.create(ENVIRONMENT, MOD_ID, MOD_ID, RainglowConfig.class);
public static final Gson GSON = new Gson();

private static final List<RainglowColour> COLOURS = new ArrayList<>();
Expand All @@ -47,7 +52,7 @@ public void onInitialize() {
PayloadTypeRegistry.playS2C().register(RainglowNetworking.ModeSyncPayload.PACKET_ID, RainglowNetworking.ModeSyncPayload.PACKET_CODEC);

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
if (CONFIG.isServerSyncEnabled()) {
if (CONFIG.serverSync.value()) {
// send modes to client
RainglowNetworking.syncModes(handler.player);

Expand All @@ -72,13 +77,15 @@ public static void setMode(RainglowMode mode) {
LOGGER.info("No colours were present in the internal collection, adding blue so that the game doesn't crash");
colours.add(RainglowColour.BLUE);
}

colours.forEach(Rainglow::addColour);
CONFIG.setInitialized();
}

public static void refreshColours() {
// we only ever need to refresh the colours of custom mode, all other sets of colours are immutable
if (CONFIG.getMode().getId().equals("custom")) {
setMode(RainglowMode.byId("custom"));
setMode(RainglowMode.get("custom"));
}
}

Expand Down
16 changes: 11 additions & 5 deletions src/main/java/io/ix0rai/rainglow/client/RainglowClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.ix0rai.rainglow.client;

import folk.sisby.kaleido.lib.quiltconfig.api.values.TrackedValue;
import folk.sisby.kaleido.lib.quiltconfig.api.values.ValueList;
import io.ix0rai.rainglow.Rainglow;
import io.ix0rai.rainglow.data.RainglowColour;
import io.ix0rai.rainglow.data.RainglowMode;
import io.ix0rai.rainglow.data.RainglowResourceReloader;
import io.ix0rai.rainglow.data.RainglowNetworking;
Expand All @@ -26,8 +29,11 @@ public void onInitializeClient() {
client.execute(() -> {
// custom must be set before mode so that if the server sends a custom mode it is set correctly
// otherwise the client's custom would be used
Rainglow.CONFIG.setCustom(payload.customMode());
Rainglow.CONFIG.setMode(RainglowMode.byId(payload.currentMode()));
ValueList<String> list = ValueList.create("", payload.customMode().stream().map(RainglowColour::getId).toArray(String[]::new));
Rainglow.CONFIG.customColours.setOverride(list);
Rainglow.CONFIG.mode.setOverride(payload.currentMode());

// todo override toggles

for (var entry : payload.enabledMobs().entrySet()) {
Rainglow.CONFIG.setEntityEnabled(entry.getKey(), entry.getValue());
Expand Down Expand Up @@ -55,8 +61,8 @@ public void onInitializeClient() {
}

// now that we have modes, we can load the config
if (Rainglow.CONFIG.isUninitialised()) {
Rainglow.CONFIG.reloadFromFile();
if (!Rainglow.CONFIG.isInitialized()) {
Rainglow.setMode(Rainglow.CONFIG.getMode());
}

// log
Expand All @@ -73,7 +79,7 @@ public void onInitializeClient() {
Rainglow.CONFIG.setEditLocked(false);

// reset values to those configured in file
Rainglow.CONFIG.reloadFromFile();
Rainglow.CONFIG.values().forEach(TrackedValue::removeOverride);
}
})
);
Expand Down
152 changes: 0 additions & 152 deletions src/main/java/io/ix0rai/rainglow/config/ConfigIo.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public DeferredSaveOption(String key, TooltipSupplier<T> tooltipSupplier, Option

@Override
public void set(T value) {
T object = (T) this.getValues().validate(value).orElseGet(() -> {
T object = this.getValues().validate(value).orElseGet(() -> {
System.out.println("Illegal option value " + value + " for " + this.text);
return this.defaultValue;
});

if (!MinecraftClient.getInstance().isRunning()) {
this.deferredValue = object;
} else {
Expand Down
Loading

0 comments on commit e28411e

Please sign in to comment.