Skip to content

Commit e76fb57

Browse files
committed
Use HotbarManager to swap to firework slots
1 parent 9b235d7 commit e76fb57

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
21+
import com.lambda.event.Event
2122
import com.lambda.event.events.TickEvent
2223
import com.lambda.interaction.request.hotbar.HotbarConfig
2324
import com.lambda.util.NamedEnum
@@ -31,5 +32,5 @@ class HotbarSettings(
3132
override val swapDelay by c.setting("Swap Delay", 0, 0..3, 1, "The number of ticks delay before allowing another hotbar selection swap", " ticks", visibility = vis).group(baseGroup)
3233
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 && vis() }.group(baseGroup)
3334
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", visibility = vis).group(baseGroup)
34-
override val sequenceStageMask by c.setting("Hotbar Stage Mask", setOf(TickEvent.Input.Post), description = "The sub-tick timing at which hotbar actions are performed", visibility = vis).group(baseGroup)
35+
override val sequenceStageMask by c.setting("Hotbar Stage Mask", setOf<Event>(TickEvent.Input.Post), description = "The sub-tick timing at which hotbar actions are performed", visibility = vis).group(baseGroup)
3536
}

src/main/kotlin/com/lambda/module/modules/movement/BetterFirework.kt

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@
1717

1818
package com.lambda.module.modules.movement
1919

20+
import com.lambda.config.groups.HotbarSettings
21+
import com.lambda.config.settings.collections.SetSetting.Companion.immutableSet
2022
import com.lambda.context.SafeContext
2123
import com.lambda.event.events.TickEvent
2224
import com.lambda.event.listener.SafeListener.Companion.listen
2325
import com.lambda.interaction.material.StackSelection.Companion.selectStack
26+
import com.lambda.interaction.request.hotbar.HotbarManager
27+
import com.lambda.interaction.request.hotbar.HotbarRequest
2428
import com.lambda.module.Module
2529
import com.lambda.module.tag.ModuleTag
2630
import com.lambda.threading.runSafe
31+
import com.lambda.util.Communication.warn
32+
import com.lambda.util.NamedEnum
2733
import com.lambda.util.player.SlotUtils.hotbar
34+
import com.lambda.util.player.SlotUtils.hotbarAndStorage
2835
import com.lambda.util.player.SlotUtils.storage
2936
import net.minecraft.client.network.ClientPlayerEntity
3037
import net.minecraft.entity.effect.StatusEffects
@@ -42,14 +49,22 @@ object BetterFirework : Module(
4249
description = "Automatic takeoff with fireworks",
4350
tag = ModuleTag.MOVEMENT,
4451
) {
45-
private var fireworkInteract by setting("Firework Interact", true, "Automatically start flying when right clicking fireworks")
46-
private var fireworkInteractCancel by setting("Firework Interact Cancel", false, "Cancel block interactions while holding fireworks") { fireworkInteract }
52+
private var middleClick by setting("Middle Click", true, "Use firework on middle mouse click").group(Group.General)
53+
private var middleClickCancel by setting("Middle Click Cancel", false, description = "Cancel pick block action on middle mouse click") { middleClick }.group(Group.General)
54+
private var fireworkInteract by setting("Right Click Fly", true, "Automatically start flying when right clicking fireworks")
55+
private var fireworkInteractCancel by setting("Right Click Cancel", false, "Cancel block interactions while holding fireworks") { fireworkInteract }
4756

48-
private var middleClick by setting("Middle Click", true, "Use firework on middle mouse click")
49-
private var middleClickCancel by setting("Middle Click Cancel", false, description = "Cancel pick block action on middle mouse click") { middleClick }
57+
private var clientSwing by setting("Swing", true, "Swing hand client side").group(Group.General)
58+
private var silentUse by setting("Silent", true, "Silent use fireworks from the inventory") { middleClick }.group(Group.General)
5059

51-
private var clientSwing by setting("Swing", true, "Swing hand client side")
52-
private var silentUse by setting("Silent", true, "Silent use fireworks from the inventory") { middleClick }
60+
override val hotbarConfig = HotbarSettings(this, Group.Hotbar).apply {
61+
::sequenceStageMask.edit { immutableSet(setOf(TickEvent.Pre)) }
62+
}
63+
64+
private enum class Group(override val displayName: String) : NamedEnum {
65+
General("General"),
66+
Hotbar("Hotbar")
67+
}
5368

5469
private var takeoffState = TakeoffState.NONE
5570

@@ -146,36 +161,30 @@ object BetterFirework : Module(
146161

147162
stack.bestItemMatch(player.hotbar)
148163
?.let {
149-
val swap = player.hotbar.indexOf(it)
150-
151-
player.networkHandler.sendPacket(UpdateSelectedSlotC2SPacket(swap))
152-
player.networkHandler.sendPacket(PlayerInteractItemC2SPacket(Hand.MAIN_HAND, 0, player.yaw, player.pitch))
153-
sendSwing()
154-
player.networkHandler.sendPacket(UpdateSelectedSlotC2SPacket(player.getInventory().selectedSlot))
164+
val request = HotbarManager.request(HotbarRequest(player.hotbar.indexOf(it), this@BetterFirework, keepTicks = 0))
165+
if (request.done) {
166+
player.networkHandler.sendPacket(PlayerInteractItemC2SPacket(Hand.MAIN_HAND, 0, player.yaw, player.pitch))
167+
sendSwing()
168+
}
155169

156170
return true
157171
}
158172

159173
if (!silent) return false
160174

161-
stack.bestItemMatch(player.storage)
175+
stack.bestItemMatch(player.hotbarAndStorage)
162176
?.let {
163-
val swap = player.storage.indexOf(it)
177+
val swap = player.hotbarAndStorage.indexOf(it)
164178

165179
interaction.clickSlot(player.playerScreenHandler.syncId, swap, 0, SlotActionType.SWAP, mc.player)
166180

167-
if (player.getInventory().selectedSlot != 0) {
168-
player.networkHandler.sendPacket(UpdateSelectedSlotC2SPacket(0))
169-
player.networkHandler.sendPacket(PlayerInteractItemC2SPacket(Hand.MAIN_HAND, 0, player.yaw, player.pitch))
170-
sendSwing()
171-
player.networkHandler.sendPacket(UpdateSelectedSlotC2SPacket(player.getInventory().selectedSlot))
172-
} else {
181+
val request = HotbarManager.request(HotbarRequest(0, this@BetterFirework, keepTicks = 0))
182+
if (request.done) {
173183
player.networkHandler.sendPacket(PlayerInteractItemC2SPacket(Hand.MAIN_HAND, 0, player.yaw, player.pitch))
174184
sendSwing()
175185
}
176186

177187
interaction.clickSlot(player.playerScreenHandler.syncId, swap, 0, SlotActionType.SWAP, mc.player)
178-
179188
return true
180189
}
181190

0 commit comments

Comments
 (0)