Skip to content

Commit a988f1e

Browse files
committed
hotbar manager debug logs
1 parent 61ebb81 commit a988f1e

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.interaction.request
1919

20+
import com.lambda.event.Event
2021
import com.lambda.util.reflections.getInstances
2122
import net.minecraft.util.math.BlockPos
2223

@@ -28,6 +29,9 @@ object ManagerUtils {
2829
fun DebugLogger.newTick() =
2930
system("------------- New Tick -------------")
3031

32+
fun DebugLogger.newStage(tickStage: Event?) =
33+
system("Tick stage ${tickStage?.run { this::class.qualifiedName }}")
34+
3135
fun isPosBlocked(pos: BlockPos) =
3236
positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } }
3337
}

src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.lambda.interaction.material.StackSelection
4141
import com.lambda.interaction.material.StackSelection.Companion.select
4242
import com.lambda.interaction.request.Logger
4343
import com.lambda.interaction.request.ManagerUtils.isPosBlocked
44+
import com.lambda.interaction.request.ManagerUtils.newStage
4445
import com.lambda.interaction.request.ManagerUtils.newTick
4546
import com.lambda.interaction.request.PositionBlocking
4647
import com.lambda.interaction.request.RequestHandler
@@ -107,7 +108,7 @@ object BreakManager : RequestHandler<BreakRequest>(
107108
TickEvent.Player.Post,
108109
onOpen = {
109110
if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty())
110-
BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}")
111+
BreakManager.logger.newStage(BreakManager.tickStage)
111112
processRequest(activeRequest)
112113
simulateAbandoned()
113114
},

src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import com.lambda.event.events.TickEvent
2424
import com.lambda.event.events.UpdateManagerEvent
2525
import com.lambda.event.listener.SafeListener.Companion.listen
2626
import com.lambda.interaction.request.Logger
27+
import com.lambda.interaction.request.ManagerUtils.newStage
28+
import com.lambda.interaction.request.ManagerUtils.newTick
2729
import com.lambda.interaction.request.RequestHandler
2830
import com.lambda.interaction.request.hotbar.HotbarManager.checkResetSwap
2931
import com.lambda.module.hud.ManagerDebugLoggers.hotbarManagerLogger
@@ -35,6 +37,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
3537
TickEvent.Input.Pre,
3638
TickEvent.Input.Post,
3739
TickEvent.Player.Post,
40+
onOpen = { if (HotbarManager.activeRequest != null) HotbarManager.logger.newStage(HotbarManager.tickStage) },
3841
onClose = { checkResetSwap() }
3942
), Logger {
4043
val serverSlot get() = runSafe {
@@ -52,6 +55,11 @@ object HotbarManager : RequestHandler<HotbarRequest>(
5255
override fun load(): String {
5356
super.load()
5457

58+
listen<TickEvent.Pre>(priority = Int.MAX_VALUE) {
59+
if (activeRequest != null)
60+
logger.newTick()
61+
}
62+
5563
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
5664
swapsThisTick = 0
5765
if (swapDelay > 0) swapDelay--
@@ -66,6 +74,8 @@ object HotbarManager : RequestHandler<HotbarRequest>(
6674
}
6775

6876
override fun SafeContext.handleRequest(request: HotbarRequest) {
77+
logger.debug("Handling request ${request.requestID}")
78+
6979
maxSwapsThisTick = request.swapsPerTick
7080
swapDelay = swapDelay.coerceAtMost(request.swapDelay)
7181

@@ -76,6 +86,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
7686
} == true
7787

7888
if (sameButLonger) activeRequest?.let { current ->
89+
logger.debug("Request is the same as current, but longer or the same keep time")
7990
request.swapPauseAge = current.swapPauseAge
8091
} else run swap@{
8192
if (request.slot != activeRequest?.slot) {
@@ -97,6 +108,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
97108
}
98109

99110
activeRequest = request
111+
logger.success("Set active request to ${request.requestID}")
100112
interaction.syncSelectedSlot()
101113
return
102114
}
@@ -105,6 +117,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
105117
activeRequest?.let { active ->
106118
val canStopSwap = swapsThisTick < maxSwapsThisTick
107119
if (active.keepTicks <= 0 && tickStage in active.sequenceStageMask && canStopSwap) {
120+
logger.debug("Clearing request and syncing slot")
108121
activeRequest = null
109122
interaction.syncSelectedSlot()
110123
}

src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.lambda.event.listener.SafeListener.Companion.listen
2727
import com.lambda.interaction.construction.context.PlaceContext
2828
import com.lambda.interaction.request.Logger
2929
import com.lambda.interaction.request.ManagerUtils.isPosBlocked
30+
import com.lambda.interaction.request.ManagerUtils.newStage
3031
import com.lambda.interaction.request.ManagerUtils.newTick
3132
import com.lambda.interaction.request.PositionBlocking
3233
import com.lambda.interaction.request.RequestHandler
@@ -74,7 +75,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
7475
onOpen = {
7576
activeRequest?.let { processRequest(it) }
7677
if (potentialPlacements.isNotEmpty())
77-
PlaceManager.logger.system("Tick stage ${PlaceManager.tickStage?.run { this::class.qualifiedName }}")
78+
PlaceManager.logger.newStage(PlaceManager.tickStage)
7879
}
7980
), PositionBlocking, Logger {
8081
private var activeRequest: PlaceRequest? = null

0 commit comments

Comments
 (0)