Skip to content

Commit 5b0faf5

Browse files
committed
cleanup and added a rotation prediction for the next place context to prevent tick delay between placing blocks
1 parent 1fa8c74 commit 5b0faf5

File tree

5 files changed

+48
-51
lines changed

5 files changed

+48
-51
lines changed

common/src/main/kotlin/com/lambda/config/groups/PlaceSettings.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class PlaceSettings(
2929
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() }
3030
override val airPlace by c.setting("Air Place", AirPlaceMode.None, "Allows for placing blocks without adjacent faces") { vis() }
3131
override val axisRotateSetting by c.setting("Axis Rotate", true, "Overrides the Rotate For Place setting and rotates the player on each axis to air place rotational blocks") { vis() && airPlace.isEnabled() }
32-
override val axisRotate
33-
get() = airPlace.isEnabled() && axisRotateSetting
3432
override val placeConfirmationMode by c.setting("Place Confirmation", PlaceConfirmationMode.PlaceThenAwait, "Wait for block placement confirmation") { vis() }
3533
override val maxPendingPlacements by c.setting("Max Pending Placements", 5, 0..30, 1, "The maximum amount of pending placements") { vis() }
3634
override val placementsPerTick by c.setting("Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick") { vis() }

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
4141
import com.lambda.interaction.request.breaking.BreakConfig.BreakMode
4242
import com.lambda.interaction.request.hotbar.HotbarManager
4343
import com.lambda.interaction.request.hotbar.HotbarRequest
44-
import com.lambda.interaction.request.rotation.RotationRequest
4544
import com.lambda.module.modules.client.TaskFlowModule
4645
import com.lambda.util.BlockUtils.blockState
4746
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
@@ -88,10 +87,6 @@ object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
8887
override val blockedPositions
8988
get() = breakingInfos.mapNotNull { it?.context?.expectedPos } + pendingBreaks.map { it.context.expectedPos }
9089

91-
private var rotation: RotationRequest? = null
92-
private val validRotation
93-
get() = rotation?.done ?: true
94-
9590
private var blockBreakingCooldown = 0
9691

9792
fun Any.onBreak(
@@ -160,11 +155,19 @@ object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
160155
}
161156
}
162157

163-
requestRotate()
164-
if (!validRotation) {
165-
postEvent()
166-
return@listen
167-
}
158+
breakingInfos
159+
.firstOrNull { it?.breakConfig?.rotateForBreak == true }
160+
?.let { info ->
161+
// If the simulation cant find a valid rotation to break the block, the existing break context stays and the keep ticks deplete until
162+
if (info.context.rotation.keepTicks <= 0) null
163+
else info.rotationConfig.request(info.context.rotation)
164+
}
165+
?.let { rot ->
166+
if (!rot.done) {
167+
postEvent()
168+
return@listen
169+
}
170+
}
168171

169172
// Reversed so that the breaking order feels natural to the user as the primary break has to
170173
// be started after the secondary
@@ -262,16 +265,6 @@ object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
262265
false
263266
}
264267

