Skip to content

Commit 87f26b7

Browse files
BaitinqAvanatiker
andauthored
Nametags: Add TOTEM_POP_COUNT ContentType (#454)
* Nametags: Add TOTEM_POP_COUNT ContentType This patch allows for the popped totems to be able to be shown in the nametags. The totem pop counting functionality is embedded in the TotemPopCounter module, hence, it needs to be active in order for this to work. As to ensure this is the case, this patch adds some logic preventing this feature to be enabled when the TotemPopCounter module is inactive, and also re-enables the TotemPopCounter module if this feature is enabled and the user tries to disable the TotemPopCounter module. * Cleanup Co-authored-by: Constructor <[email protected]>
1 parent 9429698 commit 87f26b7

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

src/main/kotlin/com/lambda/client/module/modules/combat/TotemPopCounter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object TotemPopCounter : Module(
3535
CLIENT, EVERYONE
3636
}
3737

38-
private val popCountMap = WeakHashMap<EntityPlayer, Int>().synchronized()
38+
val popCountMap = WeakHashMap<EntityPlayer, Int>().synchronized()
3939
private var wasSent = false
4040

4141
init {

src/main/kotlin/com/lambda/client/module/modules/render/Nametags.kt

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lambda.client.module.modules.render
33
import com.lambda.client.commons.extension.ceilToInt
44
import com.lambda.client.commons.extension.floorToInt
55
import com.lambda.client.commons.utils.MathUtils
6+
import com.lambda.client.event.SafeClientEvent
67
import com.lambda.client.event.events.RenderOverlayEvent
78
import com.lambda.client.event.listener.listener
89
import com.lambda.client.module.Category
@@ -11,6 +12,7 @@ import com.lambda.client.module.modules.client.ClickGUI
1112
import com.lambda.client.module.modules.client.CustomFont
1213
import com.lambda.client.module.modules.client.GuiColors
1314
import com.lambda.client.module.modules.client.Hud
15+
import com.lambda.client.module.modules.combat.TotemPopCounter
1416
import com.lambda.client.module.modules.misc.LogoutLogger
1517
import com.lambda.client.util.EnchantmentUtils
1618
import com.lambda.client.util.EntityUtils
@@ -60,7 +62,6 @@ object Nametags : Module(
6062
private val invisible by setting("Invisible", true, { page == Page.ENTITY_TYPE })
6163
private val range by setting("Range", 64, 0..256, 4, { page == Page.ENTITY_TYPE })
6264

63-
/* Content */
6465
private val line1left = setting("Line 1 Left", ContentType.NONE, { page == Page.CONTENT })
6566
private val line1center = setting("Line 1 Center", ContentType.NONE, { page == Page.CONTENT })
6667
private val line1right = setting("Line 1 Right", ContentType.NONE, { page == Page.CONTENT })
@@ -95,7 +96,7 @@ object Nametags : Module(
9596
}
9697

9798
private enum class ContentType {
98-
NONE, NAME, TYPE, TOTAL_HP, HP, ABSORPTION, PING, DISTANCE, ENTITY_ID
99+
NONE, NAME, TYPE, TOTAL_HP, HP, ABSORPTION, PING, DISTANCE, ENTITY_ID, TOTEM_POP_COUNT
99100
}
100101

101102
private val pingColorGradient = ColorGradient(
@@ -114,7 +115,7 @@ object Nametags : Module(
114115

115116
private val line1Settings = arrayOf(line1left, line1center, line1right)
116117
private val line2Settings = arrayOf(line2left, line2center, line2right)
117-
val entityMap = TreeMap<Entity, TextComponent>(compareByDescending { mc.player.getPositionEyes(1f).distanceTo(it.getPositionEyes(1f)) })
118+
private val entityMap = TreeMap<Entity, TextComponent>(compareByDescending { mc.player.getPositionEyes(1f).distanceTo(it.getPositionEyes(1f)) })
118119
private val itemMap = TreeSet<ItemGroup>(compareByDescending { mc.player.getPositionEyes(1f).distanceTo(it.getCenter(1f)) })
119120

120121
private var updateTick = 0
@@ -403,7 +404,7 @@ object Nametags : Module(
403404
}
404405
}
405406

406-
private fun getContent(contentType: ContentType, entity: Entity) = when (contentType) {
407+
private fun SafeClientEvent.getContent(contentType: ContentType, entity: Entity) = when (contentType) {
407408
ContentType.NONE -> {
408409
null
409410
}
@@ -415,44 +416,56 @@ object Nametags : Module(
415416
TextComponent.TextElement(getEntityType(entity), GuiColors.text)
416417
}
417418
ContentType.TOTAL_HP -> {
418-
if (entity !is EntityLivingBase) {
419-
null
420-
} else {
419+
if (entity is EntityLivingBase) {
421420
val totalHp = MathUtils.round(entity.health + entity.absorptionAmount, 1).toString()
422421
TextComponent.TextElement(totalHp, getHpColor(entity))
422+
} else {
423+
null
423424
}
424425
}
425426
ContentType.HP -> {
426-
if (entity !is EntityLivingBase) {
427-
null
428-
} else {
427+
if (entity is EntityLivingBase) {
429428
val hp = MathUtils.round(entity.health, 1).toString()
430429
TextComponent.TextElement(hp, getHpColor(entity))
430+
} else {
431+
null
431432
}
432433
}
433434
ContentType.ABSORPTION -> {
434-
if (entity !is EntityLivingBase || entity.absorptionAmount == 0f) {
435-
null
436-
} else {
435+
if (entity is EntityLivingBase && entity.absorptionAmount != 0f) {
437436
val absorption = MathUtils.round(entity.absorptionAmount, 1).toString()
438437
TextComponent.TextElement(absorption, ColorHolder(234, 204, 32, GuiColors.text.a))
438+
} else {
439+
null
439440
}
440441
}
441442
ContentType.PING -> {
442-
if (entity !is EntityOtherPlayerMP) {
443-
null
443+
if (entity is EntityOtherPlayerMP) {
444+
connection.getPlayerInfo(entity.uniqueID)?.responseTime?.let {
445+
TextComponent.TextElement("${it}ms", pingColorGradient.get(it.toFloat()).apply { a = GuiColors.text.a })
446+
}
444447
} else {
445-
val ping = mc.connection?.getPlayerInfo(entity.uniqueID)?.responseTime ?: 0
446-
TextComponent.TextElement("${ping}ms", pingColorGradient.get(ping.toFloat()).apply { a = GuiColors.text.a })
448+
null
447449
}
448450
}
449451
ContentType.DISTANCE -> {
450-
val dist = MathUtils.round(mc.player.getDistance(entity), 1).toString()
452+
val dist = MathUtils.round(player.getDistance(entity), 1).toString()
451453
TextComponent.TextElement("${dist}m", GuiColors.text)
452454
}
453455
ContentType.ENTITY_ID -> {
454456
TextComponent.TextElement("ID: ${entity.entityId}", GuiColors.text)
455457
}
458+
ContentType.TOTEM_POP_COUNT -> {
459+
// Note: The totem pop counting functionality is embedded in the TotemPopCounter module,
460+
// hence, it needs to be active in order for this to work.
461+
if (entity is EntityOtherPlayerMP) {
462+
if (TotemPopCounter.isDisabled) TotemPopCounter.enable()
463+
val count = TotemPopCounter.popCountMap.getOrDefault(entity, 0)
464+
TextComponent.TextElement("PT: $count", GuiColors.text)
465+
} else {
466+
null
467+
}
468+
}
456469
}
457470

458471
private fun getEntityType(entity: Entity) = entity.javaClass.simpleName.replace("Entity", "")

0 commit comments

Comments
 (0)