aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-08-07 21:34:16 +0200
committerLinnea Gräf <nea@nea.moe>2024-08-07 21:34:16 +0200
commitb4f9ca21ef801bb3e39c53ae21bb6bf4398c94e9 (patch)
tree1f7928e5587b6d4d7ca071949f0a70bf81282c14 /src/main/kotlin/moe/nea/firmament/util
parent9b277bd897490d13ee4549a086e8d1b5f4cd0e10 (diff)
downloadFirmament-b4f9ca21ef801bb3e39c53ae21bb6bf4398c94e9.tar.gz
Firmament-b4f9ca21ef801bb3e39c53ae21bb6bf4398c94e9.tar.bz2
Firmament-b4f9ca21ef801bb3e39c53ae21bb6bf4398c94e9.zip
Add /firm npcs command
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt83
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt11
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt11
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt11
4 files changed, 101 insertions, 15 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt b/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt
index 2884dc5..b99c1fc 100644
--- a/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt
@@ -18,13 +18,19 @@ import io.github.notenoughupdates.moulconfig.xml.XMLGuiLoader
import io.github.notenoughupdates.moulconfig.xml.XMLUniverse
import io.github.notenoughupdates.moulconfig.xml.XSDGenerator
import java.io.File
+import java.util.function.Supplier
import javax.xml.namespace.QName
import me.shedaniel.math.Color
import org.w3c.dom.Element
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.seconds
import net.minecraft.client.gui.screen.Screen
import moe.nea.firmament.gui.BarComponent
import moe.nea.firmament.gui.FirmButtonComponent
+import moe.nea.firmament.gui.FirmHoverComponent
import moe.nea.firmament.gui.FixedComponent
+import moe.nea.firmament.gui.ImageComponent
+import moe.nea.firmament.gui.TickComponent
object MoulConfigUtils {
val firmUrl = "http://firmament.nea.moe/moulconfig"
@@ -69,6 +75,31 @@ object MoulConfigUtils {
return mapOf("progress" to true, "total" to true, "emptyColor" to true, "fillColor" to true)
}
})
+ uni.registerLoader(object : XMLGuiLoader.Basic<FirmHoverComponent> {
+ override fun createInstance(context: XMLContext<*>, element: Element): FirmHoverComponent {
+ return FirmHoverComponent(
+ context.getChildFragment(element),
+ context.getPropertyFromAttribute(element, QName("lines"), List::class.java) as Supplier<List<String>>,
+ context.getPropertyFromAttribute(element, QName("delay"), Duration::class.java, 0.6.seconds),
+ )
+ }
+
+ override fun getName(): QName {
+ return QName(firmUrl, "Hover")
+ }
+
+ override fun getChildCount(): ChildCount {
+ return ChildCount.ONE
+ }
+
+ override fun getAttributeNames(): Map<String, Boolean> {
+ return mapOf(
+ "lines" to true,
+ "delay" to false,
+ )
+ }
+
+ })
uni.registerLoader(object : XMLGuiLoader.Basic<FirmButtonComponent> {
override fun getName(): QName {
return QName(firmUrl, "Button")
@@ -79,6 +110,7 @@ object MoulConfigUtils {
context.getChildFragment(element),
context.getPropertyFromAttribute(element, QName("enabled"), Boolean::class.java)
?: GetSetter.constant(true),
+ context.getPropertyFromAttribute(element, QName("noBackground"), Boolean::class.java, false),
context.getMethodFromAttribute(element, QName("onClick")),
)
}
@@ -88,7 +120,56 @@ object MoulConfigUtils {
}
override fun getAttributeNames(): Map<String, Boolean> {
- return mapOf("onClick" to true, "enabled" to false)
+ return mapOf("onClick" to true, "enabled" to false, "noBackground" to false)
+ }
+ })
+ uni.registerLoader(object : XMLGuiLoader.Basic<ImageComponent> {
+ override fun createInstance(context: XMLContext<*>, element: Element): ImageComponent {
+ return ImageComponent(
+ context.getPropertyFromAttribute(element, QName("width"), Int::class.java)!!.get(),
+ context.getPropertyFromAttribute(element, QName("height"), Int::class.java)!!.get(),
+ context.getPropertyFromAttribute(element, QName("resource"), MyResourceLocation::class.java)!!,
+ context.getPropertyFromAttribute(element, QName("u1"), Float::class.java, 0f),
+ context.getPropertyFromAttribute(element, QName("u2"), Float::class.java, 1f),
+ context.getPropertyFromAttribute(element, QName("v1"), Float::class.java, 0f),
+ context.getPropertyFromAttribute(element, QName("v2"), Float::class.java, 1f),
+ )
+ }
+
+ override fun getName(): QName {
+ return QName(firmUrl, "Image")
+ }
+
+ override fun getChildCount(): ChildCount {
+ return ChildCount.NONE
+ }
+
+ override fun getAttributeNames(): Map<String, Boolean> {
+ return mapOf(
+ "width" to true, "height" to true,
+ "resource" to true,
+ "u1" to false,
+ "u2" to false,
+ "v1" to false,
+ "v2" to false,
+ )
+ }
+ })
+ uni.registerLoader(object : XMLGuiLoader.Basic<TickComponent> {
+ override fun createInstance(context: XMLContext<*>, element: Element): TickComponent {
+ return TickComponent(context.getMethodFromAttribute(element, QName("tick")))
+ }
+
+ override fun getName(): QName {
+ return QName(firmUrl, "Tick")
+ }
+
+ override fun getChildCount(): ChildCount {
+ return ChildCount.NONE
+ }
+
+ override fun getAttributeNames(): Map<String, Boolean> {
+ return mapOf("tick" to true)
}
})
uni.registerLoader(object : XMLGuiLoader.Basic<FixedComponent> {
diff --git a/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt b/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt
index 7a20346..ca8bac6 100644
--- a/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt
@@ -31,8 +31,8 @@ object WarpUtil {
private var lastAttemptedWarp = ""
private var lastWarpAttempt = TimeMark.farPast()
fun findNearestWarp(island: SkyBlockIsland, pos: Position): Islands.Warp? {
- return warps.minByOrNull {
- if (island.locrawMode != it.mode || (DConfig.data?.excludedWarps?.contains(it.warp) == true)) {
+ return warps.asSequence().filter { it.mode == island.locrawMode }.minByOrNull {
+ if (DConfig.data?.excludedWarps?.contains(it.warp) == true) {
return@minByOrNull Double.MAX_VALUE
} else {
return@minByOrNull squaredDist(pos, it)
@@ -48,8 +48,11 @@ object WarpUtil {
}
fun teleportToNearestWarp(island: SkyBlockIsland, pos: Position) {
- val nearestWarp = findNearestWarp(island, pos) ?: return
-
+ val nearestWarp = findNearestWarp(island, pos)
+ if (nearestWarp == null) {
+ MC.sendChat(Text.literal("Could not find an unlocked warp in ${island.userFriendlyName}"))
+ return
+ }
if (island == SBData.skyblockLocation
&& sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp))
) {
diff --git a/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt b/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt
index 01a7083..79d6e6f 100644
--- a/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt
@@ -37,7 +37,8 @@ class FacingThePlayerContext(val worldContext: RenderInWorldContext) {
fun text(
vararg texts: Text,
- verticalAlign: RenderInWorldContext.VerticalAlign = RenderInWorldContext.VerticalAlign.CENTER
+ verticalAlign: RenderInWorldContext.VerticalAlign = RenderInWorldContext.VerticalAlign.CENTER,
+ background: Int = 0x70808080,
) {
assertTrueOr(texts.isNotEmpty()) { return@text }
for ((index, text) in texts.withIndex()) {
@@ -47,14 +48,14 @@ class FacingThePlayerContext(val worldContext: RenderInWorldContext) {
val vertexConsumer: VertexConsumer =
worldContext.vertexConsumers.getBuffer(RenderLayer.getTextBackgroundSeeThrough())
val matrix4f = worldContext.matrixStack.peek().positionMatrix
- vertexConsumer.vertex(matrix4f, -1.0f, -1.0f, 0.0f).color(0x70808080)
+ vertexConsumer.vertex(matrix4f, -1.0f, -1.0f, 0.0f).color(background)
.light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next()
- vertexConsumer.vertex(matrix4f, -1.0f, MC.font.fontHeight.toFloat(), 0.0f).color(0x70808080)
+ vertexConsumer.vertex(matrix4f, -1.0f, MC.font.fontHeight.toFloat(), 0.0f).color(background)
.light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next()
vertexConsumer.vertex(matrix4f, width.toFloat(), MC.font.fontHeight.toFloat(), 0.0f)
- .color(0x70808080)
+ .color(background)
.light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next()
- vertexConsumer.vertex(matrix4f, width.toFloat(), -1.0f, 0.0f).color(0x70808080)
+ vertexConsumer.vertex(matrix4f, width.toFloat(), -1.0f, 0.0f).color(background)
.light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next()
worldContext.matrixStack.translate(0F, 0F, 0.01F)
diff --git a/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt
index 3b6e262..0620425 100644
--- a/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt
@@ -83,11 +83,12 @@ class RenderInWorldContext private constructor(
}
}
- fun waypoint(position: BlockPos, label: Text) {
+ fun waypoint(position: BlockPos, vararg label: Text) {
text(
position.toCenterPos(),
- label,
- Text.literal("§e${FirmFormatters.formatDistance(MC.player?.pos?.distanceTo(position.toCenterPos()) ?: 42069.0)}")
+ *label,
+ Text.literal("§e${FirmFormatters.formatDistance(MC.player?.pos?.distanceTo(position.toCenterPos()) ?: 42069.0)}"),
+ background = 0xAA202020.toInt()
)
}
@@ -123,9 +124,9 @@ class RenderInWorldContext private constructor(
}
}
- fun text(position: Vec3d, vararg texts: Text, verticalAlign: VerticalAlign = VerticalAlign.CENTER) {
+ fun text(position: Vec3d, vararg texts: Text, verticalAlign: VerticalAlign = VerticalAlign.CENTER, background: Int = 0x70808080) {
withFacingThePlayer(position) {
- text(*texts, verticalAlign = verticalAlign)
+ text(*texts, verticalAlign = verticalAlign, background = background)
}
}