Skip to content

Commit 9f617f5

Browse files
committed
perform airplace bypass for regular interactions too
1 parent 7389e70 commit 9f617f5

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/main/kotlin/com/lambda/interaction/managers/interacting/InteractManager.kt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.lambda.interaction.managers.Manager
3030
import com.lambda.interaction.managers.ManagerUtils.isPosBlocked
3131
import com.lambda.interaction.managers.PositionBlocking
3232
import com.lambda.interaction.managers.breaking.BreakManager
33+
import com.lambda.interaction.managers.interacting.InteractConfig.AirPlaceMode
3334
import com.lambda.interaction.managers.interacting.InteractManager.activeRequest
3435
import com.lambda.interaction.managers.interacting.InteractManager.maxPlacementsThisTick
3536
import com.lambda.interaction.managers.interacting.InteractManager.populateFrom
@@ -147,8 +148,23 @@ object InteractManager : Manager<InteractRequest>(
147148
if (!player.validSneak) return
148149
if (tickStage !in interactConfig.tickStageMask) return
149150

150-
val actionResult = if (ctx.preProcessingInfo.placing) placeBlock(ctx, request, Hand.MAIN_HAND)
151-
else interaction.interactBlock(player, Hand.MAIN_HAND, ctx.hitResult)
151+
lateinit var actionResult: ActionResult
152+
fun doAction() {
153+
val hand = if (interactConfig.airPlace == AirPlaceMode.Grim) Hand.OFF_HAND else Hand.MAIN_HAND
154+
actionResult = if (ctx.preProcessingInfo.placing) placeBlock(ctx, request, hand)
155+
else interaction.interactBlock(player, Hand.MAIN_HAND, ctx.hitResult)
156+
}
157+
158+
//ToDo: Once we add 30bps placements we will need to move the air place bypass logic out of the loop to avoid excess packet spam
159+
if (interactConfig.airPlace == AirPlaceMode.Grim) {
160+
val inventoryRequest = inventoryRequest {
161+
swapHands()
162+
action { doAction() }
163+
swapHands()
164+
}.submit(queueIfMismatchedStage = false)
165+
if (!inventoryRequest.done) actionResult = ActionResult.PASS
166+
} else doAction()
167+
152168
if (actionResult.isAccepted && interactConfig.swing) {
153169
swingHand(interactConfig.swingType, Hand.MAIN_HAND)
154170

@@ -224,7 +240,7 @@ object InteractManager : Manager<InteractRequest>(
224240
}
225241
}
226242

227-
val stack = player.mainHandStack
243+
val stack = player.getStackInHand(hand)
228244

229245
if (!stack.isEmpty && !isItemOnCooldown(stack)) {
230246
val itemUsageContext = ItemUsageContext(player, hand, hitResult)
@@ -280,17 +296,7 @@ object InteractManager : Manager<InteractRequest>(
280296
val itemPlacementContext = item.getPlacementContext(context) ?: return ActionResult.FAIL
281297
val blockState = item.getPlacementState(itemPlacementContext) ?: return ActionResult.FAIL
282298

283-
if (interactConfig.airPlace == InteractConfig.AirPlaceMode.Grim) {
284-
val placeHand = if (hand == Hand.MAIN_HAND) Hand.OFF_HAND else Hand.MAIN_HAND
285-
val inventoryRequest = inventoryRequest {
286-
swapHands()
287-
action { sendInteractPacket(placeHand, hitResult) }
288-
swapHands()
289-
}.submit(queueIfMismatchedStage = false)
290-
if (!inventoryRequest.done) return ActionResult.FAIL
291-
} else {
292-
sendInteractPacket(hand, hitResult)
293-
}
299+
sendInteractPacket(hand, hitResult)
294300

295301
if (interactConfig.interactConfirmationMode != InteractConfig.InteractConfirmationMode.None) {
296302
InteractInfo(interactContext, request.pendingInteractions, request.onPlace, interactConfig).startPending()

0 commit comments

Comments
 (0)