diff --git a/src/main/java/de/bixilon/minosoft/data/text/RGBColor.kt b/src/main/java/de/bixilon/minosoft/data/text/RGBColor.kt index d9e96f3da..2fe1d0f48 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/RGBColor.kt +++ b/src/main/java/de/bixilon/minosoft/data/text/RGBColor.kt @@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.text import org.checkerframework.common.value.qual.IntRange -class RGBColor(val color: Int) : ChatCode { +class RGBColor(val rgba: Int) : ChatCode { @JvmOverloads constructor(red: Int, green: Int, blue: Int, alpha: Int = 0xFF) : this(alpha or (blue shl 8) or (green shl 16) or (red shl 24)) @@ -24,22 +24,31 @@ class RGBColor(val color: Int) : ChatCode { constructor(colorString: String) : this(colorString.toColorInt()) val alpha: @IntRange(from = 0.toLong(), to = 255.toLong()) Int - get() = color and 0xFF + get() = rgba and 0xFF + val red: @IntRange(from = 0.toLong(), to = 255.toLong()) Int - get() = color ushr 24 and 0xFF + get() = rgba ushr 24 and 0xFF + val floatRed: @IntRange(from = 0.toLong(), to = 1.toLong()) Float get() = red / COLOR_FLOAT_DIVIDER + val green: @IntRange(from = 0.toLong(), to = 255.toLong()) Int - get() = color ushr 16 and 0xFF + get() = rgba ushr 16 and 0xFF + val floatGreen: @IntRange(from = 0.toLong(), to = 1.toLong()) Float get() = green / COLOR_FLOAT_DIVIDER + val blue: @IntRange(from = 0.toLong(), to = 255.toLong()) Int - get() = color ushr 8 and 0xFF + get() = rgba ushr 8 and 0xFF + val floatBlue: @IntRange(from = 0.toLong(), to = 1.toLong()) Float get() = blue / COLOR_FLOAT_DIVIDER + val rgb: Int + get() = rgba ushr 8 + override fun hashCode(): Int { - return color + return rgba } override fun equals(other: Any?): Boolean { @@ -47,19 +56,20 @@ class RGBColor(val color: Int) : ChatCode { return true } val their = other as RGBColor? ?: return false - return color == their.color + return rgba == their.rgba } override fun toString(): String { return if (alpha != 255) { - String.format("#%08X", color) + String.format("#%08X", rgba) } else { - String.format("#%06X", 0xFFFFFF and color) + String.format("#%06X", 0xFFFFFF and rgba) } } companion object { private const val COLOR_FLOAT_DIVIDER = 255.0f + fun noAlpha(color: Int): RGBColor { return RGBColor(color shl 8 or 0xFF) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt index 3513893e8..dc9ddaafc 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt @@ -48,7 +48,7 @@ class SectionArrayMesh : Mesh(initialCacheSize = 100000) { textureCoordinates.y * texture.uvEnd.y, Float.fromBits(textureLayer), Float.fromBits(texture.properties.animation?.animationId ?: -1), - Float.fromBits(lightColor.color ushr 8), + Float.fromBits(lightColor.rgb), )) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/HUDCacheMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/HUDCacheMesh.kt index a24b6b618..903a21813 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/HUDCacheMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/HUDCacheMesh.kt @@ -38,7 +38,7 @@ class HUDCacheMesh( if (tintColor == null) { 0.0f } else { - Float.fromBits(tintColor.color) + Float.fromBits(tintColor.rgba) }, )) } diff --git a/src/main/java/de/bixilon/minosoft/util/json/RGBColorSerializer.kt b/src/main/java/de/bixilon/minosoft/util/json/RGBColorSerializer.kt index c003d0c04..f0c2c0dd1 100644 --- a/src/main/java/de/bixilon/minosoft/util/json/RGBColorSerializer.kt +++ b/src/main/java/de/bixilon/minosoft/util/json/RGBColorSerializer.kt @@ -35,9 +35,9 @@ object RGBColorSerializer : JsonAdapter() { jsonWriter.nullValue() return } - if (color.color == 0) { + if (color.rgba == 0) { jsonWriter.nullValue() } - jsonWriter.value(color.color) + jsonWriter.value(color.rgba) } }