aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt34
-rw-r--r--src/main/kotlin/com/dulkirfabric/config/Pair.kt28
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/RenderTest.kt5
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt2
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt1
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt8
6 files changed, 30 insertions, 48 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
index ac7e209..e8dc743 100644
--- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
+++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
@@ -19,13 +19,13 @@ import com.dulkirfabric.config.ConfigHelper.mkStringField
import com.dulkirfabric.config.ConfigHelper.mkToggle
import com.dulkirfabric.util.render.AnimationPreset
import com.dulkirfabric.util.render.HudElement
-import com.dulkirfabric.util.render.HudElementDefaultPositionings
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import me.shedaniel.clothconfig2.api.ConfigBuilder
+import moe.nea.jarvis.api.Point
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.util.InputUtil
import net.minecraft.client.util.InputUtil.UNKNOWN_KEY
@@ -267,7 +267,7 @@ class DulkirConfig {
var bridgeFormatter: Boolean = false,
var bridgeBotName: String = "Dilkur",
var bridgeNameColor: Int = Formatting.GOLD.colorValue!!,
- var hudPosData: HudElementDefaultPositionings = HudElementDefaultPositionings()
+ val positions: MutableMap<String, HudElement.Positioning> = mutableMapOf(),
)
@Serializable
@@ -288,14 +288,25 @@ class DulkirConfig {
companion object ConfigVars {
var configOptions = ConfigOptions()
- var Huds: MutableMap<(HudElementDefaultPositionings) -> HudElement.Positioning, HudElement> = mutableMapOf()
- fun hudElement(pos: (HudElementDefaultPositionings) -> HudElement.Positioning, label: Text, width: Int, height: Int): HudElement {
- val hud = HudElement(pos(configOptions.hudPosData), label, width, height)
- Huds[pos] = hud
- return hud
+
+ val huds = mutableListOf<Pair<HudElement, Point>>()
+
+ fun hudElement(
+ id: String, label: Text, width: Int, height: Int,
+ defaultPosition: Point
+ ): HudElement {
+ val element = HudElement(
+ configOptions.positions.getOrPut(
+ id,
+ { HudElement.Positioning(defaultPosition.x(), defaultPosition.y(), 1F) }
+ ),
+ id,
+ label, width, height,
+ )
+ huds.add(Pair(element, defaultPosition))
+ return element
}
- val fooHudElement: HudElement = hudElement(HudElementDefaultPositionings::fooPos, Text.literal("§6Hello World!"), 200, 11)
private fun saveConfig() {
val json = Json {
@@ -324,8 +335,11 @@ class DulkirConfig {
}
configOptions = json.decodeFromString<ConfigOptions>(configFile.readText())
}
- Huds.forEach { (a, b) ->
- b.positioning = a(configOptions.hudPosData)
+ huds.forEach { (element, defaultPosition) ->
+ element.positioning = configOptions.positions.getOrPut(
+ element.key,
+ { HudElement.Positioning(defaultPosition.x(), defaultPosition.y(), 1F) }
+ )
}
}
}
diff --git a/src/main/kotlin/com/dulkirfabric/config/Pair.kt b/src/main/kotlin/com/dulkirfabric/config/Pair.kt
deleted file mode 100644
index cf5e914..0000000
--- a/src/main/kotlin/com/dulkirfabric/config/Pair.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.dulkirfabric.config
-
-class Pair<T, R>(val t: T, val r: R) {
-
- fun getLeft(): T {
- return t
- }
-
- fun getRight(): R {
- return r
- }
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- } else if (other != null && this::class == other::class) {
- other as Pair<*, *>
- return t == other.t && r == other.r
- }
- return false
- }
-
- override fun hashCode(): Int {
- var result = t?.hashCode() ?: 0
- result = 31 * result + (r?.hashCode() ?: 0)
- return result
- }
-}
diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
index e139ad0..3442f8a 100644
--- a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
@@ -7,6 +7,7 @@ import com.dulkirfabric.events.HudRenderEvent
import com.dulkirfabric.events.WorldRenderLastEvent
import com.dulkirfabric.util.render.WorldRenderUtils
import meteordevelopment.orbit.EventHandler
+import moe.nea.jarvis.api.Point
import net.minecraft.text.Style
import net.minecraft.text.Text
import net.minecraft.util.math.Vec3d
@@ -34,12 +35,14 @@ object RenderTest {
//event.entity.setDulkirEntityGlow(true, Color(0, 0, 255, 255),false)
}
+ val fooHud = DulkirConfig.hudElement("foobar", Text.literal("Text"), 200, 10, Point(0.4, 0.4))
+
@EventHandler
fun onRenderHud(event: HudRenderEvent) {
val context = event.context
val matrices = context.matrices
matrices.push()
- DulkirConfig.fooHudElement.applyTransformations(matrices)
+ fooHud.applyTransformations(matrices)
context.drawText(mc.textRenderer, Text.literal("§6This is the actual element."),0, 0, -1, true)
matrices.pop()
}
diff --git a/src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt b/src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt
index e1f986b..28b0fd3 100644
--- a/src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/JarvisIntegrationPlugin.kt
@@ -10,6 +10,6 @@ class JarvisIntegrationPlugin: JarvisPlugin {
}
override fun getAllHuds(): List<JarvisHud> {
- return DulkirConfig.Huds.values.toList()
+ return DulkirConfig.huds.map { it.first }
}
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt b/src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt
index 824c745..d545cbf 100644
--- a/src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/render/HudElement.kt
@@ -6,6 +6,7 @@ import moe.nea.jarvis.api.JarvisScalable
import net.minecraft.text.Text
class HudElement (var positioning: Positioning,
+ val key: String,
private val label: Text,
private val width: Int,
private val height: Int
diff --git a/src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt b/src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt
deleted file mode 100644
index 9d27158..0000000
--- a/src/main/kotlin/com/dulkirfabric/util/render/HudElementDefaultPositionings.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.dulkirfabric.util.render
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class HudElementDefaultPositionings(
- var fooPos: HudElement.Positioning = HudElement.Positioning(.1, .1, 1f)
-)