aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/misc/Hud.kt
blob: fb7c6cd99fa4632c7b691491debee4caa16b4c2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package moe.nea.firmament.features.misc

import org.joml.Vector2i
import net.minecraft.client.network.PlayerListEntry
import net.minecraft.text.Text
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HudRenderEvent
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.data.Config
import moe.nea.firmament.util.data.ManagedConfig
import moe.nea.firmament.util.tr

object Hud {
	val identifier: String
		get() = "hud"

	@Config
	object TConfig : ManagedConfig(identifier, Category.MISC) {
		var dayCount by toggle("day-count") { false }
		val dayCountHud by position("day-count-hud", 80, 10) { Vector2i() }
		var fpsCount by toggle("fps-count") { false }
		val fpsCountHud by position("fps-count-hud", 80, 10) { Vector2i() }
		var pingCount by toggle("ping-count") { false }
		val pingCountHud by position("ping-count-hud", 80, 10) { Vector2i() }
	}

	@Subscribe
	fun onRenderHud(it: HudRenderEvent) {
		if (TConfig.dayCount) {
			it.context.matrices.pushMatrix()
			TConfig.dayCountHud.applyTransformations(it.context.matrices)
			val day = (MC.world?.timeOfDay ?: 0L) / 24000
			it.context.drawText(
				MC.font,
				Text.literal(String.format(tr("firmament.config.hud.day-count-hud.display", "Day: %s").string, day)),
				36,
				MC.font.fontHeight,
				-1,
				true
			)
			it.context.matrices.popMatrix()
		}

		if (TConfig.fpsCount) {
			it.context.matrices.pushMatrix()
			TConfig.fpsCountHud.applyTransformations(it.context.matrices)
			it.context.drawText(
				MC.font, Text.literal(
					String.format(
						tr("firmament.config.hud.fps-count-hud.display", "FPS: %s").string, MC.instance.currentFps
					)
				), 36, MC.font.fontHeight, -1, true
			)
			it.context.matrices.popMatrix()
		}

		if (TConfig.pingCount) {
			it.context.matrices.pushMatrix()
			TConfig.pingCountHud.applyTransformations(it.context.matrices)
			val ping = MC.player?.let {
				val entry: PlayerListEntry? = MC.networkHandler?.getPlayerListEntry(it.uuid)
				entry?.latency ?: -1
			} ?: -1
			it.context.drawText(
				MC.font, Text.literal(
					String.format(
						tr("firmament.config.hud.ping-count-hud.display", "Ping: %s ms").string, ping
					)
				), 36, MC.font.fontHeight, -1, true
			)

			it.context.matrices.popMatrix()
		}
	}
}