aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/features/items/EtherwarpOverlay.kt8
-rw-r--r--src/main/kotlin/gui/config/ColourHandler.kt82
-rw-r--r--src/main/kotlin/gui/config/ManagedConfig.kt5
-rw-r--r--src/main/kotlin/util/ChromaColourUtil.kt10
4 files changed, 102 insertions, 3 deletions
diff --git a/src/main/kotlin/features/items/EtherwarpOverlay.kt b/src/main/kotlin/features/items/EtherwarpOverlay.kt
index 2de2159..b1f695a 100644
--- a/src/main/kotlin/features/items/EtherwarpOverlay.kt
+++ b/src/main/kotlin/features/items/EtherwarpOverlay.kt
@@ -1,12 +1,13 @@
package moe.nea.firmament.features.items
+import io.github.notenoughupdates.moulconfig.ChromaColour
import me.shedaniel.math.Color
+import net.minecraft.util.hit.BlockHitResult
import moe.nea.firmament.annotations.Subscribe
+import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.util.MC
-import net.minecraft.util.hit.BlockHitResult
-import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.util.extraAttributes
import moe.nea.firmament.util.render.RenderInWorldContext
import moe.nea.firmament.util.skyBlockId
@@ -19,6 +20,7 @@ object EtherwarpOverlay : FirmamentFeature {
object TConfig : ManagedConfig(identifier, Category.ITEMS) {
var etherwarpOverlay by toggle("etherwarp-overlay") { false }
var cube by toggle("cube") { true }
+ val cubeColour by colour("cube-colour") { ChromaColour.fromStaticRGB(172, 0, 255, 60) }
var wireframe by toggle("wireframe") { false }
}
@@ -44,7 +46,7 @@ object EtherwarpOverlay : FirmamentFeature {
if (!world.getBlockState(blockPos.up()).isAir) return
if (!world.getBlockState(blockPos.up(2)).isAir) return
RenderInWorldContext.renderInWorld(event) {
- if (TConfig.cube) block(blockPos, Color.ofRGBA(172, 0, 255, 60).color)
+ if (TConfig.cube) block(blockPos, TConfig.cubeColour.getEffectiveColourRGB())
if (TConfig.wireframe) wireframeCube(blockPos, 10f)
}
}
diff --git a/src/main/kotlin/gui/config/ColourHandler.kt b/src/main/kotlin/gui/config/ColourHandler.kt
new file mode 100644
index 0000000..7d121ab
--- /dev/null
+++ b/src/main/kotlin/gui/config/ColourHandler.kt
@@ -0,0 +1,82 @@
+package moe.nea.firmament.gui.config
+
+import io.github.notenoughupdates.moulconfig.ChromaColour
+import io.github.notenoughupdates.moulconfig.gui.component.ColorSelectComponent
+import kotlinx.serialization.KSerializer
+import kotlinx.serialization.SerialName
+import kotlinx.serialization.Serializable
+import kotlinx.serialization.descriptors.SerialDescriptor
+import kotlinx.serialization.encoding.Decoder
+import kotlinx.serialization.encoding.Encoder
+import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.JsonElement
+
+class ColourHandler(val config: ManagedConfig) :
+ ManagedConfig.OptionHandler<ChromaColour> {
+ @Serializable
+ data class ChromaDelegate(
+ @SerialName("h")
+ val hue: Float,
+ @SerialName("s")
+ val saturation: Float,
+ @SerialName("b")
+ val brightness: Float,
+ @SerialName("a")
+ val alpha: Int,
+ @SerialName("c")
+ val timeForFullRotationInMillis: Int,
+ ) {
+ constructor(delegate: ChromaColour) : this(
+ delegate.hue,
+ delegate.saturation,
+ delegate.brightness,
+ delegate.alpha,
+ delegate.timeForFullRotationInMillis
+ )
+
+ fun into(): ChromaColour = ChromaColour(hue, saturation, brightness, alpha, timeForFullRotationInMillis)
+ }
+
+ object ChromaSerializer : KSerializer<ChromaColour> {
+ override val descriptor: SerialDescriptor
+ get() = SerialDescriptor("FirmChromaColour", ChromaDelegate.serializer().descriptor)
+
+ override fun serialize(
+ encoder: Encoder,
+ value: ChromaColour
+ ) {
+ encoder.encodeSerializableValue(ChromaDelegate.serializer(), ChromaDelegate(value))
+ }
+
+ override fun deserialize(decoder: Decoder): ChromaColour {
+ return decoder.decodeSerializableValue(ChromaDelegate.serializer()).into()
+ }
+ }
+
+ override fun toJson(element: ChromaColour): JsonElement? {
+ return Json.encodeToJsonElement(ChromaSerializer, element)
+ }
+
+ override fun fromJson(element: JsonElement): ChromaColour {
+ return Json.decodeFromJsonElement(ChromaSerializer, element)
+ }
+
+ override fun emitGuiElements(
+ opt: ManagedOption<ChromaColour>,
+ guiAppender: GuiAppender
+ ) {
+ guiAppender.appendLabeledRow(
+ opt.labelText,
+ ColorSelectComponent(
+ 0,
+ 0,
+ opt.value.toLegacyString(),
+ {
+ opt.value = ChromaColour.forLegacyString(it)
+ config.save()
+ },
+ { }
+ )
+ )
+ }
+}
diff --git a/src/main/kotlin/gui/config/ManagedConfig.kt b/src/main/kotlin/gui/config/ManagedConfig.kt
index ba6792d..12b82d6 100644
--- a/src/main/kotlin/gui/config/ManagedConfig.kt
+++ b/src/main/kotlin/gui/config/ManagedConfig.kt
@@ -1,6 +1,7 @@
package moe.nea.firmament.gui.config
import com.mojang.serialization.Codec
+import io.github.notenoughupdates.moulconfig.ChromaColour
import io.github.notenoughupdates.moulconfig.gui.CloseEventListener
import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper
import io.github.notenoughupdates.moulconfig.gui.GuiContext
@@ -118,6 +119,10 @@ abstract class ManagedConfig(
return option(propertyName, default, BooleanHandler(this))
}
+ protected fun colour(propertyName: String, default: ()-> ChromaColour) : ManagedOption<ChromaColour> {
+ return option(propertyName, default, ColourHandler(this))
+ }
+
protected fun <E> choice(
propertyName: String,
enumClass: Class<E>,
diff --git a/src/main/kotlin/util/ChromaColourUtil.kt b/src/main/kotlin/util/ChromaColourUtil.kt
new file mode 100644
index 0000000..0130326
--- /dev/null
+++ b/src/main/kotlin/util/ChromaColourUtil.kt
@@ -0,0 +1,10 @@
+package moe.nea.firmament.util
+
+import io.github.notenoughupdates.moulconfig.ChromaColour
+import java.awt.Color
+
+fun ChromaColour.getRGBAWithoutAnimation() =
+ Color(ChromaColour.specialToSimpleRGB(toLegacyString()), true)
+
+fun Color.toChromaWithoutAnimation(timeForFullRotationInMillis: Int = 0) =
+ ChromaColour.fromRGB(red, green, blue, timeForFullRotationInMillis, alpha)