Skip to content

Commit 108d766

Browse files
committed
Improve type safety and nesting depth
1 parent 0d0fb47 commit 108d766

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/main/kotlin/com/lambda/client/gui/hudgui/AbstractHudElement.kt

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,31 @@ abstract class AbstractHudElement(
6060
private val chatSnapY = 15f
6161

6262
init {
63-
safeListener<TickEvent.ClientTickEvent> {
64-
if (it.phase != TickEvent.Phase.END || !visible) return@safeListener
63+
safeListener<TickEvent.ClientTickEvent> { event ->
64+
if (event.phase != TickEvent.Phase.END || !visible) return@safeListener
6565
width = maxWidth
6666
height = maxHeight
67-
if (Hud.chatSnap) {
68-
if (mc.currentScreen is GuiChat && !chatSnapping) {
69-
val screenH = (mc.currentScreen as GuiChat).height
70-
if (posY >= screenH - height - 3 && posX <= 3 && yShift == 0.0f) {
71-
val prevPosYSnap = posY
72-
yShift = -chatSnapY
73-
snappedElements.clear()
74-
GuiManager.getHudElementOrNull(componentName)?.let { snappedElements.add(it) }
75-
chatSnapCheck(componentName, prevPosYSnap)
76-
chatSnapping = true
77-
}
78-
} else if (mc.currentScreen !is GuiChat && chatSnapping) {
79-
yShift = 0.0f
80-
for (element in snappedElements) {
81-
element.yShift = 0.0f
82-
}
67+
68+
if (!Hud.chatSnap) return@safeListener
69+
70+
val currentScreen = mc.currentScreen
71+
if (currentScreen is GuiChat && !chatSnapping) {
72+
val screenH = currentScreen.height
73+
if (posY >= screenH - height - 3 && posX <= 3 && yShift == 0.0f) {
74+
val prevPosYSnap = posY
75+
yShift = -chatSnapY
8376
snappedElements.clear()
84-
chatSnapping = false
77+
GuiManager.getHudElementOrNull(componentName)?.let { snappedElements.add(it) }
78+
chatSnapCheck(componentName, prevPosYSnap)
79+
chatSnapping = true
80+
}
81+
} else if (currentScreen !is GuiChat && chatSnapping) {
82+
yShift = 0.0f
83+
snappedElements.forEach {
84+
it.yShift = 0.0f
8585
}
86+
snappedElements.clear()
87+
chatSnapping = false
8688
}
8789
}
8890
}

0 commit comments

Comments
 (0)