@@ -35,6 +35,7 @@ import com.lambda.interaction.request.placing.PlaceManager.activeRequest
3535import com.lambda.interaction.request.placing.PlaceManager.processRequest
3636import com.lambda.interaction.request.placing.PlacedBlockHandler.addPendingPlace
3737import com.lambda.interaction.request.placing.PlacedBlockHandler.pendingPlacements
38+ import com.lambda.interaction.request.placing.PlacedBlockHandler.setPendingConfigs
3839import com.lambda.util.BlockUtils.blockState
3940import com.lambda.util.Communication.warn
4041import com.lambda.util.player.gamemode
@@ -97,6 +98,12 @@ object PlaceManager : RequestHandler<PlaceRequest>(
9798 }
9899 }
99100
101+ /* *
102+ * accepts, and processes the request, as long as the current [activeRequest] is null, and the [BreakManager] has not
103+ * been active this tick.
104+ *
105+ * @see processRequest
106+ */
100107 override fun SafeContext.handleRequest (request : PlaceRequest ) {
101108 if (activeRequest != null || BreakManager .activeThisTick) return
102109
@@ -105,6 +112,16 @@ object PlaceManager : RequestHandler<PlaceRequest>(
105112 if (placementsThisTick > 0 ) activeThisTick = true
106113 }
107114
115+ /* *
116+ * If the request is fresh, local variables are populated through the [processRequest] method.
117+ * It then attempts to perform as many placements within this tick as possible from the [potentialPlacements] collection.
118+ *
119+ * If all the [maxPlacementsThisTick] limit is reached and the user has rotations enabled, it will start rotating to
120+ * the next predicted placement in the list for optimal speed.
121+ *
122+ * @see populateFrom
123+ * @see placeBlock
124+ */
108125 fun SafeContext.processRequest (request : PlaceRequest ) {
109126 pendingPlacements.cleanUp()
110127
@@ -136,12 +153,16 @@ object PlaceManager : RequestHandler<PlaceRequest>(
136153 }
137154 }
138155
156+ /* *
157+ * Filters and sorts the [request]'s [PlaceContext]s, placing them into the [potentialPlacements] collection, and
158+ * setting the maxPlacementsThisTick value.
159+ *
160+ * @see canPlace
161+ */
139162 private fun SafeContext.populateFrom (request : PlaceRequest ) {
140163 val place = request.build.placing
141164
142- pendingPlacements.setSizeLimit(place.maxPendingPlacements)
143- pendingPlacements.setDecayTime(request.build.interactionTimeout * 50L )
144-
165+ setPendingConfigs(request)
145166 potentialPlacements = request.contexts
146167 .filter { canPlace(it) }
147168 .sortedWith(
@@ -153,11 +174,19 @@ object PlaceManager : RequestHandler<PlaceRequest>(
153174 maxPlacementsThisTick = (place.placementsPerTick.coerceAtMost(pendingLimit))
154175 }
155176
177+ /* *
178+ * @return if none of the [pendingPlacements] match positions with the [placeContext]
179+ */
156180 private fun canPlace (placeContext : PlaceContext ) =
157181 pendingPlacements.none { pending ->
158182 pending.context.expectedPos == placeContext.expectedPos
159183 }
160184
185+ /* *
186+ * A modified version of the minecraft interactBlock method, renamed to better suit its usage.
187+ *
188+ * @see net.minecraft.client.network.ClientPlayerInteractionManager.interactBlock
189+ */
161190 private fun SafeContext.placeBlock (placeContext : PlaceContext , request : PlaceRequest , hand : Hand ): ActionResult {
162191 interaction.syncSelectedSlot()
163192 val hitResult = placeContext.result
@@ -166,6 +195,11 @@ object PlaceManager : RequestHandler<PlaceRequest>(
166195 return interactBlockInternal(placeContext, request, request.build.placing, hand, hitResult)
167196 }
168197
198+ /* *
199+ * A modified version of the minecraft interactBlockInternal method.
200+ *
201+ * @see net.minecraft.client.network.ClientPlayerInteractionManager.interactBlockInternal
202+ */
169203 private fun SafeContext.interactBlockInternal (
170204 placeContext : PlaceContext ,
171205 request : PlaceRequest ,
@@ -203,6 +237,11 @@ object PlaceManager : RequestHandler<PlaceRequest>(
203237 return ActionResult .PASS
204238 }
205239
240+ /* *
241+ * A modified version of the minecraft useOnBlock method.
242+ *
243+ * @see net.minecraft.item.Item.useOnBlock
244+ */
206245 private fun SafeContext.useOnBlock (
207246 placeContext : PlaceContext ,
208247 request : PlaceRequest ,
@@ -223,6 +262,11 @@ object PlaceManager : RequestHandler<PlaceRequest>(
223262 return place(placeContext, request, hand, hitResult, placeConfig, item, ItemPlacementContext (context))
224263 }
225264
265+ /* *
266+ * A modified version of the minecraft place method.
267+ *
268+ * @see net.minecraft.item.BlockItem.place
269+ */
226270 private fun SafeContext.place (
227271 placeContext : PlaceContext ,
228272 request : PlaceRequest ,
@@ -290,11 +334,17 @@ object PlaceManager : RequestHandler<PlaceRequest>(
290334 return ActionResult .success(world.isClient)
291335 }
292336
337+ /* *
338+ * sends the block placement packet using the given [hand] and [hitResult].
339+ */
293340 private fun SafeContext.sendPlacePacket (hand : Hand , hitResult : BlockHitResult ) =
294341 interaction.sendSequencedPacket(world) { sequence: Int ->
295342 PlayerInteractBlockC2SPacket (hand, hitResult, sequence)
296343 }
297344
345+ /* *
346+ * Plays the block placement sound at a given position.
347+ */
298348 fun SafeContext.placeSound (item : BlockItem , state : BlockState , pos : BlockPos ) {
299349 val blockSoundGroup = state.soundGroup
300350 world.playSound(
@@ -307,6 +357,9 @@ object PlaceManager : RequestHandler<PlaceRequest>(
307357 )
308358 }
309359
360+ /* *
361+ * Must be called before and after placing a block to bypass grim's air place checks.
362+ */
310363 private fun SafeContext.airPlaceOffhandSwap () {
311364 connection.sendPacket(
312365 PlayerActionC2SPacket (
0 commit comments