Skip to content

Commit 9279895

Browse files
committed
instant break limit checks
1 parent b8d56dd commit 9279895

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import com.lambda.interaction.request.breaking.BreakManager.breaks
5656
import com.lambda.interaction.request.breaking.BreakManager.canAccept
5757
import com.lambda.interaction.request.breaking.BreakManager.checkForCancels
5858
import com.lambda.interaction.request.breaking.BreakManager.initNewBreak
59-
import com.lambda.interaction.request.breaking.BreakManager.maxBreaksThisTick
59+
import com.lambda.interaction.request.breaking.BreakManager.maxInstantBreaksThisTick
6060
import com.lambda.interaction.request.breaking.BreakManager.processNewBreak
6161
import com.lambda.interaction.request.breaking.BreakManager.processRequest
6262
import com.lambda.interaction.request.breaking.BreakManager.simulateAbandoned
@@ -156,8 +156,8 @@ object BreakManager : RequestHandler<BreakRequest>(
156156
var heldTicks = 0
157157
var swappedThisTick = false
158158
private var breakCooldown = 0
159-
var breaksThisTick = 0
160-
private var maxBreaksThisTick = 0
159+
var instantBreaksThisTick = 0
160+
private var maxInstantBreaksThisTick = 0
161161

162162
private var breaks = mutableListOf<BreakContext>()
163163

@@ -188,7 +188,7 @@ object BreakManager : RequestHandler<BreakRequest>(
188188
}
189189
activeRequest = null
190190
breaks = mutableListOf()
191-
breaksThisTick = 0
191+
instantBreaksThisTick = 0
192192
}
193193

194194
listen<WorldEvent.BlockUpdate.Server>(priority = Int.MIN_VALUE) { event ->
@@ -355,15 +355,15 @@ object BreakManager : RequestHandler<BreakRequest>(
355355
if (activeRequest != null) logger.debug("Clearing active request", activeRequest)
356356
activeRequest = null
357357
}
358-
if (breaksThisTick > 0 || activeInfos.isNotEmpty()) {
358+
if (instantBreaksThisTick > 0 || activeInfos.isNotEmpty()) {
359359
activeThisTick = true
360360
}
361361
}
362362

363363
/**
364364
* Filters the requests [BreakContext]s, and iterates over the [breakInfos] collection looking for matches
365365
* in positions. If a match is found, the [BreakInfo] is updated with the new context. Otherwise, the break is cancelled.
366-
* The [instantBreaks] and [breaks] collections are then populated with the new appropriate contexts, and the [maxBreaksThisTick]
366+
* The [instantBreaks] and [breaks] collections are then populated with the new appropriate contexts, and the [maxInstantBreaksThisTick]
367367
* value is set.
368368
*
369369
* @see canAccept
@@ -406,7 +406,7 @@ object BreakManager : RequestHandler<BreakRequest>(
406406

407407
val breakConfig = request.config
408408
val pendingLimit = (breakConfig.maxPendingBreaks - pendingBreakCount).coerceAtLeast(0)
409-
maxBreaksThisTick = breakConfig.breaksPerTick.coerceAtMost(pendingLimit)
409+
maxInstantBreaksThisTick = breakConfig.breaksPerTick.coerceAtMost(pendingLimit)
410410
}
411411

412412
/**
@@ -415,6 +415,8 @@ object BreakManager : RequestHandler<BreakRequest>(
415415
private fun SafeContext.canAccept(newCtx: BreakContext): Boolean {
416416
if (activeInfos.none { it.context.blockPos == newCtx.blockPos } && isPosBlocked(newCtx.blockPos)) return false
417417

418+
if (newCtx.instantBreak && instantBreaksThisTick > maxInstantBreaksThisTick) return false
419+
418420
if (!currentStackSelection.filterStack(player.inventory.getStack(newCtx.hotbarIndex)))
419421
return false
420422

@@ -595,7 +597,7 @@ object BreakManager : RequestHandler<BreakRequest>(
595597
info.startPending()
596598
}
597599
}
598-
breaksThisTick++
600+
instantBreaksThisTick++
599601
info.nullify()
600602
}
601603

@@ -822,6 +824,7 @@ object BreakManager : RequestHandler<BreakRequest>(
822824
logger.success("Instant breaking", info)
823825
onBlockBreak(info)
824826
if (!info.vanillaInstantBreakable) breakCooldown = info.breakConfig.breakDelay
827+
instantBreaksThisTick++
825828
} else {
826829
logger.debug("Starting break", info)
827830
info.apply {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object RebreakHandler {
9797
if (reBreak.breakConfig.swing.isEnabled()) {
9898
swingHand(reBreak.breakConfig.swingType, Hand.MAIN_HAND)
9999
}
100-
BreakManager.breaksThisTick++
100+
BreakManager.instantBreaksThisTick++
101101
RebreakResult.Rebroke
102102
} else {
103103
RebreakResult.StillBreaking(reBreak)

0 commit comments

Comments
 (0)