Skip to content

Commit 99a3940

Browse files
committed
Add Universal Keybind to BetterFirework.kt
1 parent 903aff1 commit 99a3940

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

src/main/kotlin/com/lambda/config/settings/complex/KeybindSetting.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ data class Bind(
174174
if (modifiers and GLFW_MOD_NUM_LOCK != 0) add(KeyCode.NUM_LOCK)
175175
}
176176

177+
val isMouseBind: Boolean
178+
get() = mouse >= 0
179+
180+
val isKeyBind: Boolean
181+
get() = key > 0
182+
177183
val name: String
178184
get() {
179185
if (mouse < 0 && modifiers <= 0 && key <= 0) return "Unbound"

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

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ package com.lambda.module.modules.movement
1919

2020
import com.lambda.config.groups.HotbarSettings
2121
import com.lambda.config.settings.collections.SetSetting.Companion.immutableSet
22+
import com.lambda.config.settings.complex.Bind
2223
import com.lambda.context.SafeContext
24+
import com.lambda.event.events.KeyboardEvent
25+
import com.lambda.event.events.MouseEvent
2326
import com.lambda.event.events.TickEvent
2427
import com.lambda.event.listener.SafeListener.Companion.listen
2528
import com.lambda.interaction.material.StackSelection.Companion.selectStack
@@ -28,10 +31,13 @@ import com.lambda.interaction.request.hotbar.HotbarRequest
2831
import com.lambda.module.Module
2932
import com.lambda.module.tag.ModuleTag
3033
import com.lambda.threading.runSafe
34+
import com.lambda.util.KeyCode
35+
import com.lambda.util.Mouse
3136
import com.lambda.util.NamedEnum
3237
import com.lambda.util.player.SlotUtils.hotbar
3338
import com.lambda.util.player.SlotUtils.hotbarAndStorage
3439
import net.minecraft.client.network.ClientPlayerEntity
40+
import net.minecraft.client.option.KeyBinding
3541
import net.minecraft.entity.effect.StatusEffects
3642
import net.minecraft.item.Items
3743
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
@@ -40,19 +46,20 @@ import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket
4046
import net.minecraft.screen.slot.SlotActionType
4147
import net.minecraft.util.Hand
4248
import net.minecraft.util.hit.HitResult
49+
import org.lwjgl.glfw.GLFW
4350

4451
object BetterFirework : Module(
4552
name = "BetterFirework",
4653
description = "Automatic takeoff with fireworks",
4754
tag = ModuleTag.MOVEMENT,
4855
) {
49-
private var middleClick by setting("Middle Click", true, "Use firework on middle mouse click").group(Group.General)
50-
private var middleClickCancel by setting("Middle Click Cancel", false, description = "Cancel pick block action on middle mouse click") { middleClick }.group(Group.General)
56+
private var activateButton by setting("Activate Key", Bind(0, 0, Mouse.Middle.ordinal), "Button to activate Firework").group(Group.General)
57+
private var middleClickCancel by setting("Middle Click Cancel", false, description = "Cancel pick block action on middle mouse click") { activateButton.key != KeyCode.UNBOUND.code }.group(Group.General)
5158
private var fireworkInteract by setting("Right Click Fly", true, "Automatically start flying when right clicking fireworks")
5259
private var fireworkInteractCancel by setting("Right Click Cancel", false, "Cancel block interactions while holding fireworks") { fireworkInteract }
5360

5461
private var clientSwing by setting("Swing", true, "Swing hand client side").group(Group.General)
55-
private var silentUse by setting("Silent", true, "Silent use fireworks from the inventory") { middleClick }.group(Group.General)
62+
private var silentUse by setting("Silent", true, "Silent use fireworks from the inventory") { activateButton.key != KeyCode.UNBOUND.code }.group(Group.General)
5663

5764
override val hotbarConfig = HotbarSettings(this, Group.Hotbar).apply {
5865
::sequenceStageMask.edit { immutableSet(setOf(TickEvent.Pre)) }
@@ -91,6 +98,42 @@ object BetterFirework : Module(
9198
}
9299
}
93100
}
101+
listen<MouseEvent.Click> {
102+
if (!activateButton.isMouseBind || activateButton.mouse == mc.options.pickItemKey.boundKey.code) {
103+
return@listen
104+
}
105+
if (it.isPressed && it.satisfies(activateButton)) {
106+
runSafe {
107+
if (takeoffState != TakeoffState.None) {
108+
return@listen // Prevent using multiple times
109+
}
110+
if (player.canOpenElytra || player.isGliding) {
111+
// If already gliding use another firework
112+
takeoffState = TakeoffState.StartFlying
113+
} else if (player.canTakeoff) {
114+
takeoffState = TakeoffState.Jumping
115+
}
116+
}
117+
}
118+
}
119+
listen<KeyboardEvent.Press> {
120+
if (!activateButton.isKeyBind || activateButton.key == mc.options.pickItemKey.boundKey.code) {
121+
return@listen
122+
}
123+
if (it.isPressed && it.satisfies(activateButton)) {
124+
runSafe {
125+
if (takeoffState != TakeoffState.None) {
126+
return@listen // Prevent using multiple times
127+
}
128+
if (player.canOpenElytra || player.isGliding) {
129+
// If already gliding use another firework
130+
takeoffState = TakeoffState.StartFlying
131+
} else if (player.canTakeoff) {
132+
takeoffState = TakeoffState.Jumping
133+
}
134+
}
135+
}
136+
}
94137
}
95138

96139
/**
@@ -125,10 +168,12 @@ object BetterFirework : Module(
125168
@JvmStatic
126169
fun onPick() =
127170
runSafe {
128-
if (!middleClick) return false
129171
if (mc.crosshairTarget?.type == HitResult.Type.BLOCK && !middleClickCancel) {
130172
return false
131173
}
174+
if (!activateButton.isMouseBind || activateButton.mouse != mc.options.pickItemKey.boundKey.code) {
175+
return false
176+
}
132177
if (takeoffState != TakeoffState.None) {
133178
return false // Prevent using multiple times
134179
}
@@ -138,7 +183,7 @@ object BetterFirework : Module(
138183
} else if (player.canTakeoff) {
139184
takeoffState = TakeoffState.Jumping
140185
}
141-
return true
186+
return middleClickCancel
142187
} ?: false
143188

144189
fun SafeContext.sendSwing() {

0 commit comments

Comments
 (0)