Skip to content

Commit dfa8de1

Browse files
committed
Show thread id in tooltip
1 parent 045841b commit dfa8de1

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

Common/src/main/kotlin/gay/object/hexdebug/items/DebuggerItem.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import net.minecraft.world.entity.LivingEntity
2828
import net.minecraft.world.entity.player.Player
2929
import net.minecraft.world.item.ItemStack
3030
import net.minecraft.world.item.Rarity
31+
import net.minecraft.world.item.TooltipFlag
3132
import net.minecraft.world.item.context.UseOnContext
3233
import net.minecraft.world.item.enchantment.EnchantmentHelper
3334
import net.minecraft.world.item.enchantment.Enchantments
@@ -183,6 +184,16 @@ class DebuggerItem(
183184
return super.hurtEnemy(stack, target, attacker)
184185
}
185186

187+
override fun appendHoverText(
188+
stack: ItemStack,
189+
level: Level?,
190+
tooltipComponents: MutableList<Component>,
191+
isAdvanced: TooltipFlag,
192+
) {
193+
tooltipComponents.add(displayThread(null, getThreadId(stack)))
194+
super.appendHoverText(stack, level, tooltipComponents, isAdvanced)
195+
}
196+
186197
// always allow shift, only allow ctrl if quenched
187198
override fun canShiftScroll(isCtrl: Boolean) = !isCtrl || isQuenched
188199

Common/src/main/kotlin/gay/object/hexdebug/items/EvaluatorItem.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import gay.`object`.hexdebug.debugger.DebuggerState
1313
import gay.`object`.hexdebug.items.base.*
1414
import gay.`object`.hexdebug.utils.asItemPredicate
1515
import net.minecraft.client.player.LocalPlayer
16+
import net.minecraft.network.chat.Component
1617
import net.minecraft.server.level.ServerPlayer
1718
import net.minecraft.stats.Stats
1819
import net.minecraft.world.InteractionHand
1920
import net.minecraft.world.InteractionResultHolder
2021
import net.minecraft.world.entity.player.Player
2122
import net.minecraft.world.item.ItemStack
23+
import net.minecraft.world.item.TooltipFlag
2224
import net.minecraft.world.level.Level
2325
import net.minecraft.world.phys.Vec3
2426

@@ -83,6 +85,16 @@ class EvaluatorItem(
8385
}
8486
)
8587

88+
override fun appendHoverText(
89+
stack: ItemStack,
90+
level: Level?,
91+
tooltipComponents: MutableList<Component>,
92+
isAdvanced: TooltipFlag,
93+
) {
94+
tooltipComponents.add(displayThread(null, getThreadId(stack)))
95+
super.appendHoverText(stack, level, tooltipComponents, isAdvanced)
96+
}
97+
8698
// only allow shift+ctrl scrolling, and only if it's quenched
8799
override fun canShiftScroll(isCtrl: Boolean) = isCtrl && isQuenched
88100

Common/src/main/kotlin/gay/object/hexdebug/items/base/ShiftScrollable.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package gay.`object`.hexdebug.items.base
22

3-
import at.petrak.hexcasting.api.utils.asTranslatedComponent
4-
import at.petrak.hexcasting.api.utils.getInt
5-
import at.petrak.hexcasting.api.utils.putInt
3+
import at.petrak.hexcasting.api.utils.*
64
import gay.`object`.hexdebug.config.HexDebugServerConfig
75
import gay.`object`.hexdebug.core.api.HexDebugCoreAPI
86
import net.minecraft.network.chat.Component
@@ -24,13 +22,17 @@ fun getThreadId(stack: ItemStack) = stack.getInt(THREAD_ID_TAG)
2422
fun rotateThreadId(caster: ServerPlayer, stack: ItemStack, increase: Boolean): Component {
2523
val threadId = (getThreadId(stack) + (if (increase) 1 else -1))
2624
.coerceIn(0 until HexDebugServerConfig.config.maxDebugThreads)
27-
2825
stack.putInt(THREAD_ID_TAG, threadId)
26+
return displayThread(caster, threadId)
27+
}
2928

30-
val envName = HexDebugCoreAPI.INSTANCE.getDebugEnv(caster, threadId)?.name
31-
return if (envName != null) {
32-
"hexdebug.tooltip.thread.active".asTranslatedComponent(threadId, envName)
29+
fun displayThread(caster: ServerPlayer?, threadId: Int): Component {
30+
val threadText = threadId.toString().asTextComponent.white
31+
val envName = caster?.let { HexDebugCoreAPI.INSTANCE.getDebugEnv(it, threadId) }?.name
32+
val component = if (envName != null) {
33+
"hexdebug.tooltip.thread.active".asTranslatedComponent(threadText, envName)
3334
} else {
34-
"hexdebug.tooltip.thread.inactive".asTranslatedComponent(threadId)
35+
"hexdebug.tooltip.thread.inactive".asTranslatedComponent(threadText)
3536
}
37+
return component.gray
3638
}

Common/src/main/resources/assets/hexdebug/lang/en_us.flatten.json5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@
258258
hexdebug: {
259259
tooltip: {
260260
thread: {
261-
inactive: "Thread %d",
262-
active: "Thread %d (%s)",
261+
inactive: "Thread %s",
262+
active: "Thread %s (%s)",
263263
},
264264
debugger: {
265265
step_mode: {

0 commit comments

Comments
 (0)