Skip to content

Commit 20ddf05

Browse files
committed
Fixed coordinate module
1 parent 00654a0 commit 20ddf05

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ import com.lambda.threading.runSafe
2424
import com.lambda.util.Formatting.asString
2525
import com.lambda.util.Formatting.string
2626
import com.lambda.util.extension.dimensionName
27+
import com.lambda.util.extension.isNether
2728
import com.lambda.util.math.netherCoord
2829
import com.lambda.util.math.overworldCoord
29-
import net.minecraft.registry.RegistryKey
30-
import net.minecraft.world.World
3130

3231
object Coordinates : HudModule(
3332
name = "Coordinates",
@@ -38,7 +37,7 @@ object Coordinates : HudModule(
3837
private val decimals by setting("Decimals", 2, 0..4, 1)
3938

4039
private val SafeContext.text: String
41-
get() = "XYZ ${if (showDimension) dimensionName else ""} ${positionForDimension(world.registryKey)}"
40+
get() = "XYZ ${if (showDimension) dimensionName else ""} ${positionForDimension()}"
4241

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

@@ -53,9 +52,9 @@ object Coordinates : HudModule(
5352
}
5453
}
5554

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}]"
55+
private fun SafeContext.positionForDimension() =
56+
when {
57+
isNether -> "${player.pos.asString(decimals)} [${player.overworldCoord.x.string}; ${player.overworldCoord.z.string}]"
58+
else -> "${player.pos.asString(decimals)} [${player.netherCoord.x.string}; ${player.netherCoord.z.string}]"
6059
}
6160
}

common/src/main/kotlin/com/lambda/util/Formatting.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ import java.time.LocalDateTime
2222
import java.time.ZoneId
2323
import java.time.ZonedDateTime
2424
import java.time.format.DateTimeFormatter
25+
import java.util.*
2526

2627
object Formatting {
2728
val Vec3d.string: String
2829
get() = asString()
2930

3031
val Float.string: String
31-
get() = "%.2f".format(this)
32+
get() = "%.2f".format(Locale.US, this)
3233

3334
val Double.string: String
34-
get() = "%.2f".format(this)
35+
get() = "%.2f".format(Locale.US, this)
3536

3637
fun Vec3d.asString(decimals: Int = 2): String {
3738
val format = "%.${decimals}f"
38-
return "(${format.format(x)}, ${format.format(y)}, ${format.format(z)})"
39+
return "(${format.format(Locale.US, x)}, ${format.format(Locale.US, y)}, ${format.format(Locale.US, z)})"
3940
}
4041

4142
fun getTime(formatter: DateTimeFormatter = DateTimeFormatter.RFC_1123_DATE_TIME): String {

0 commit comments

Comments
 (0)