aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/gui
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-07-17 11:52:28 +0200
committerLinnea Gräf <nea@nea.moe>2025-07-17 11:52:28 +0200
commit25f0e7fd62db22036969120843165f4759530b8f (patch)
tree262ed44e0e68464ba99f7650fed8df102c982fe5 /src/main/kotlin/gui
parent13d64762bbf110fbc52719fb9d93490648199dd2 (diff)
downloadFirmament-25f0e7fd62db22036969120843165f4759530b8f.tar.gz
Firmament-25f0e7fd62db22036969120843165f4759530b8f.tar.bz2
Firmament-25f0e7fd62db22036969120843165f4759530b8f.zip
feat: Launch on 1.21.7
Diffstat (limited to 'src/main/kotlin/gui')
-rw-r--r--src/main/kotlin/gui/BarComponent.kt4
-rw-r--r--src/main/kotlin/gui/CheckboxComponent.kt3
-rw-r--r--src/main/kotlin/gui/config/HudMetaHandler.kt14
-rw-r--r--src/main/kotlin/gui/config/JAnyHud.kt71
-rw-r--r--src/main/kotlin/gui/config/ManagedConfig.kt7
-rw-r--r--src/main/kotlin/gui/entity/EntityRenderer.kt7
-rw-r--r--src/main/kotlin/gui/hud/MoulConfigHud.kt10
7 files changed, 74 insertions, 42 deletions
diff --git a/src/main/kotlin/gui/BarComponent.kt b/src/main/kotlin/gui/BarComponent.kt
index da781da..563e159 100644
--- a/src/main/kotlin/gui/BarComponent.kt
+++ b/src/main/kotlin/gui/BarComponent.kt
@@ -8,6 +8,7 @@ import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext
import io.github.notenoughupdates.moulconfig.observer.GetSetter
import io.github.notenoughupdates.moulconfig.platform.ModernRenderContext
import me.shedaniel.math.Color
+import net.minecraft.client.gl.RenderPipelines
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.render.RenderLayer
import net.minecraft.util.Identifier
@@ -33,7 +34,7 @@ class BarComponent(
) {
fun draw(context: DrawContext, x: Int, y: Int, width: Int, height: Int, color: Color) {
context.drawTexturedQuad(
- RenderLayer::getGuiTextured,
+ RenderPipelines.GUI_TEXTURED,
identifier,
x, y, x + width, x + height,
u1, u2, v1, v2,
@@ -104,7 +105,6 @@ class BarComponent(
(context.width - 4) * total.get() / context.width,
total.get()
)
- RenderSystem.setShaderColor(1F, 1F, 1F, 1F)
}
diff --git a/src/main/kotlin/gui/CheckboxComponent.kt b/src/main/kotlin/gui/CheckboxComponent.kt
index fc48661..9baf720 100644
--- a/src/main/kotlin/gui/CheckboxComponent.kt
+++ b/src/main/kotlin/gui/CheckboxComponent.kt
@@ -5,6 +5,7 @@ import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext
import io.github.notenoughupdates.moulconfig.gui.MouseEvent
import io.github.notenoughupdates.moulconfig.observer.GetSetter
import io.github.notenoughupdates.moulconfig.platform.ModernRenderContext
+import net.minecraft.client.gl.RenderPipelines
import net.minecraft.client.render.RenderLayer
import moe.nea.firmament.Firmament
@@ -27,7 +28,7 @@ class CheckboxComponent<T>(
override fun render(context: GuiImmediateContext) {
val ctx = (context.renderContext as ModernRenderContext).drawContext
ctx.drawGuiTexture(
- RenderLayer::getGuiTextured,
+ RenderPipelines.GUI_TEXTURED,
if (isEnabled()) Firmament.identifier("widget/checkbox_checked")
else Firmament.identifier("widget/checkbox_unchecked"),
0, 0,
diff --git a/src/main/kotlin/gui/config/HudMetaHandler.kt b/src/main/kotlin/gui/config/HudMetaHandler.kt
index a9659ee..0637351 100644
--- a/src/main/kotlin/gui/config/HudMetaHandler.kt
+++ b/src/main/kotlin/gui/config/HudMetaHandler.kt
@@ -8,18 +8,25 @@ import kotlinx.serialization.json.encodeToJsonElement
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.MutableText
import net.minecraft.text.Text
+import moe.nea.firmament.Firmament
import moe.nea.firmament.gui.FirmButtonComponent
import moe.nea.firmament.jarvis.JarvisIntegration
import moe.nea.firmament.util.MC
-class HudMetaHandler(val config: ManagedConfig, val label: MutableText, val width: Int, val height: Int) :
+class HudMetaHandler(
+ val config: ManagedConfig,
+ val propertyName: String,
+ val label: MutableText,
+ val width: Int,
+ val height: Int
+) :
ManagedConfig.OptionHandler<HudMeta> {
override fun toJson(element: HudMeta): JsonElement? {
return Json.encodeToJsonElement(element.position)
}
override fun fromJson(element: JsonElement): HudMeta {
- return HudMeta(Json.decodeFromJsonElement(element), label, width, height)
+ return HudMeta(Json.decodeFromJsonElement(element), Firmament.identifier(propertyName), label, width, height)
}
fun openEditor(option: ManagedOption<HudMeta>, oldScreen: Screen) {
@@ -34,7 +41,8 @@ class HudMetaHandler(val config: ManagedConfig, val label: MutableText, val widt
opt.labelText,
FirmButtonComponent(
TextComponent(
- Text.stringifiedTranslatable("firmament.hud.edit", label).string),
+ Text.stringifiedTranslatable("firmament.hud.edit", label).string
+ ),
) {
openEditor(opt, guiAppender.screenAccessor())
})
diff --git a/src/main/kotlin/gui/config/JAnyHud.kt b/src/main/kotlin/gui/config/JAnyHud.kt
index 35c4eb2..1cde4f9 100644
--- a/src/main/kotlin/gui/config/JAnyHud.kt
+++ b/src/main/kotlin/gui/config/JAnyHud.kt
@@ -1,48 +1,67 @@
-
-
package moe.nea.firmament.gui.config
import moe.nea.jarvis.api.JarvisHud
-import moe.nea.jarvis.api.JarvisScalable
+import org.joml.Matrix3x2f
+import org.joml.Vector2i
+import org.joml.Vector2ic
import kotlinx.serialization.Serializable
import net.minecraft.text.Text
+import net.minecraft.util.Identifier
+import moe.nea.firmament.jarvis.JarvisIntegration
@Serializable
data class HudPosition(
- var x: Double,
- var y: Double,
- var scale: Float,
+ var x: Int,
+ var y: Int,
+ var scale: Float,
)
data class HudMeta(
- val position: HudPosition,
- private val label: Text,
- private val width: Int,
- private val height: Int,
-) : JarvisScalable, JarvisHud {
- override fun getX(): Double = position.x
+ val position: HudPosition,
+ private val id: Identifier,
+ private val label: Text,
+ private val width: Int,
+ private val height: Int,
+) : JarvisHud, JarvisHud.Scalable {
+ override fun getLabel(): Text = label
+ override fun getUnscaledWidth(): Int {
+ return width
+ }
+
+ override fun getUnscaledHeight(): Int {
+ return height
+ }
- override fun setX(newX: Double) {
- position.x = newX
- }
+ override fun getHudId(): Identifier {
+ return id
+ }
- override fun getY(): Double = position.y
+ override fun getPosition(): Vector2ic {
+ return Vector2i(position.x, position.y)
+ }
- override fun setY(newY: Double) {
- position.y = newY
- }
+ override fun setPosition(p0: Vector2ic) {
+ position.x = p0.x()
+ position.y = p0.y()
+ }
- override fun getLabel(): Text = label
+ override fun isEnabled(): Boolean {
+ return true // TODO: this should be actually truthful, if possible
+ }
- override fun getWidth(): Int = width
+ override fun isVisible(): Boolean {
+ return true // TODO: this should be actually truthful, if possible
+ }
- override fun getHeight(): Int = height
+ override fun getScale(): Float = position.scale
- override fun getScale(): Float = position.scale
+ override fun setScale(newScale: Float) {
+ position.scale = newScale
+ }
- override fun setScale(newScale: Float) {
- position.scale = newScale
- }
+ fun applyTransformations(matrix4f: Matrix3x2f) {
+ applyTransformations(JarvisIntegration.jarvis, matrix4f)
+ }
}
diff --git a/src/main/kotlin/gui/config/ManagedConfig.kt b/src/main/kotlin/gui/config/ManagedConfig.kt
index 12b82d6..71d8c66 100644
--- a/src/main/kotlin/gui/config/ManagedConfig.kt
+++ b/src/main/kotlin/gui/config/ManagedConfig.kt
@@ -12,6 +12,7 @@ import io.github.notenoughupdates.moulconfig.gui.component.RowComponent
import io.github.notenoughupdates.moulconfig.gui.component.ScrollPanelComponent
import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
import moe.nea.jarvis.api.Point
+import org.joml.Vector2i
import org.lwjgl.glfw.GLFW
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.JsonElement
@@ -172,13 +173,13 @@ abstract class ManagedConfig(
propertyName: String,
width: Int,
height: Int,
- default: () -> Point,
+ default: () -> Vector2i,
): ManagedOption<HudMeta> {
val label = Text.translatable("firmament.config.${name}.${propertyName}")
return option(propertyName, {
val p = default()
- HudMeta(HudPosition(p.x, p.y, 1F), label, width, height)
- }, HudMetaHandler(this, label, width, height))
+ HudMeta(HudPosition(p.x(), p.y(), 1F), Firmament.identifier(propertyName), label, width, height)
+ }, HudMetaHandler(this, propertyName, label, width, height))
}
protected fun keyBinding(
diff --git a/src/main/kotlin/gui/entity/EntityRenderer.kt b/src/main/kotlin/gui/entity/EntityRenderer.kt
index a1b2577..c17169b 100644
--- a/src/main/kotlin/gui/entity/EntityRenderer.kt
+++ b/src/main/kotlin/gui/entity/EntityRenderer.kt
@@ -121,7 +121,8 @@ object EntityRenderer {
for (modifierJson in modifiers) {
val modifier = ErrorUtil.notNullOr(
modifierJson["type"]?.asString?.let(entityModifiers::get),
- "Could not create entity with id $entityId. Failed to apply modifier $modifierJson") { return null }
+ "Could not create entity with id $entityId. Failed to apply modifier $modifierJson"
+ ) { return null }
entity = modifier.apply(entity, modifierJson)
}
return entity
@@ -217,8 +218,8 @@ object EntityRenderer {
val vector3f = Vector3f(0.0f, (entity.height / 2.0f + bottomOffset).toFloat(), 0.0f)
InventoryScreen.drawEntity(
context,
- centerX,
- centerY,
+ x1, y1,
+ x2, y2,
size.toFloat(),
vector3f,
rotateToFaceTheFront,
diff --git a/src/main/kotlin/gui/hud/MoulConfigHud.kt b/src/main/kotlin/gui/hud/MoulConfigHud.kt
index e99b069..14b7232 100644
--- a/src/main/kotlin/gui/hud/MoulConfigHud.kt
+++ b/src/main/kotlin/gui/hud/MoulConfigHud.kt
@@ -9,6 +9,7 @@ import net.minecraft.resource.SynchronousResourceReloader
import moe.nea.firmament.events.FinalizeResourceManagerEvent
import moe.nea.firmament.events.HudRenderEvent
import moe.nea.firmament.gui.config.HudMeta
+import moe.nea.firmament.jarvis.JarvisIntegration
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.MoulConfigUtils
@@ -42,13 +43,14 @@ abstract class MoulConfigHud(
val renderContext = componentWrapper.createContext(it.context)
if (fragment == null)
loadFragment()
- it.context.matrices.push()
+ it.context.matrices.pushMatrix()
hudMeta.applyTransformations(it.context.matrices)
- val renderContextTranslated =
- renderContext.translated(hudMeta.absoluteX, hudMeta.absoluteY, hudMeta.width, hudMeta.height)
+ val pos = hudMeta.getEffectivePosition(JarvisIntegration.jarvis)
+ val renderContextTranslated =
+ renderContext.translated(pos.x(), pos.y(), hudMeta.effectiveWidth, hudMeta.effectiveHeight)
.scaled(hudMeta.scale)
fragment!!.root.render(renderContextTranslated)
- it.context.matrices.pop()
+ it.context.matrices.popMatrix()
}
FinalizeResourceManagerEvent.subscribe("MoulConfigHud:finalizeResourceManager") {
MC.resourceManager.registerReloader(object : SynchronousResourceReloader {