From 6f4d433561b21de8ad2a9bf48d972249c8e2d6d3 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sat, 25 Sep 2021 15:02:08 -0400 Subject: [PATCH] We don't need to store each individual RGB color for maps --- .../java/world/JavaMapDataTranslator.java | 2 +- .../geysermc/connector/utils/MapColor.java | 26 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java index 7dfa08266..0bed6a28b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java @@ -67,7 +67,7 @@ public class JavaMapDataTranslator extends PacketTranslator int idx = 0; for (byte colorId : data.getData()) { - colors[idx++] = MapColor.fromId(colorId & 0xFF).toARGB(); + colors[idx++] = MapColor.fromId(colorId & 0xFF).getARGB(); } mapItemDataPacket.setColors(colors); diff --git a/connector/src/main/java/org/geysermc/connector/utils/MapColor.java b/connector/src/main/java/org/geysermc/connector/utils/MapColor.java index 5e70b1436..2a7c34888 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MapColor.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MapColor.java @@ -277,28 +277,24 @@ public enum MapColor { private static final MapColor[] VALUES = values(); - private final int red; - private final int green; - private final int blue; + private final int value; MapColor(int red, int green, int blue) { - this.red = red; - this.green = green; - this.blue = blue; + int alpha = 255; + if (red == -1 && green == -1 && blue == -1) + alpha = 0; // transparent + + this.value = ((alpha & 0xFF) << 24) | + ((red & 0xFF) << 16) | + ((green & 0xFF) << 8) | + (blue & 0xFF); } public static MapColor fromId(int id) { return id >= 0 && id < VALUES.length ? VALUES[id] : COLOR_0; } - public int toARGB() { - int alpha = 255; - if (red == -1 && green == -1 && blue == -1) - alpha = 0; // transparent - - return ((alpha & 0xFF) << 24) | - ((red & 0xFF) << 16) | - ((green & 0xFF) << 8) | - (blue & 0xFF); + public int getARGB() { + return value; } } \ No newline at end of file