@@ -20,6 +20,7 @@ package com.lambda.module.modules.player
2020import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
2121import com.lambda.config.applyEdits
2222import com.lambda.config.settings.complex.Bind
23+ import com.lambda.context.SafeContext
2324import com.lambda.event.events.MouseEvent
2425import com.lambda.event.events.PlayerEvent
2526import 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