Skip to content

Commit 0ca4d9e

Browse files
committed
rotation manager and place manager docs
1 parent dccb0a8 commit 0ca4d9e

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import net.minecraft.util.math.ChunkSectionPos
4343

4444
/**
4545
* Designed to handle blocks that are deemed broken, yet are awaiting
46-
* confirmation from the server, and/or an item drop.
46+
* confirmation from the server and/or an item drop.
4747
*
4848
* @see BreakManager
4949
*/

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ import net.minecraft.util.math.BlockPos
6969
import net.minecraft.world.GameMode
7070
import kotlin.math.min
7171

72+
/**
73+
* Manager designed to place blocks.
74+
*/
7275
object PlaceManager : RequestHandler<PlaceRequest>(
7376
0,
7477
TickEvent.Pre,
@@ -135,11 +138,10 @@ object PlaceManager : RequestHandler<PlaceRequest>(
135138
}
136139

137140
/**
138-
* If the request is fresh, local variables are populated through the [processRequest] method.
139-
* It then attempts to perform as many placements within this tick as possible from the [potentialPlacements] collection.
140-
*
141-
* If all the [maxPlacementsThisTick] limit is reached and the user has rotations enabled, it will start rotating to
142-
* the next predicted placement in the list for optimal speed.
141+
* Returns immediately if [BreakManager] or [InteractionManager] have been active this tick.
142+
* Otherwise, for fresh requests, [populateFrom] is called to fill the [potentialPlacements] collection.
143+
* It then attempts to perform as many placements as possible from the [potentialPlacements] collection within
144+
* the [maxPlacementsThisTick] limit.
143145
*
144146
* @see populateFrom
145147
* @see placeBlock
@@ -182,7 +184,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
182184

183185
/**
184186
* Filters the [request]'s [PlaceContext]s, placing them into the [potentialPlacements] collection, and
185-
* setting the maxPlacementsThisTick value.
187+
* setting other configurations.
186188
*
187189
* @see isPosBlocked
188190
*/
@@ -205,9 +207,8 @@ object PlaceManager : RequestHandler<PlaceRequest>(
205207
}
206208

207209
/**
208-
* A modified version of the minecraft interactBlock method, renamed to better suit its usage.
209-
*
210-
* @see net.minecraft.client.network.ClientPlayerInteractionManager.interactBlock
210+
* A modified version of the minecraft [net.minecraft.client.network.ClientPlayerInteractionManager.interactBlock] method,
211+
* renamed to better suit its usage.
211212
*/
212213
private fun AutomatedSafeContext.placeBlock(placeContext: PlaceContext, request: PlaceRequest, hand: Hand): ActionResult {
213214
interaction.syncSelectedSlot()
@@ -224,9 +225,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
224225
}
225226

226227
/**
227-
* A modified version of the minecraft interactBlockInternal method.
228-
*
229-
* @see net.minecraft.client.network.ClientPlayerInteractionManager.interactBlockInternal
228+
* A modified version of the minecraft [net.minecraft.client.network.ClientPlayerInteractionManager.interactBlockInternal] method.
230229
*/
231230
private fun AutomatedSafeContext.interactBlockInternal(
232231
placeContext: PlaceContext,
@@ -267,9 +266,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
267266
}
268267

269268
/**
270-
* A modified version of the minecraft useOnBlock method.
271-
*
272-
* @see net.minecraft.item.Item.useOnBlock
269+
* A modified version of the minecraft [net.minecraft.item.Item.useOnBlock] method.
273270
*/
274271
private fun AutomatedSafeContext.useOnBlock(
275272
placeContext: PlaceContext,
@@ -297,9 +294,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
297294
}
298295

299296
/**
300-
* A modified version of the minecraft place method.
301-
*
302-
* @see net.minecraft.item.BlockItem.place
297+
* A modified version of the minecraft [net.minecraft.item.BlockItem.place] method.
303298
*/
304299
private fun AutomatedSafeContext.place(
305300
placeContext: PlaceContext,
@@ -396,7 +391,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
396391
}
397392

398393
/**
399-
* Plays the block placement sound at a given position.
394+
* Plays the block placement sound at a given [pos].
400395
*/
401396
fun SafeContext.placeSound(state: BlockState, pos: BlockPos) {
402397
val blockSoundGroup = state.soundGroup

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import com.lambda.util.Communication.info
2929
import com.lambda.util.Communication.warn
3030
import com.lambda.util.collections.LimitedDecayQueue
3131

32+
/**
33+
* Designed to handle placements pending a response from the server.
34+
*/
3235
object PlacedBlockHandler : PostActionHandler<PlaceInfo>() {
3336
override val pendingActions = LimitedDecayQueue<PlaceInfo>(
3437
AutomationConfig.buildConfig.maxPendingInteractions,

src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import com.lambda.interaction.BaritoneManager
3333
import com.lambda.interaction.request.Logger
3434
import com.lambda.interaction.request.RequestHandler
3535
import com.lambda.interaction.request.rotating.Rotation.Companion.slerp
36+
import com.lambda.interaction.request.rotating.RotationManager.activeRequest
37+
import com.lambda.interaction.request.rotating.RotationManager.activeRotation
38+
import com.lambda.interaction.request.rotating.RotationManager.serverRotation
39+
import com.lambda.interaction.request.rotating.RotationManager.updateActiveRotation
3640
import com.lambda.interaction.request.rotating.visibilty.lookAt
3741
import com.lambda.module.hud.ManagerDebugLoggers.rotationManagerLogger
3842
import com.lambda.threading.runGameScheduled
@@ -53,6 +57,9 @@ import kotlin.math.atan2
5357
import kotlin.math.cos
5458
import kotlin.math.sin
5559

60+
/**
61+
* Manager designed to rotate the player and adjust movement input to match the camera's direction.
62+
*/
5663
object RotationManager : RequestHandler<RotationRequest>(
5764
1,
5865
TickEvent.Pre,
@@ -62,8 +69,7 @@ object RotationManager : RequestHandler<RotationRequest>(
6269
), Logger {
6370
var activeRotation = Rotation.ZERO
6471
var serverRotation = Rotation.ZERO
65-
@JvmStatic
66-
var prevServerRotation = Rotation.ZERO
72+
@JvmStatic var prevServerRotation = Rotation.ZERO
6773
var baritoneRequest: RotationRequest? = null
6874

6975
var activeRequest: RotationRequest? = null
@@ -138,6 +144,12 @@ object RotationManager : RequestHandler<RotationRequest>(
138144
return "Loaded Rotation Manager"
139145
}
140146

147+
/**
148+
* If the [activeRequest] is from an older tick or null, and the [request]'s target rotation is not null,
149+
* the request is accepted and set as the [activeRequest]. The [activeRotation] is then updated.
150+
*
151+
* @see updateActiveRotation
152+
*/
141153
override fun AutomatedSafeContext.handleRequest(request: RotationRequest) {
142154
activeRequest?.let { if (it.age <= 0) return }
143155
if (request.target.targetRotation.value != null) {
@@ -148,6 +160,11 @@ object RotationManager : RequestHandler<RotationRequest>(
148160
}
149161
}
150162

163+
/**
164+
* If the rotation has not been changed this tick, the [activeRequest]'s target rotation is updated, and
165+
* likewise the [activeRotation]. The [activeRequest] is then updated, ticking the [RotationRequest.keepTicks]
166+
* and [RotationRequest.decayTicks].
167+
*/
151168
@JvmStatic
152169
fun processRotations() = runSafe {
153170
if (activeRequest != null) activeThisTick = true
@@ -171,6 +188,11 @@ object RotationManager : RequestHandler<RotationRequest>(
171188
}
172189
}
173190

191+
/**
192+
* Calculates and sets the optimal movement input for moving in the direction the player is facing. This
193+
* is not the direction the rotation manager is rotated towards, but the underlying player rotation, typically
194+
* also the camera's rotation.
195+
*/
174196
@JvmStatic
175197
fun redirectStrafeInputs(input: Input) = runSafe {
176198
if (activeRequest == baritoneRequest) return@runSafe
@@ -263,11 +285,15 @@ object RotationManager : RequestHandler<RotationRequest>(
263285
}
264286
}
265287

288+
/**
289+
* Updates the [activeRotation]. If [activeRequest] is null, the player's rotation is used.
290+
* Otherwise, the [serverRotation] is interpolated towards the [RotationRequest.target] rotation.
291+
*/
266292
private fun SafeContext.updateActiveRotation() {
267293
activeRotation = activeRequest?.let { request ->
268294
val rotationTo = if (request.keepTicks >= 0)
269295
request.target.targetRotation.value
270-
?: activeRotation // same context gets used again && the rotation is null this tick
296+
?: activeRotation // the same context gets used again && the rotation is null this tick
271297
else player.rotation
272298

273299
val speedMultiplier = if (request.keepTicks < 0) 1.0 else request.speedMultiplier

0 commit comments

Comments
 (0)