@@ -31,6 +31,7 @@ import com.lambda.interaction.request.RequestHandler
3131import com.lambda.interaction.request.hotbar.HotbarManager.checkResetSwap
3232import com.lambda.module.hud.ManagerDebugLoggers.hotbarManagerLogger
3333import com.lambda.threading.runSafe
34+ import net.minecraft.item.ItemStack
3435
3536object HotbarManager : RequestHandler<HotbarRequest>(
3637 1 ,
@@ -44,6 +45,9 @@ object HotbarManager : RequestHandler<HotbarRequest>(
4445 val serverSlot get() = runSafe {
4546 interaction.lastSelectedSlot
4647 } ? : 0
48+ // ToDo: something to manage stacks so the hotbar manager is strictly index based
49+ private var previousStack: ItemStack ? = null
50+ private var swappedTicks = 0
4751
4852 private var swapsThisTick = 0
4953 private var maxSwapsThisTick = 0
@@ -64,9 +68,14 @@ object HotbarManager : RequestHandler<HotbarRequest>(
6468 listen<TickEvent .Post >(priority = Int .MIN_VALUE ) {
6569 swapsThisTick = 0
6670 if (swapDelay > 0 ) swapDelay--
67- val activeInfo = activeRequest ? : return @listen
6871
69- activeInfo.swapPauseAge++
72+ val currentStack = player.mainHandStack
73+ if (previousStack != currentStack) swappedTicks = 1
74+ else swappedTicks++
75+ previousStack = currentStack
76+
77+ val activeInfo = activeRequest ? : return @listen
78+ activeInfo.swapPauseAge = swappedTicks
7079 activeInfo.activeRequestAge++
7180 activeInfo.keepTicks--
7281 }
@@ -77,40 +86,34 @@ object HotbarManager : RequestHandler<HotbarRequest>(
7786 override fun AutomatedSafeContext.handleRequest (request : HotbarRequest ) {
7887 logger.debug(" Handling request:" , request)
7988
80- maxSwapsThisTick = hotbarConfig.swapsPerTick
81- swapDelay = swapDelay.coerceAtMost(hotbarConfig.swapDelay)
82-
8389 if (tickStage !in hotbarConfig.sequenceStageMask) return
8490
85- val sameButLonger = activeRequest?.let { active ->
86- request.slot == active.slot && request.keepTicks >= active.keepTicks
87- } == true
91+ activeRequest?.let { active ->
92+ if (request.slot == serverSlot && request.keepTicks >= active.keepTicks) {
93+ logger.debug(" Request is the same as current, but longer or the same keep time" , request)
94+ setActiveRequest(request)
95+ return
96+ }
8897
89- if (sameButLonger) activeRequest?.let { active ->
90- request.swapPauseAge = active.swapPauseAge
91- logger.debug(" Request is the same as current, but longer or the same keep time" , request)
92- } else run swap@{
93- if (request.slot != activeRequest?.slot) {
94- if (swapsThisTick + 1 > maxSwapsThisTick || swapDelay > 0 ) return
98+ if (active.activeRequestAge <= 0 && active.keepTicks > 0 ) return
99+ } ? : run { maxSwapsThisTick = hotbarConfig.swapsPerTick }
95100
96- activeRequest?.let { active ->
97- if (active.swappedThisTick && active.keeping) return
98- }
101+ if (request.slot != serverSlot)
102+ if (swapsThisTick + 1 > maxSwapsThisTick || swapDelay > 0 ) return
99103
100- swapsThisTick++
101- swapDelay = hotbarConfig.swapDelay
102- return @swap
103- }
104-
105- activeRequest?.let { active ->
106- request.swapPauseAge = active.swapPauseAge
107- if (active.swappedThisTick && active.keeping) return
108- }
109- }
104+ setActiveRequest(request)
105+ }
110106
107+ private fun AutomatedSafeContext.setActiveRequest (request : HotbarRequest ) {
108+ maxSwapsThisTick = hotbarConfig.swapsPerTick
109+ if (request.slot != serverSlot) {
110+ swapsThisTick++
111+ swappedTicks = 0
112+ swapDelay = hotbarConfig.swapDelay
113+ } else request.swapPauseAge = swappedTicks
111114 activeRequest = request
112- logger.success(" Set active request" , request)
113115 interaction.syncSelectedSlot()
116+ logger.success(" Set active request" , request)
114117 }
115118
116119 private fun SafeContext.checkResetSwap () {
0 commit comments