From e28411e1fc815b0fdfcb93ee0ab397cb556bb124 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 12 May 2024 20:07:17 -0500 Subject: [PATCH] quilt config --- build.gradle | 3 + .../java/io/ix0rai/rainglow/Rainglow.java | 13 +- .../rainglow/client/RainglowClient.java | 16 +- .../io/ix0rai/rainglow/config/ConfigIo.java | 152 ------------- .../rainglow/config/DeferredSaveOption.java | 3 +- .../rainglow/config/RainglowConfig.java | 204 +++++------------- .../rainglow/config/RainglowConfigScreen.java | 12 +- .../io/ix0rai/rainglow/data/RainglowMode.java | 8 +- .../rainglow/data/RainglowNetworking.java | 4 +- .../data/RainglowResourceReloader.java | 3 +- .../client/SlimeEntityRendererMixin.java | 2 +- 11 files changed, 96 insertions(+), 324 deletions(-) delete mode 100644 src/main/java/io/ix0rai/rainglow/config/ConfigIo.java diff --git a/build.gradle b/build.gradle index 22cbaba..4c0a94e 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { @@ -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 apiModules = [ "fabric-networking-api-v1", diff --git a/src/main/java/io/ix0rai/rainglow/Rainglow.java b/src/main/java/io/ix0rai/rainglow/Rainglow.java index 7ec7846..1efb13b 100644 --- a/src/main/java/io/ix0rai/rainglow/Rainglow.java +++ b/src/main/java/io/ix0rai/rainglow/Rainglow.java @@ -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; @@ -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 COLOURS = new ArrayList<>(); @@ -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); @@ -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")); } } diff --git a/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java b/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java index a478f66..985ce8c 100644 --- a/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java +++ b/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java @@ -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; @@ -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 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()); @@ -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 @@ -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); } }) ); diff --git a/src/main/java/io/ix0rai/rainglow/config/ConfigIo.java b/src/main/java/io/ix0rai/rainglow/config/ConfigIo.java deleted file mode 100644 index e3f33f2..0000000 --- a/src/main/java/io/ix0rai/rainglow/config/ConfigIo.java +++ /dev/null @@ -1,152 +0,0 @@ -package io.ix0rai.rainglow.config; - -import io.ix0rai.rainglow.Rainglow; -import net.fabricmc.loader.api.FabricLoader; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ConfigIo { - private static final String CONFIG_FILE_NAME = "rainglow.toml"; - private static final Path CONFIG_FILE_PATH = Paths.get(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME).toUri()); - - private ConfigIo() { - } - - public static boolean parseTomlBoolean(String value) { - return value.equals("true"); - } - - public static int parseTomlInt(String value) { - return Integer.parseInt(value); - } - - public static String parseTomlString(String string) { - try { - return string.split("\"")[1].split("\"")[0]; - } catch (Exception e) { - Rainglow.LOGGER.warn("failed to parse toml string " + string + "; config will reset to default value"); - return ""; - } - } - - public static List parseTomlStringList(String list) { - List parsedList = new ArrayList<>(); - - // trim brackets - try { - String rawList = list.split("\\[")[1].split("]")[0]; - // separate by comma - String[] contents = rawList.split(","); - - for (String item : contents) { - // trim - item = item.trim(); - - // trim quotes and add to list - parsedList.add(item.split("\"")[1].split("\"")[0]); - } - } catch (Exception e) { - Rainglow.LOGGER.error("failed to parse toml list " + list + "; config will reset to default value"); - } - - return parsedList; - } - - public static Map readConfig() { - String content; - try { - content = Files.readString(CONFIG_FILE_PATH); - } catch (IOException e) { - Rainglow.LOGGER.warn("config file not found or corrupted; failed to read: creating new file with default values!"); - createConfigFile(); - return new HashMap<>(); - } - - String[] lines; - try { - lines = content.split("\n"); - } catch (Exception e) { - Rainglow.LOGGER.warn("config file not found or corrupted; failed to read: creating new file with default values!"); - createConfigFile(); - return new HashMap<>(); - } - - Map configData = new HashMap<>(); - - for (String line : lines) { - try { - if (line.isBlank() || line.startsWith("#")) { - continue; - } - - String[] splitLine = line.split("="); - - configData.put(splitLine[0].trim(), splitLine[1].trim()); - } catch (Exception e) { - Rainglow.LOGGER.warn("failed to read line \"" + line + "\" of config file; line will reset to default value"); - } - } - - return configData; - } - - public static void createConfigFile() { - try { - Files.createFile(CONFIG_FILE_PATH); - } catch (IOException e) { - Rainglow.LOGGER.warn("could not create config file!"); - } - } - - public static void writeString(String key, String string) { - write(key, "\"" + string + "\"", "string"); - } - - public static void writeBoolean(String key, boolean bool) { - write(key, bool ? "true" : "false", "boolean"); - } - - public static void writeInt(String key, int value) { - write(key, Integer.toString(value), "int"); - } - - public static void writeStringList(String key, List list) { - // convert to toml-friendly format - StringBuilder tomlCompatibleList = new StringBuilder("["); - for (int i = 0; i < list.size(); i ++) { - tomlCompatibleList.append("\"").append(list.get(i).toString()).append("\"").append(i == list.size() - 1 ? "" : ", "); - } - tomlCompatibleList.append("]"); - - write(key, tomlCompatibleList.toString(), "string list"); - } - - private static void write(String key, String value, String type) { - try { - String content = Files.readString(CONFIG_FILE_PATH); - String[] lines = content.split("\n"); - - for (int i = 0; i < lines.length; i++) { - if (lines[i].startsWith(key)) { - // if key is found replace line - lines[i] = key + " = " + value; - break; - } else if (i == lines.length - 1) { - // if key is not found append it to the end - lines[i] += (!lines[i].isBlank() ? "\n" : "") + key + " = " + value; - } - } - - Files.writeString(CONFIG_FILE_PATH, String.join("\n", lines)); - } catch (IOException e) { - Rainglow.LOGGER.warn("could not write object " + value + " of type " + type + " to config file under key \"" + key + "\"!"); - } - } -} diff --git a/src/main/java/io/ix0rai/rainglow/config/DeferredSaveOption.java b/src/main/java/io/ix0rai/rainglow/config/DeferredSaveOption.java index 7ef3b60..d610d73 100644 --- a/src/main/java/io/ix0rai/rainglow/config/DeferredSaveOption.java +++ b/src/main/java/io/ix0rai/rainglow/config/DeferredSaveOption.java @@ -25,10 +25,11 @@ public DeferredSaveOption(String key, TooltipSupplier 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 { diff --git a/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java b/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java index 8f81cdc..737863b 100644 --- a/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java +++ b/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java @@ -1,122 +1,71 @@ package io.ix0rai.rainglow.config; -import io.ix0rai.rainglow.Rainglow; +import folk.sisby.kaleido.api.ReflectiveConfig; +import folk.sisby.kaleido.lib.quiltconfig.api.annotations.Comment; +import folk.sisby.kaleido.lib.quiltconfig.api.annotations.SerializedNameConvention; +import folk.sisby.kaleido.lib.quiltconfig.api.metadata.NamingSchemes; +import folk.sisby.kaleido.lib.quiltconfig.api.values.TrackedValue; +import folk.sisby.kaleido.lib.quiltconfig.api.values.ValueList; +import folk.sisby.kaleido.lib.quiltconfig.api.values.ValueMap; import io.ix0rai.rainglow.data.RainglowColour; import io.ix0rai.rainglow.data.RainglowEntity; import io.ix0rai.rainglow.data.RainglowMode; -import net.fabricmc.api.EnvType; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; -import java.util.ArrayList; -import java.util.EnumMap; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; - -public class RainglowConfig { - public static final String MODE_KEY = "mode"; - public static final String CUSTOM_KEY = "custom"; - public static final String SERVER_SYNC_KEY = "enable_server_sync"; - - public static final Function TO_CONFIG_KEY = entity -> "enable_" + entity.getId(); - public static final Function RARITY_CONFIG_KEY = entity -> entity.getId() + "_rarity"; - - private RainglowMode mode; - private List custom; - private boolean enableServerSync; - private boolean editLocked = false; - private boolean isInitialised = false; - private final Map entityToggles = new EnumMap<>(RainglowEntity.class); - private final Map entityRarities = new EnumMap<>(RainglowEntity.class); - - public RainglowConfig() { - // we cannot load the config here because it would be loaded before modes, since it's statically initialised - } - - public void reloadFromFile() { - // read config from file - Map config = ConfigIo.readConfig(); - - // parse mode - RainglowMode rainglowMode = RainglowMode.getDefault(); - if (config.containsKey(MODE_KEY)) { - RainglowMode parsedMode = RainglowMode.byId(ConfigIo.parseTomlString(config.get(MODE_KEY))); - if (parsedMode != null) { - rainglowMode = parsedMode; - } - } - - // parse colours for custom mode - // note: we cannot get the default colours from the enum to start off as it's an immutable list - List customColours = new ArrayList<>(); - if (config.containsKey(CUSTOM_KEY)) { - List colours = ConfigIo.parseTomlStringList(config.get(CUSTOM_KEY)); - - for (String colour : colours) { - RainglowColour squidColour = RainglowColour.get(colour); - if (squidColour != null) { - customColours.add(squidColour); - } - } - } - - // parse server sync - boolean serverSync = true; - if (config.containsKey(SERVER_SYNC_KEY)) { - serverSync = ConfigIo.parseTomlBoolean(config.get(SERVER_SYNC_KEY)); - } +import java.util.stream.Collectors; + +@SerializedNameConvention(NamingSchemes.SNAKE_CASE) +public class RainglowConfig extends ReflectiveConfig { + @Comment("The currently active rainglow mode, which determines the possible colours for entities to spawn with.") + @Comment("If custom, will be reset to the default mode if you join a server that does not have the mode.") + public final TrackedValue mode = this.value("rainbow"); + @Comment("For server owners only: whether to sync the rainglow mode and config to clients when they join to give everyone a unified experience.") + @Comment("When this is turned off, players will not be able to see the same colours as each other, and players will see different colours each time they rejoin.") + public final TrackedValue serverSync = this.value(true); + @Comment("The rarity of coloured entities, with 0 making all entities vanilla and 100 making all entities coloured.") + public final TrackedValue> rarities = this.createMap(100); + @Comment("Toggles for disabling colours for each entity.") + public final TrackedValue> toggles = this.createMap(true); + @Comment("The custom colours to use when the mode is set to custom.") + public final TrackedValue> customColours = this.list("", RainglowMode.getDefaultCustom().stream().map(RainglowColour::getId).toArray(String[]::new)); + + private transient boolean editLocked = false; + private transient boolean initialized = false; - // parse entity toggles - for (RainglowEntity entity : RainglowEntity.values()) { - String configKey = TO_CONFIG_KEY.apply(entity); + public RainglowMode getMode() { + return RainglowMode.get(this.mode.value()); + } - if (config.containsKey(configKey)) { - entityToggles.put(entity, ConfigIo.parseTomlBoolean(config.get(configKey))); - } else { - entityToggles.put(entity, true); - } - } + public List getCustom() { + return this.customColours.value().stream().map(RainglowColour::get).collect(Collectors.toList()); + } - // parse rarity + public Map getToggles() { + Map map = new HashMap<>(); for (RainglowEntity entity : RainglowEntity.values()) { - String configKey = RARITY_CONFIG_KEY.apply(entity); - - if (config.containsKey(configKey)) { - entityRarities.put(entity, ConfigIo.parseTomlInt(config.get(configKey))); - } else { - entityRarities.put(entity, 100); - } - } - - // reset colours if parsing failed - if (customColours.isEmpty()) { - customColours = RainglowMode.getDefaultCustom(); + map.put(entity, this.isEntityEnabled(entity)); } - // set and write - this.mode = rainglowMode; - this.custom = customColours; - this.enableServerSync = serverSync; - this.save(false); - - this.isInitialised = true; + return map; } - public RainglowMode getMode() { - return this.mode; + public boolean isEntityEnabled(RainglowEntity entity) { + return this.toggles.value().get(entity.getId()); } - public List getCustom() { - return this.custom; + public void setEntityEnabled(RainglowEntity entity, boolean enabled) { + this.toggles.value().put(entity.getId(), enabled); } public int getRarity(RainglowEntity entity) { - return this.entityRarities.get(entity); + return this.rarities.value().get(entity.getId()); } - public boolean isServerSyncEnabled() { - return this.enableServerSync; + public void setRarity(RainglowEntity entity, int rarity) { + this.rarities.value().put(entity.getId(), rarity); } public boolean isEditLocked(MinecraftClient client) { @@ -124,68 +73,27 @@ public boolean isEditLocked(MinecraftClient client) { return !client.isInSingleplayer() && (client.getCurrentServerEntry() != null && this.editLocked); } - public boolean isUninitialised() { - return !this.isInitialised; - } - - public void setMode(RainglowMode mode) { - this.mode = mode; - Rainglow.setMode(mode); - } - - public void setCustom(List custom) { - this.custom = custom; - Rainglow.refreshColours(); - } - - public void setRarity(RainglowEntity entity, int rarity) { - this.entityRarities.put(entity, rarity); - } - public void setEditLocked(boolean editLocked) { this.editLocked = editLocked; } - public boolean isEntityEnabled(RainglowEntity entity) { - return this.entityToggles.get(entity); - } - - public void setEntityEnabled(RainglowEntity entity, boolean enabled) { - this.entityToggles.put(entity, enabled); - } - - public Map getEntityToggles() { - return this.entityToggles; + public boolean isInitialized() { + return this.initialized; } - public void save(boolean log) { - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER || !this.isEditLocked(MinecraftClient.getInstance())) { - ConfigIo.writeString(MODE_KEY, this.mode.getId()); - this.saveCustom(); - ConfigIo.writeBoolean(SERVER_SYNC_KEY, this.enableServerSync); - writeEntityRarities(); - } - - // entity toggles cannot be locked by the server - this.writeEntityToggles(); - if (log) { - Rainglow.LOGGER.info("saved config!"); - } + public void setInitialized() { + this.initialized = true; } - public void saveCustom() { - ConfigIo.writeStringList(CUSTOM_KEY, this.custom); - } - - private void writeEntityToggles() { - for (Map.Entry entry : entityToggles.entrySet()) { - ConfigIo.writeBoolean(TO_CONFIG_KEY.apply(entry.getKey()), entry.getValue()); + /** + * creates a map of default values for each {@link RainglowEntity} + */ + private TrackedValue> createMap(T defaultValue) { + var builder = this.map(defaultValue); + for (RainglowEntity entity : RainglowEntity.values()) { + builder.put(entity.getId(), defaultValue); } - } - private void writeEntityRarities() { - for (Map.Entry entry : entityRarities.entrySet()) { - ConfigIo.writeInt(RARITY_CONFIG_KEY.apply(entry.getKey()), entry.getValue()); - } + return builder.build(); } } diff --git a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java index d8d5a76..6e1e6ff 100644 --- a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.List; +// todo: now that config uses overrides, edit lock doesn't matter + public class RainglowConfigScreen extends SimpleOptionsScreen { // private final SpruceOption modeOption; // private final SpruceOption customOption; @@ -140,9 +142,13 @@ private static List> createColourRaritySliders() { } private void save() { - for (Option option : this.options) { - if (option instanceof DeferredSaveOption) { - ((DeferredSaveOption) option).save(); + if (Rainglow.CONFIG.isEditLocked(MinecraftClient.getInstance())) { + sendConfigLockedToast(); + } else { + for (Option option : this.options) { + if (option instanceof DeferredSaveOption) { + ((DeferredSaveOption) option).save(); + } } } } diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java b/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java index b62cf7b..97a23e2 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java @@ -97,14 +97,10 @@ public boolean existsLocally() { return this.existsLocally; } - public static RainglowMode byId(String id) { + public static RainglowMode get(String id) { return MODES.get(id); } - public static RainglowMode getDefault() { - return MODES.get("rainbow"); - } - public static void addMode(RainglowMode mode) { MODES.put(mode.id, mode); } @@ -148,7 +144,7 @@ public static RainglowMode read(PacketByteBuf buf) { Text text = TextCodecs.UNLIMITED_TEXT_PACKET_CODEC.decode(buf); List colourIds = buf.readList(PacketByteBuf::readString); - return new RainglowMode(id, colourIds, text, RainglowMode.byId(id) != null); + return new RainglowMode(id, colourIds, text, RainglowMode.get(id) != null); } diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowNetworking.java b/src/main/java/io/ix0rai/rainglow/data/RainglowNetworking.java index ff6513d..6c972b4 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowNetworking.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowNetworking.java @@ -1,14 +1,12 @@ package io.ix0rai.rainglow.data; import io.ix0rai.rainglow.Rainglow; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.packet.payload.CustomPayload; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Identifier; import java.util.Collection; import java.util.List; @@ -18,7 +16,7 @@ public class RainglowNetworking { public static void syncConfig(ServerPlayerEntity player) { // note: client does not need to know if server sync is enabled or not // they already know that it is enabled because they are receiving this packet - ServerPlayNetworking.send(player, new ConfigSyncPayload(Rainglow.CONFIG.getMode().getId(), Rainglow.CONFIG.getCustom(), Rainglow.CONFIG.getEntityToggles())); + ServerPlayNetworking.send(player, new ConfigSyncPayload(Rainglow.CONFIG.mode.value(), Rainglow.CONFIG.getCustom(), Rainglow.CONFIG.getToggles())); } public record ConfigSyncPayload(String currentMode, List customMode, Map enabledMobs) implements CustomPayload { diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java b/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java index 2d1befc..5c91c4c 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java @@ -47,8 +47,7 @@ default void reload(ResourceManager manager) { this.log(); // load config - if (Rainglow.CONFIG.isUninitialised() || (FabricLoader.getInstance().getEnvironmentType().equals(EnvType.CLIENT) && !Rainglow.CONFIG.isEditLocked(MinecraftClient.getInstance()))) { - Rainglow.CONFIG.reloadFromFile(); + if (!Rainglow.CONFIG.isInitialized() || (FabricLoader.getInstance().getEnvironmentType().equals(EnvType.CLIENT) && !Rainglow.CONFIG.isEditLocked(MinecraftClient.getInstance()))) { Rainglow.setMode(Rainglow.CONFIG.getMode()); } } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java index a40d18f..d93ede4 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java @@ -19,7 +19,7 @@ public void getTexture(SlimeEntity entity, CallbackInfoReturnable ci String colour = Rainglow.getColour(RainglowEntity.SLIME, entity.getDataTracker(), entity.getRandom()); // don't override if the colour is lime, use the default texture - if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.SLIME) && !colour.equals(RainglowColour.LIME.getId()) || Rainglow.CONFIG.getMode().equals(RainglowMode.byId("vanilla"))) { + if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.SLIME) && !colour.equals(RainglowColour.LIME.getId()) || Rainglow.CONFIG.getMode().equals(RainglowMode.get("vanilla"))) { Identifier texture = Rainglow.getTexture(RainglowEntity.SLIME, colour); cir.setReturnValue(texture != null ? texture : Rainglow.getDefaultTexture(RainglowEntity.SLIME)); }