Skip to content

Commit e7c7990

Browse files
committed
rotations for instant breakable blocks
1 parent 67c6f26 commit e7c7990

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

common/src/main/kotlin/com/lambda/interaction/request/RequestConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ package com.lambda.interaction.request
2020
abstract class RequestConfig <R : Request>(
2121
val priority: Priority
2222
) {
23-
protected abstract fun requestInternal(request: R)
23+
protected abstract fun requestInternal(request: R, queueIfClosed: Boolean = true)
2424

25-
fun request(request: R): R =
26-
request.apply(::requestInternal)
25+
fun request(request: R, queueIfClosed: Boolean = true): R =
26+
request.apply { requestInternal(this, queueIfClosed) }
2727
}

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ abstract class BreakConfig(
4747
abstract val minFortuneLevel: Int
4848
abstract val ignoredBlocks: Set<Block>
4949

50-
override fun requestInternal(request: BreakRequest) {
51-
BreakManager.request(request)
50+
override fun requestInternal(request: BreakRequest, queueIfClosed: Boolean) {
51+
BreakManager.request(request, queueIfClosed)
5252
}
5353

5454
enum class BreakMode {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,16 @@ object BreakManager : RequestHandler<BreakRequest>(
191191
.filterNotNull()
192192
.filter { !it.isRedundant }
193193
.also { infos ->
194-
infos.firstOrNull { it.breakConfig.rotateForBreak }?.let { info ->
195-
info.request.rotation.request(info.context.rotation)
194+
rotationRequest = infos.firstOrNull { it.breakConfig.rotateForBreak }?.let { info ->
195+
val rotation = info.context.rotation
196+
if (instantBreaks.isEmpty()) info.request.rotation.request(rotation, false) else rotation
196197
}
197198
}
198199
.reversed()
199200
.forEach { info ->
200201
if (info.updatedProgressThisTick) return@forEach
201202
if (!info.context.requestDependencies(request)) return@breakInfos
202-
if (!rotated || tickStage !in info.breakConfig.breakStageMask) return@breakInfos
203+
if ((!rotated && info.isPrimary) || tickStage !in info.breakConfig.breakStageMask) return@breakInfos
203204
updateBreakProgress(info)
204205
}
205206
}
@@ -283,7 +284,8 @@ object BreakManager : RequestHandler<BreakRequest>(
283284
val ctx = iterator.next()
284285

285286
if (!ctx.requestDependencies(request)) return false
286-
if (tickStage !in request.build.breaking.breakStageMask) return false
287+
rotationRequest = if (request.build.breaking.rotateForBreak) request.rotation.request(ctx.rotation, false) else null
288+
if (!rotated || tickStage !in request.build.breaking.breakStageMask) return false
287289

288290
val breakInfo = initNewBreak(ctx, request) ?: return false
289291
request.onAccept?.invoke(ctx.expectedPos)

common/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ abstract class HotbarConfig(
6464
*
6565
* @param request The hotbar request to register.
6666
*/
67-
override fun requestInternal(request: HotbarRequest) {
68-
HotbarManager.request(request)
67+
override fun requestInternal(request: HotbarRequest, queueIfClosed: Boolean) {
68+
HotbarManager.request(request, queueIfClosed)
6969
}
7070
}

common/src/main/kotlin/com/lambda/interaction/request/placing/PlaceConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ abstract class PlaceConfig(
4040
abstract val swingType: BuildConfig.SwingType
4141
abstract val sounds: Boolean
4242

43-
override fun requestInternal(request: PlaceRequest) {
44-
PlaceManager.request(request)
43+
override fun requestInternal(request: PlaceRequest, queueIfClosed: Boolean) {
44+
PlaceManager.request(request, queueIfClosed)
4545
}
4646

4747
enum class AirPlaceMode {

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ abstract class RotationConfig(priority: Priority) : RequestConfig<RotationReques
5757

5858
val rotate: Boolean get() = rotationMode != RotationMode.None
5959

60-
override fun requestInternal(request: RotationRequest) {
61-
RotationManager.request(request)
60+
override fun requestInternal(request: RotationRequest, queueIfClosed: Boolean) {
61+
RotationManager.request(request, queueIfClosed)
6262
}
6363

6464
open class Instant(mode: RotationMode, priority: Priority = 0) : RotationConfig(priority) {

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ import kotlin.math.sign
5050
import kotlin.math.sin
5151

5252
object RotationManager : RequestHandler<RotationRequest>(
53-
TickStage.TickStart
53+
TickStage.TickStart,
54+
TickStage.PostHotbar,
55+
TickStage.PostInteract,
5456
), Loadable {
5557
var activeRotation = Rotation.ZERO; private set
5658
var serverRotation = Rotation.ZERO; private set

0 commit comments

Comments
 (0)