From 91909478c584695f215f92de8b11ff692df8a72b Mon Sep 17 00:00:00 2001 From: ix0rai Date: Mon, 27 May 2024 22:05:22 -0500 Subject: [PATCH] remove dumb existsLocally logic in server sync --- .../rainglow/client/RainglowClient.java | 8 +++----- .../io/ix0rai/rainglow/data/RainglowMode.java | 20 ++++--------------- .../data/RainglowResourceReloader.java | 8 +++----- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java b/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java index c84c628..c0bb1fc 100644 --- a/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java +++ b/src/main/java/io/ix0rai/rainglow/client/RainglowClient.java @@ -58,12 +58,10 @@ public void onInitializeClient() { client.execute(() -> { List newModeIds = new ArrayList<>(); - // add modes that do not exist on the client to the map + // add modes on the client for (RainglowMode mode : payload.modes()) { - if (!mode.existsLocally()) { - newModeIds.add(mode.getId()); - RainglowMode.addMode(mode); - } + newModeIds.add(mode.getId()); + RainglowMode.addMode(mode); } diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java b/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java index 4c94a53..bb07e89 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowMode.java @@ -19,18 +19,16 @@ public class RainglowMode { private final String id; private final List colours = new ArrayList<>(); private final Text text; - private final boolean existsLocally; - public RainglowMode(JsonMode mode, boolean existsLocally) { + public RainglowMode(JsonMode mode) { this( mode.id, mode.colourIds, - Rainglow.translatableText("mode." + mode.id).copy().setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Integer.parseInt(mode.textColour, 16)))), - existsLocally + Rainglow.translatableText("mode." + mode.id).copy().setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Integer.parseInt(mode.textColour, 16)))) ); } - public RainglowMode(String id, List colourIds, Text text, boolean existsLocally) { + public RainglowMode(String id, List colourIds, Text text) { if (!id.matches("^[a-z0-9_]+$")) { Rainglow.LOGGER.error("loaded rainglow mode with id {} which contains invalid characters! (only lowercase letters, numbers, and underscores are allowed)", id); } @@ -51,7 +49,6 @@ public RainglowMode(String id, List colourIds, Text text, boolean exists } this.text = text; - this.existsLocally = existsLocally; MODES.put(this.id, this); } @@ -79,10 +76,6 @@ public String getId() { return this.id; } - public boolean existsLocally() { - return this.existsLocally; - } - public static RainglowMode get(String id) { return MODES.get(id); } @@ -99,11 +92,6 @@ public static List getDefaultCustom() { return List.of(RainglowColour.BLUE, RainglowColour.WHITE, RainglowColour.PINK); } - public static void clearUniversalModes() { - Collection modes = List.copyOf(MODES.values()); - for (RainglowMode mode : modes) if (mode.existsLocally()) MODES.remove(mode.id); - } - public static void printLoadedModes() { StringBuilder formatted = new StringBuilder(); for (RainglowMode mode : MODES.values()) @@ -130,7 +118,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.get(id) != null); + return new RainglowMode(id, colourIds, text); } diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java b/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java index 1fea62d..38b921a 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowResourceReloader.java @@ -20,10 +20,6 @@ default void log() { @Override default void reload(ResourceManager manager) { - // remove existing modes to avoid adding duplicates - // this only clears modes that exist on both the server and the client - // otherwise we would have to re-request the mode data packet on every reload - RainglowMode.clearUniversalModes(); Rainglow.RAINGLOW_DATAPACKS.clear(); // load custom modes from rainglow/custom_modes in the datapack @@ -36,9 +32,11 @@ default void reload(ResourceManager manager) { try (InputStream stream = entry.getValue().open()) { Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8); RainglowMode.JsonMode result = Rainglow.GSON.fromJson(reader, RainglowMode.JsonMode.class); - RainglowMode.addMode(new RainglowMode(result, true)); + // todo logic for handling duplicates String name = entry.getValue().getSourceName(); + RainglowMode.addMode(new RainglowMode(result)); + if (this.getFabricId().equals(Rainglow.SERVER_MODE_DATA_ID) && !Rainglow.RAINGLOW_DATAPACKS.contains(name)) { Rainglow.RAINGLOW_DATAPACKS.add(name); }