Skip to content

Commit a8887fa

Browse files
committed
interact delay setting
1 parent 446870b commit a8887fa

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/main/kotlin/com/lambda/config/groups/InteractSettings.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class InteractSettings(
3636
override val sorter by c.setting("Interaction Sorter", ActionConfig.SortMode.Tool, "The order in which placements are performed").group(baseGroup).index()
3737
override val tickStageMask by c.setting("Interaction Stage Mask", setOf(TickEvent.Input.Post), ALL_STAGES.toSet(), description = "The sub-tick timing at which place actions are performed").group(baseGroup).index()
3838
override val interactConfirmationMode by c.setting("Interact Confirmation", InteractConfirmationMode.PlaceThenAwait, "Wait for block placement confirmation").group(baseGroup).index()
39-
override val maxPendingInteractions by c.setting("Max Pending Interactions", 5, 0..30, 1, "The maximum amount of pending placements").group(baseGroup).index()
39+
override val interactDelay by c.setting("Interact Delay", 0, 0..3, 1, "Tick delay between interacting with another block").group(baseGroup).index()
40+
override val maxPendingInteractions by c.setting("Max Pending Interactions", 5, 0..30, 1, "The maximum amount of pending placements").group(baseGroup).index()
4041
override val interactionsPerTick by c.setting("Interactions Per Tick", 1, 1..30, 1, "Maximum instant block places per tick").group(baseGroup).index()
4142
override val swing by c.setting("Swing On Interact", true, "Swings the players hand when placing").group(baseGroup).index()
4243
override val swingType by c.setting("Interact Swing Type", BuildConfig.SwingType.Vanilla, "The style of swing") { swing }.group(baseGroup).index()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ interface InteractConfig : ActionConfig, ISettingGroup {
2929
val axisRotateSetting: Boolean
3030
val axisRotate get() = rotate && airPlace.isEnabled && axisRotateSetting
3131
val interactConfirmationMode: InteractConfirmationMode
32-
val maxPendingInteractions: Int
32+
val interactDelay: Int
33+
val maxPendingInteractions: Int
3334
val interactionsPerTick: Int
3435
val swing: Boolean
3536
val swingType: BuildConfig.SwingType

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import com.lambda.context.AutomatedSafeContext
2222
import com.lambda.context.SafeContext
2323
import com.lambda.event.Event
2424
import com.lambda.event.EventFlow.post
25+
import com.lambda.event.events.ConnectionEvent
2526
import com.lambda.event.events.MovementEvent
2627
import com.lambda.event.events.TickEvent
2728
import com.lambda.event.events.UpdateManagerEvent
2829
import com.lambda.event.listener.SafeListener.Companion.listen
30+
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
2931
import com.lambda.interaction.construction.simulation.context.InteractContext
3032
import com.lambda.interaction.managers.Logger
3133
import com.lambda.interaction.managers.Manager
@@ -79,6 +81,7 @@ object InteractManager : Manager<InteractRequest>(
7981
private var activeRequest: InteractRequest? = null
8082
private var potentialPlacements = mutableListOf<InteractContext>()
8183

84+
private var interactCooldown = 0
8285
private var placementsThisTick = 0
8386
private var maxPlacementsThisTick = 0
8487

@@ -103,6 +106,9 @@ object InteractManager : Manager<InteractRequest>(
103106
activeRequest = null
104107
placementsThisTick = 0
105108
potentialPlacements.clear()
109+
if (interactCooldown > 0) {
110+
interactCooldown--
111+
}
106112
}
107113

108114
listen<MovementEvent.InputUpdate>(priority = Int.MIN_VALUE) {
@@ -112,6 +118,10 @@ object InteractManager : Manager<InteractRequest>(
112118
}
113119
}
114120

121+
listenUnsafe<ConnectionEvent.Connect.Pre>(priority = Int.MIN_VALUE) {
122+
interactCooldown = 0
123+
}
124+
115125
return "Loaded Place Manager"
116126
}
117127

@@ -150,6 +160,7 @@ object InteractManager : Manager<InteractRequest>(
150160

151161
val iterator = potentialPlacements.iterator()
152162
while (iterator.hasNext()) {
163+
if (interactCooldown > 0) break
153164
if (placementsThisTick + 1 > maxPlacementsThisTick) break
154165
val ctx = iterator.next()
155166

@@ -174,6 +185,7 @@ object InteractManager : Manager<InteractRequest>(
174185
mc.gameRenderer.firstPersonRenderer.resetEquipProgress(Hand.MAIN_HAND)
175186
}
176187
}
188+
interactCooldown = ctx.interactConfig.interactDelay + 1
177189
placementsThisTick++
178190
iterator.remove()
179191
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.config.settings.complex.Bind
2323
import com.lambda.event.events.MouseEvent
24+
import com.lambda.event.events.PlayerEvent
2425
import com.lambda.event.events.TickEvent
2526
import com.lambda.event.events.onStaticRender
2627
import com.lambda.event.listener.SafeListener.Companion.listen
@@ -66,16 +67,23 @@ object AirPlace : Module(
6667
private var placementState: BlockState? = null
6768
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
6869

70+
private var placedThisTick = false
71+
6972
init {
7073
setDefaultAutomationConfig {
7174
applyEdits {
7275
interactConfig.apply {
7376
::airPlace.edit { defaultValue(InteractConfig.AirPlaceMode.Grim) }
77+
::interactDelay.edit { defaultValue(3) }
7478
}
7579
hideAllGroupsExcept(interactConfig)
7680
}
7781
}
7882

83+
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
84+
placedThisTick = false
85+
}
86+
7987
listen<TickEvent.Pre> {
8088
val selectedStack = player.inventory.selectedStack
8189
val blockItem = selectedStack.item as? BlockItem ?: run {
@@ -108,10 +116,15 @@ object AirPlace : Module(
108116
.interactRequest(pendingInteractions)
109117
?.submit()
110118
}
119+
placedThisTick = true
111120
}
112121
}
113122
}
114123

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() }
127+
115128
onStaticRender { event ->
116129
placementPos?.let { pos ->
117130
val boxes = placementState?.getOutlineShape(world, pos)?.boundingBoxes

0 commit comments

Comments
 (0)