Skip to content

Commit 1a0977b

Browse files
committed
use vanilla block and item player interact events to keep parity with vanilla place delay
1 parent a8887fa commit 1a0977b

File tree

1 file changed

+19
-22
lines changed
  • src/main/kotlin/com/lambda/module/modules/player

1 file changed

+19
-22
lines changed

src/main/kotlin/com/lambda/module/modules/player/AirPlace.kt

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.lambda.module.modules.player
2020
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.config.settings.complex.Bind
23+
import com.lambda.context.SafeContext
2324
import com.lambda.event.events.MouseEvent
2425
import com.lambda.event.events.PlayerEvent
2526
import com.lambda.event.events.TickEvent
@@ -67,23 +68,16 @@ object AirPlace : Module(
6768
private var placementState: BlockState? = null
6869
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
6970

70-
private var placedThisTick = false
71-
7271
init {
7372
setDefaultAutomationConfig {
7473
applyEdits {
7574
interactConfig.apply {
7675
::airPlace.edit { defaultValue(InteractConfig.AirPlaceMode.Grim) }
77-
::interactDelay.edit { defaultValue(3) }
7876
}
7977
hideAllGroupsExcept(interactConfig)
8078
}
8179
}
8280

83-
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
84-
placedThisTick = false
85-
}
86-
8781
listen<TickEvent.Pre> {
8882
val selectedStack = player.inventory.selectedStack
8983
val blockItem = selectedStack.item as? BlockItem ?: run {
@@ -107,23 +101,10 @@ object AirPlace : Module(
107101
)
108102
placementPos = placementContext.blockPos
109103
placementState = blockItem.getPlacementState(placementContext)
110-
if (!mc.options.useKey.isPressed) return@listen
111-
placementPos?.let { pos ->
112-
placementState?.let { state ->
113-
runSafeAutomated {
114-
mapOf(pos to TargetState.State(state))
115-
.simulate()
116-
.interactRequest(pendingInteractions)
117-
?.submit()
118-
}
119-
placedThisTick = true
120-
}
121-
}
122104
}
123105

124-
listen<PlayerEvent.Interact.Block> { if (placedThisTick) it.cancel() }
125-
listen<PlayerEvent.Interact.Item> { if (placedThisTick) it.cancel() }
126-
listen<PlayerEvent.Interact.Entity> { if (placedThisTick) it.cancel() }
106+
listen<PlayerEvent.Interact.Block> { if (airPlace()) it.cancel() }
107+
listen<PlayerEvent.Interact.Item> { if (airPlace()) it.cancel() }
127108

128109
onStaticRender { event ->
129110
placementPos?.let { pos ->
@@ -141,4 +122,20 @@ object AirPlace : Module(
141122
distance += event.delta.y
142123
}
143124
}
125+
126+
private fun SafeContext.airPlace(): Boolean {
127+
if (player.inventory.selectedStack.item !is BlockItem) return false
128+
placementPos?.let { pos ->
129+
placementState?.let { state ->
130+
runSafeAutomated {
131+
mapOf(pos to TargetState.State(state))
132+
.simulate()
133+
.interactRequest(pendingInteractions)
134+
?.submit()
135+
}
136+
return true
137+
}
138+
}
139+
return false
140+
}
144141
}

0 commit comments

Comments
 (0)