Skip to content

Commit 45ca49f

Browse files
committed
ref: coordinate hud
1 parent 4e391c0 commit 45ca49f

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

common/src/main/kotlin/com/lambda/module/hud/Coordinates.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ import com.lambda.context.SafeContext
2121
import com.lambda.module.HudModule
2222
import com.lambda.module.tag.ModuleTag
2323
import com.lambda.threading.runSafe
24+
import com.lambda.util.Formatting.asString
2425
import com.lambda.util.Formatting.string
26+
import com.lambda.util.extension.dimensionName
27+
import com.lambda.util.math.VecUtils.netherCoord
28+
import com.lambda.util.math.VecUtils.overworldCoord
29+
import net.minecraft.registry.RegistryKey
30+
import net.minecraft.world.World
2531

2632
object Coordinates : HudModule(
2733
name = "Coordinates",
2834
description = "Show your coordinates",
2935
defaultTags = setOf(ModuleTag.CLIENT),
3036
) {
37+
private val showDimension by setting("Show Dimension", true)
38+
private val decimals by setting("Decimals", 2, 0..4, 1)
39+
3140
private val SafeContext.text: String
32-
get() = "Position: ${player.pos.string}"
41+
get() = "XYZ ${if (showDimension) dimensionName else ""} ${positionForDimension(world.registryKey)}"
3342

3443
// TODO: Replace by LambdaAtlas height cache and actually build a proper text with highlighted parameters
3544

@@ -43,4 +52,10 @@ object Coordinates : HudModule(
4352
}
4453
}
4554
}
55+
56+
private fun SafeContext.positionForDimension(dimension: RegistryKey<World>) =
57+
when (dimension) {
58+
World.NETHER -> "[${player.netherCoord.asString(decimals)}, ${player.netherCoord.z.string}] ${player.overworldCoord.asString(decimals)}"
59+
else -> "${player.overworldCoord.asString(decimals)} [${player.netherCoord.x.string}, ${player.netherCoord.z.string}]"
60+
}
4661
}

common/src/main/kotlin/com/lambda/module/hud/TPS.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package com.lambda.module.hud
1919

2020
import com.lambda.module.HudModule
2121
import com.lambda.module.tag.ModuleTag
22+
import com.lambda.util.Formatting.string
2223
import com.lambda.util.NamedEnum
2324
import com.lambda.util.ServerTPS.averageMSPerTick
24-
import com.lambda.util.math.MathUtils.format
2525

2626
object TPS : HudModule(
2727
name = "TPS",
@@ -30,7 +30,7 @@ object TPS : HudModule(
3030
) {
3131
private val format by setting("Tick format", TickFormat.TPS)
3232

33-
private val text: String get() = "${format.displayName}: ${format.output().format(2)}${format.unit}"
33+
private val text: String get() = "${format.displayName}: ${format.output().string}${format.unit}"
3434

3535
// TODO: Replace by LambdaAtlas height cache and actually build a proper text with highlighted parameters
3636

common/src/main/kotlin/com/lambda/util/extension/World.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ import net.minecraft.world.World
3636
import java.awt.Color
3737
import kotlin.experimental.and
3838

39+
val SafeContext.isOverworld: Boolean get() = world.registryKey == World.OVERWORLD
40+
val SafeContext.isNether: Boolean get() = world.registryKey == World.NETHER
41+
val SafeContext.isEnd: Boolean get() = world.registryKey == World.END
42+
val SafeContext.dimensionName: String
43+
get() = when {
44+
isOverworld -> "Overworld"
45+
isNether -> "Nether"
46+
isEnd -> "End"
47+
else -> "Unknown"
48+
}
49+
3950
fun SafeContext.collisionShape(state: BlockState, pos: BlockPos) =
4051
state.getCollisionShape(world, pos).offset(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble())
4152

common/src/main/kotlin/com/lambda/util/math/MathUtils.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,5 @@ object MathUtils {
8282

8383
fun Int.nextPowerOf2() = 2f.pow(ceil(log2(toFloat()))).toInt()
8484

85-
fun Double.format(scale: Int) = "%.${scale}f".format(this)
86-
8785
inline val Int.sq: Int get() = this * this
8886
}

common/src/main/kotlin/com/lambda/util/math/VecUtils.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ object VecUtils {
4343
fun Vec3d.approximate(other: Vec3d, precision: Double = 2.0E-4): Boolean =
4444
(subtract(other) distSq Vec3d.ZERO) > precision.pow(2)
4545

46+
val Entity.netherCoord: Vec3d get() = pos.multiply(0.125, 1.0, 0.125)
47+
val Entity.overworldCoord: Vec3d get() = pos.multiply(8.0, 1.0, 8.0)
48+
4649
infix fun Vec3d.dist(other: Vec3d): Double = sqrt(this distSq other)
4750
infix fun Vec3d.dist(other: Vec3i): Double = sqrt(this distSq other)
4851
infix fun Vec3d.distSq(other: Vec3d): Double = this.squaredDistanceTo(other)

0 commit comments

Comments
 (0)