Skip to content

Commit e557a7c

Browse files
committed
swap mode option in hotbar config. Temporary and permanent
1 parent 2be5c78 commit e557a7c

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ open class BreakSettings(
6060
override val tickStageMask by c.setting("Break Stage Mask", setOf(TickEvent.Input.Post), ALL_STAGES.toSet(), description = "The sub-tick timing at which break actions can be performed").group(baseGroup, Group.General).index()
6161

6262
// Swap
63-
override val swapMode by c.setting("Swap Mode", BreakConfig.SwapMode.End, "Decides when to swap to the best suited tool when breaking a block").group(baseGroup, Group.General).index()
63+
override val swapMode by c.setting("Break Swap Mode", BreakConfig.SwapMode.End, "Decides when to swap to the best suited tool when breaking a block").group(baseGroup, Group.General).index()
6464

6565
// Swing
6666
override val swing by c.setting("Swing Mode", SwingMode.Constant, "The times at which to swing the players hand").group(baseGroup, Group.General).index()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class HotbarSettings(
2828
c: Configurable,
2929
baseGroup: NamedEnum
3030
) : SettingGroup(c), HotbarConfig {
31-
override val keepTicks by c.setting("Keep Ticks", 1, 0..20, 1, "The number of ticks to keep the current hotbar selection active", " ticks").group(baseGroup).index()
31+
override val swapMode by c.setting("Swap Mode", HotbarConfig.SwapMode.Temporary).group(baseGroup).index()
32+
override val keepTicks by c.setting("Keep Ticks", 1, 0..20, 1, "The number of ticks to keep the current hotbar selection active", " ticks") { swapMode == HotbarConfig.SwapMode.Temporary }.group(baseGroup).index()
3233
override val swapDelay by c.setting("Swap Delay", 0, 0..3, 1, "The number of ticks delay before allowing another hotbar selection swap", " ticks").group(baseGroup).index()
3334
override val swapsPerTick by c.setting("Swaps Per Tick", 3, 1..10, 1, "The number of hotbar selection swaps that can take place each tick") { swapDelay <= 0 }.group(baseGroup).index()
3435
override val swapPause by c.setting("Swap Pause", 0, 0..20, 1, "The delay in ticks to pause actions after switching to the slot", " ticks").group(baseGroup).index()

src/main/kotlin/com/lambda/interaction/managers/hotbar/HotbarConfig.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.lambda.event.events.TickEvent
2626
* @param priority The priority of this configuration.
2727
*/
2828
interface HotbarConfig : ISettingGroup {
29+
val swapMode: SwapMode
2930
/**
3031
* The number of ticks to keep the current hotbar selection active.
3132
*/
@@ -54,4 +55,9 @@ interface HotbarConfig : ISettingGroup {
5455
* The sub-tick timings at which hotbar actions can be performed
5556
*/
5657
val tickStageMask: Collection<TickEvent>
58+
59+
enum class SwapMode {
60+
Temporary,
61+
Permanent
62+
}
5763
}

src/main/kotlin/com/lambda/interaction/managers/hotbar/HotbarManager.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import com.lambda.event.events.TickEvent
2525
import com.lambda.event.events.UpdateManagerEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
2727
import com.lambda.interaction.managers.Logger
28+
import com.lambda.interaction.managers.Manager
2829
import com.lambda.interaction.managers.ManagerUtils.newStage
2930
import com.lambda.interaction.managers.ManagerUtils.newTick
30-
import com.lambda.interaction.managers.Manager
31+
import com.lambda.interaction.managers.hotbar.HotbarConfig.SwapMode
3132
import com.lambda.interaction.managers.hotbar.HotbarManager.activeRequest
3233
import com.lambda.interaction.managers.hotbar.HotbarManager.activeSlot
3334
import com.lambda.interaction.managers.hotbar.HotbarManager.checkResetSwap
@@ -148,6 +149,8 @@ object HotbarManager : Manager<HotbarRequest>(
148149
} else activeRequest.swapPauseAge = swappedTicks
149150
if (activeRequest.slot == activeSlot) return true
150151
activeSlot = activeRequest.slot
152+
if (activeRequest.hotbarConfig.swapMode == SwapMode.Permanent)
153+
player.inventory.selectedSlot = activeRequest.slot
151154
interaction.syncSelectedSlot()
152155
}
153156
return true
@@ -162,14 +165,21 @@ object HotbarManager : Manager<HotbarRequest>(
162165
*/
163166
private fun SafeContext.checkResetSwap() {
164167
activeRequest?.let { active ->
165-
val canStopSwap = swapsThisTick < maxSwapsThisTick
166-
if (active.keepTicks <= 0 && tickStage in active.hotbarConfig.tickStageMask && canStopSwap) {
167-
logger.debug("Clearing request and syncing slot", activeRequest)
168-
val prevSlot = activeSlot
169-
activeRequest = null
170-
activeSlot = -1
171-
interaction.syncSelectedSlot()
172-
if (serverSlot != prevSlot) swapsThisTick++
168+
if (active.keepTicks <= 0) {
169+
if (active.hotbarConfig.swapMode == SwapMode.Permanent) {
170+
activeRequest = null
171+
activeSlot = -1
172+
return
173+
}
174+
val canStopSwap = swapsThisTick < maxSwapsThisTick
175+
if (tickStage in active.hotbarConfig.tickStageMask && canStopSwap) {
176+
logger.debug("Clearing request and syncing slot", activeRequest)
177+
val prevSlot = activeSlot
178+
activeRequest = null
179+
activeSlot = -1
180+
interaction.syncSelectedSlot()
181+
if (serverSlot != prevSlot) swapsThisTick++
182+
}
173183
}
174184
}
175185
}

0 commit comments

Comments
 (0)