From f2d10e5d9c33984e948005cce22c7af3b9da8144 Mon Sep 17 00:00:00 2001 From: CodexAdrian <83074853+CodexAdrian@users.noreply.github.com> Date: Sat, 31 Aug 2024 14:16:51 -0400 Subject: [PATCH 1/3] Update Color.java --- .../resourcefullib/common/color/Color.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java index 4db475f..0837f90 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java @@ -10,6 +10,7 @@ import com.teamresourceful.resourcefullib.common.utils.Scheduling; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextColor; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Locale; @@ -24,16 +25,16 @@ public class Color { protected static final Map colorsWithNames = new HashMap<>(); - public static final Codec CODEC = Codec.PASSTHROUGH.comapFlatMap(Color::decodeColor, color -> new Dynamic<>(JsonOps.INSTANCE, new JsonPrimitive(color.value))); + public static final Codec CODEC = Codec.PASSTHROUGH.comapFlatMap(Color::decodeColor, color -> new Dynamic<>(JsonOps.INSTANCE, new JsonPrimitive(color.toString()))); public static final Color DEFAULT = defaultColor(); public static final Color RAINBOW = createRainbowColor(); public static final ByteCodec BYTE_CODEC = ByteCodec.BYTE.dispatch(aByte -> switch (aByte) { case 0 -> ByteCodec.unit(DEFAULT); - case 1 -> ByteCodec.unit(RAINBOW); + case 1 -> ByteCodec.STRING.map(Color::parse, Color::toString); default -> ByteCodec.INT.map(Color::new, Color::getValue); }, color -> { if (color.isDefault()) return (byte) 0; - if (color.isRainbow()) return (byte) 1; + if (color.isSpecial()) return (byte) 1; return (byte) 2; }); @@ -48,7 +49,9 @@ public class Color { private int value; private boolean defaultValue; - private boolean isRainbow; + + @Nullable + private String specialName; private float[] rgbaValue; @@ -86,14 +89,15 @@ private static Color defaultColor() { private static Color createRainbowColor() { Color color = new Color(0xff0000); - color.isRainbow = true; + color.specialName = "rainbow"; colorsWithNames.put("rainbow", color); return color; } public static Color createNamedColor(String name, int value) { Color color = new Color(value); - colorsWithNames.putIfAbsent(name.toLowerCase(Locale.ENGLISH), color); + color.specialName = name.toLowerCase(Locale.ENGLISH); + colorsWithNames.putIfAbsent(color.specialName, color); return color; } @@ -188,26 +192,34 @@ public boolean isDefault() { return defaultValue; } + /** + * @deprecated Use {@link #isSpecial()} instead. + */ + @Deprecated public boolean isRainbow() { - return isRainbow; + return specialName != null && specialName.equals("rainbow"); + } + + public boolean isSpecial() { + return specialName != null; } @Override public String toString() { - if (this.isRainbow) return "rainbow"; + if (specialName != null) return specialName; return String.format("#%x", this.value); } @Override public int hashCode() { - return Objects.hash(defaultValue, isRainbow, value); + return Objects.hash(defaultValue, specialName, value); } @Override public boolean equals(Object obj) { return obj instanceof Color color && color.value == this.value && - color.isRainbow == this.isRainbow && + color.specialName == this.specialName && color.defaultValue == this.defaultValue; } From 3d4279b8b23706445f582984a2583aa8df9415b8 Mon Sep 17 00:00:00 2001 From: "Adrian O.V" <83074853+CodexAdrian@users.noreply.github.com> Date: Sat, 31 Aug 2024 14:31:53 -0400 Subject: [PATCH 2/3] Update Color.java --- .../com/teamresourceful/resourcefullib/common/color/Color.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java index 0837f90..87ee29f 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java @@ -197,7 +197,7 @@ public boolean isDefault() { */ @Deprecated public boolean isRainbow() { - return specialName != null && specialName.equals("rainbow"); + return "rainbow".equals(specialName); } public boolean isSpecial() { From e1ec392896a675e3bef313ec13a20df26cc030f3 Mon Sep 17 00:00:00 2001 From: CodexAdrian <83074853+CodexAdrian@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:25:27 -0400 Subject: [PATCH 3/3] Mark for removal --- .../com/teamresourceful/resourcefullib/common/color/Color.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java index 87ee29f..162f3cb 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/color/Color.java @@ -10,6 +10,7 @@ import com.teamresourceful.resourcefullib.common.utils.Scheduling; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextColor; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.HashMap; @@ -196,6 +197,7 @@ public boolean isDefault() { * @deprecated Use {@link #isSpecial()} instead. */ @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "1.21.2") public boolean isRainbow() { return "rainbow".equals(specialName); }