265-
private fun requestRotate() {
266-
rotation = breakingInfos
267-
.firstOrNull { it?.breakConfig?.rotateForBreak == true }
268-
?.let { info ->
269-
// If the simulation cant find a valid rotation to break the block, the existing break context stays and the keep ticks deplete until
270-
if (info.context.rotation.keepTicks <= 0) null
271-
else info.rotationConfig.request(info.context.rotation)
272-
}
273-
}
274-
275268
private fun handleRequestContext(
276269
requestCtx: BreakContext,
277270
request: BreakRequest

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ abstract class PlaceConfig(
2525
priority: Priority
2626
) : RequestConfig<PlaceRequest>(priority) {
2727
abstract val rotateForPlace: Boolean
28+
val rotate
29+
get() = rotateForPlace || axisRotate
2830
abstract val airPlace: AirPlaceMode
2931
protected abstract val axisRotateSetting: Boolean
30-
abstract val axisRotate: Boolean
32+
val axisRotate
33+
get() = airPlace.isEnabled() && axisRotateSetting
3134
abstract val placeConfirmationMode: PlaceConfirmationMode
3235
abstract val maxPendingPlacements: Int
3336
abstract val placementsPerTick: Int

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

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
111111
pendingPlacements.setDecayTime(request.buildConfig.interactionTimeout * 50L)
112112

113113
val placeConfig = request.buildConfig.placeSettings
114-
115-
val maxPlacementsThisTick = (placeConfig.maxPendingPlacements - pendingPlacements.size).coerceAtLeast(0)
116-
val takeCount = (placeConfig.placementsPerTick.coerceAtMost(maxPlacementsThisTick))
117114
val isSneaking = player.isSneaking
118115
val currentHotbarIndex = HotbarManager.serverSlot
119116
val placeContexts = request.placeContexts
@@ -122,33 +119,42 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
122119
compareByDescending<PlaceContext> { it.hotbarIndex == currentHotbarIndex }
123120
.thenByDescending { it.sneak == isSneaking }
124121
)
125-
.take(takeCount)
126122

127-
placeContexts.forEach { ctx ->
128-
val notSneaking = !player.isSneaking
129-
val hotbarRequest = request.hotbarConfig.request(HotbarRequest(ctx.hotbarIndex))
130-
if (ctx.sneak && notSneaking) {
131-
shouldCrouch = true
132-
postEvent()
133-
return@listen
134-
}
135-
if ((placeConfig.rotateForPlace || placeConfig.axisRotate)) {
136-
rotation = request.rotationConfig.request(ctx.rotation)
137-
if (!ctx.rotation.target.verify()) {
123+
val maxPlacementsThisTick = (placeConfig.maxPendingPlacements - pendingPlacements.size).coerceAtLeast(0)
124+
val takeCount = (placeConfig.placementsPerTick.coerceAtMost(maxPlacementsThisTick))
125+
val nextRotationPrediction = placeContexts.getOrNull(takeCount)?.rotation
126+
127+
placeContexts
128+
.take(takeCount)
129+
.forEach { ctx ->
130+
val notSneaking = !player.isSneaking
131+
val hotbarRequest = request.hotbarConfig.request(HotbarRequest(ctx.hotbarIndex))
132+
if (placeConfig.rotate) {
133+
val rot = request.rotationConfig.request(ctx.rotation)
134+
if (!rot.done) {
135+
postEvent()
136+
return@listen
137+
}
138+
}
139+
if (ctx.sneak && notSneaking) {
140+
shouldCrouch = true
141+
postEvent()
142+
return@listen
143+
}
144+
if (!hotbarRequest.done) {
138145
postEvent()
139146
return@listen
140147
}
141-
}
142-
if (!hotbarRequest.done) {
143-
postEvent()
144-
return@listen
145-
}
146148

147-
val actionResult = placeBlock(ctx, request, Hand.MAIN_HAND)
148-
if (!actionResult.isAccepted) {
149-
warn("Placement interaction failed with $actionResult")
149+
val actionResult = placeBlock(ctx, request, Hand.MAIN_HAND)
150+
if (!actionResult.isAccepted) {
151+
warn("Placement interaction failed with $actionResult")
152+
}
153+
activeThisTick = true
150154
}
151-
activeThisTick = true
155+
156+
nextRotationPrediction?.let { rot ->
157+
request.rotationConfig.request(rot)
152158
}
153159
}
154160

common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,10 @@ class BuildTask @Ta5kBuilder constructor(
172172
return@listen
173173
}
174174
is PlaceResult.Place -> {
175-
val takeCount = build.placeSettings
176-
.placementsPerTick
177-
.coerceAtMost(emptyPendingInteractionSlots)
178175
val placeResults = resultsNotBlocked
179176
.filterIsInstance<PlaceResult.Place>()
180177
.distinctBy { it.blockPos }
181-
.take(takeCount)
178+
.take(emptyPendingInteractionSlots)
182179

183180
build.placeSettings.request(
184181
PlaceRequest(

0 commit comments

Comments
 (0)