Skip to content

Commit fe0a151

Browse files
committed
Fix bugs
Fixes #20 Fixes #19 Fixes #18 Fixes #15 Fixes #16 Fixes #13
1 parent 91f41c2 commit fe0a151

8 files changed

Lines changed: 91 additions & 50 deletions

File tree

build.gradle.kts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ val modversion = property("mod.version") as String
1313
val mcversion = property("minecraft_version") as String
1414
val versionrange = property("minecraft_version_range") as String
1515
val loaderversion = property("loader_version") as String
16-
val oneconfigVersion = "1.0.0-beta.4"
16+
val oneconfigVersion = "1.0.0-beta.6"
1717

1818
base {
1919
archivesName.set("$modid-$modversion+$mcversion")
@@ -31,12 +31,17 @@ repositories {
3131
maven("https://central.sonatype.com/repository/maven-snapshots")
3232
maven("https://repo.papermc.io/repository/maven-public")
3333

34-
maven("https://maven.logix.dev/snapshots")
34+
maven("https://maven.logix.dev/snapshots") {
35+
content { excludeGroup("com.terraformersmc") }
36+
}
3537
maven("https://nexus.prsm.wtf/repository/maven-public/maven-repo/releases/")
3638
maven("https://repo.hypixel.net/repository/Hypixel/")
3739
maven("https://maven.deftu.dev/releases")
3840

3941
maven("https://maven.fabricmc.net/releases")
42+
maven("https://maven.terraformersmc.com/releases") {
43+
content { includeGroup("com.terraformersmc") }
44+
}
4045
maven("https://jitpack.io") {
4146
content { includeGroupAndSubgroups("com.github") }
4247
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod.id=polysprint
33
mod.version=1.1.0-alpha.1
44
mod.group=org.polyfrost
55

6-
loomx.loom_version=1.16-SNAPSHOT
6+
loomx.loom_version=1.17-SNAPSHOT
77
loader_version=0.19.2
88
fabric_kotlin_version=1.13.8+kotlin.2.3.0
99
minecraft_version=[VERSIONED]

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/org/polyfrost/polysprint/mixins/Mixin_SetFlyBoost.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public Mixin_SetFlyBoost(ClientLevel level, GameProfile profile) {
4747

4848
@Inject(method = "aiStep", at = @At("HEAD"))
4949
private void polysprint$modifyFlightSpeed(CallbackInfo ci) {
50+
if (!SprintState.isFlyBoostEnabled()) {
51+
return;
52+
}
53+
5054
final float base = 0.05f;
5155

5256
if (!SprintState.isFlyBoosting()) {

src/main/kotlin/org/polyfrost/polysprint/client/PolySprintClient.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.polyfrost.oneconfig.api.commands.v1.CommandManager
2626
import org.polyfrost.oneconfig.api.event.v1.eventHandler
2727
import org.polyfrost.oneconfig.api.event.v1.events.KeyInputEvent
2828
import org.polyfrost.oneconfig.api.event.v1.events.MouseInputEvent
29+
import org.polyfrost.oneconfig.api.event.v1.events.TickEvent
2930
import org.polyfrost.oneconfig.api.hud.v1.HudManager
3031
import org.polyfrost.oneconfig.utils.v1.dsl.createScreen
3132
import org.polyfrost.polysprint.PolySprintConstants
@@ -40,6 +41,7 @@ object PolySprintClient {
4041
fun initialize() {
4142
PolySprintConfig.preload()
4243
PolySprintConfig.syncTogglesFromVanilla()
44+
PolySprintConfig.syncTogglesToVanilla()
4345
HudManager.register(PolySprintHud())
4446

4547
eventHandler { _: KeyInputEvent ->
@@ -50,6 +52,16 @@ object PolySprintClient {
5052
processInput()
5153
}.register()
5254

55+
eventHandler { event: SprintStateEvent.End ->
56+
if (event.type == SprintStateEvent.Type.FLY && PolySprintConfig.toggleFlyBoost) {
57+
PolySprintConfig.resyncSprintKeyState()
58+
}
59+
}.register()
60+
61+
eventHandler { _: TickEvent.End ->
62+
PolySprintConfig.reassertToggledKeys()
63+
}.register()
64+
5365
CommandManager.register(CommandManager.literal(PolySprintConstants.ID).executes {
5466
PolySprintConfig.syncTogglesFromVanilla()
5567
//? if =26.2 {
@@ -63,16 +75,6 @@ object PolySprintClient {
6375
initialized = true
6476
}
6577

66-
@JvmStatic
67-
fun invertSprintHeld() {
68-
isSprintHeld = !isSprintHeld
69-
}
70-
71-
@JvmStatic
72-
fun invertSneakHeld() {
73-
isSneakHeld = !isSneakHeld
74-
}
75-
7678
@JvmStatic
7779
fun syncTogglesFromVanillaOptions() {
7880
if (!initialized) {
@@ -87,9 +89,15 @@ object PolySprintClient {
8789
return
8890
}
8991

92+
if (HudManager.isGuiScreenOpen) {
93+
return
94+
}
95+
96+
val flying = Minecraft.getInstance().player?.abilities?.flying == true
97+
9098
val sprintKey = Minecraft.getInstance().options.keySprint
9199
if (!PolySprintConfig.keybindToggleSprint && sprintKey.isPhysicallyDown()) {
92-
if (isToggleSprintEnabled && !isSprintHeld) {
100+
if (!flying && isToggleSprintEnabled && !isSprintHeld) {
93101
PolySprintConfig.invertToggleSprintState()
94102
}
95103

@@ -110,6 +118,9 @@ object PolySprintClient {
110118
}
111119
}
112120

121+
@JvmStatic
122+
fun isKeyPhysicallyDown(key: KeyMapping): Boolean = key.isPhysicallyDown()
123+
113124
private fun KeyMapping.isPhysicallyDown(): Boolean {
114125
val key = InputConstants.getKey(saveString())
115126
return when (key.type) {

src/main/kotlin/org/polyfrost/polysprint/client/PolySprintConfig.kt

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,46 +62,42 @@ object PolySprintConfig : Config(
6262
var toggleSneakState = false
6363

6464
@Switch(
65-
title = "Seperate Keybind for Toggle Sprint",
65+
title = "Separate Keybind for Toggle Sprint",
6666
subcategory = "Toggle Sprint",
67-
description = "Use a seperate keybind for Toggle Sprint."
67+
description = "Use a separate keybind for Toggle Sprint."
6868
)
6969
var keybindToggleSprint = false
7070

7171
@Keybind(
7272
title = "Toggle Sprint Keybind",
7373
subcategory = "Toggle Sprint"
7474
)
75-
var keybindToggleSprintKey = KeybindHelper.builder().key(InputConstants.UNKNOWN.value).action(Runnable {
76-
if (keybindToggleSprint) {
77-
if (isEnabled && isToggleSprintEnabled && !PolySprintClient.isSprintHeld) {
78-
invertToggleSprintState()
79-
}
80-
81-
PolySprintClient.invertSprintHeld()
75+
var keybindToggleSprintKey = KeybindHelper.builder().key(InputConstants.UNKNOWN.value).action { pressed: Boolean ->
76+
if (keybindToggleSprint && pressed && isEnabled && isToggleSprintEnabled) {
77+
invertToggleSprintState()
8278
}
83-
}).build()
79+
80+
true
81+
}.build()
8482

8583
@Switch(
86-
title = "Seperate Keybind for Toggle Sneak",
84+
title = "Separate Keybind for Toggle Sneak",
8785
subcategory = "Toggle Sneak",
88-
description = "Use a seperate keybind for Toggle Sneak."
86+
description = "Use a separate keybind for Toggle Sneak."
8987
)
9088
var keybindToggleSneak = false
9189

9290
@Keybind(
9391
title = "Toggle Sneak Keybind",
9492
subcategory = "Toggle Sneak"
9593
)
96-
var keybindToggleSneakKey = KeybindHelper.builder().key(InputConstants.UNKNOWN.value).action(Runnable {
97-
if (keybindToggleSneak) {
98-
if (isEnabled && isToggleSneakEnabled && !PolySprintClient.isSneakHeld) {
99-
invertToggleSneakState()
100-
}
101-
102-
PolySprintClient.invertSneakHeld()
94+
var keybindToggleSneakKey = KeybindHelper.builder().key(InputConstants.UNKNOWN.value).action { pressed: Boolean ->
95+
if (keybindToggleSneak && pressed && isEnabled && isToggleSneakEnabled) {
96+
invertToggleSneakState()
10397
}
104-
}).build()
98+
99+
true
100+
}.build()
105101

106102
@Switch(
107103
title = "Fly Boost",
@@ -126,26 +122,25 @@ object PolySprintConfig : Config(
126122
addDependency("keybindToggleSneakKey", "keybindToggleSneak")
127123
addCallback("toggleSprint") { syncToggleSprintToVanilla() }
128124
addCallback("toggleSneak") { syncToggleSneakToVanilla() }
125+
addCallback("keybindToggleSprint") { syncToggleSprintToVanilla() }
126+
addCallback("keybindToggleSneak") { syncToggleSneakToVanilla() }
129127

130128
KeybindManager.register(keybindToggleSprintKey)
131129
KeybindManager.register(keybindToggleSneakKey)
132130
}
133131

134132
fun syncTogglesFromVanilla(persist: Boolean = false) {
135-
val options = Minecraft.getInstance().options ?: return
136-
val vanillaToggleSprint = options.toggleSprint().get()
137-
val vanillaToggleSneak = options.toggleCrouch().get()
138-
val changed = toggleSprint != vanillaToggleSprint || toggleSneak != vanillaToggleSneak
139-
140-
toggleSprint = vanillaToggleSprint
141-
toggleSneak = vanillaToggleSneak
133+
syncToggleSprintFromVanilla(persist)
134+
syncToggleSneakFromVanilla(persist)
135+
}
142136

143-
if (persist && changed) {
144-
save()
145-
}
137+
fun syncTogglesToVanilla() {
138+
syncToggleSprintToVanilla()
139+
syncToggleSneakToVanilla()
146140
}
147141

148142
fun syncToggleSprintFromVanilla(persist: Boolean = false) {
143+
if (keybindToggleSprint) return
149144
val options = Minecraft.getInstance().options ?: return
150145
val vanillaToggleSprint = options.toggleSprint().get()
151146
val changed = toggleSprint != vanillaToggleSprint
@@ -158,6 +153,7 @@ object PolySprintConfig : Config(
158153
}
159154

160155
fun syncToggleSneakFromVanilla(persist: Boolean = false) {
156+
if (keybindToggleSneak) return
161157
val options = Minecraft.getInstance().options ?: return
162158
val vanillaToggleSneak = options.toggleCrouch().get()
163159
val changed = toggleSneak != vanillaToggleSneak
@@ -171,16 +167,31 @@ object PolySprintConfig : Config(
171167

172168
private fun syncToggleSprintToVanilla() {
173169
val options = Minecraft.getInstance().options ?: return
174-
options.toggleSprint().set(toggleSprint)
170+
options.toggleSprint().set(toggleSprint && !keybindToggleSprint)
175171
options.save()
176172
}
177173

178174
private fun syncToggleSneakToVanilla() {
179175
val options = Minecraft.getInstance().options ?: return
180-
options.toggleCrouch().set(toggleSneak)
176+
options.toggleCrouch().set(toggleSneak && !keybindToggleSneak)
181177
options.save()
182178
}
183179

180+
fun reassertToggledKeys() {
181+
val options = Minecraft.getInstance().options ?: return
182+
if (keybindToggleSprint && toggleSprintState) {
183+
(options.keySprint as StickyKeyBindingSetter).`polySprint$toggle`(true)
184+
}
185+
if (keybindToggleSneak && toggleSneakState) {
186+
(options.keyShift as StickyKeyBindingSetter).`polySprint$toggle`(true)
187+
}
188+
}
189+
190+
fun resyncSprintKeyState() {
191+
val options = Minecraft.getInstance().options ?: return
192+
(options.keySprint as StickyKeyBindingSetter).`polySprint$toggle`(toggleSprintState)
193+
}
194+
184195
fun invertToggleSprintState() {
185196
toggleSprintState = !toggleSprintState
186197
(Minecraft.getInstance().options.keySprint as StickyKeyBindingSetter).`polySprint$toggle`(PolySprintConfig.toggleSprintState)

src/main/kotlin/org/polyfrost/polysprint/client/PolySprintHud.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class PolySprintHud : TextHud(
143143
)
144144
var sprint = "Sprinting (vanilla)"
145145

146+
override fun updateFrequency(): Long = 100_000_000L
147+
146148
override fun setup() {
147149
super.setup()
148150

src/main/kotlin/org/polyfrost/polysprint/client/SprintState.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,20 @@ fun isSneakingToggled(keyBinding: KeyMapping): Boolean {
5959
}
6060

6161

62-
// TODO: this isnt always correct
62+
fun isFlyBoostEnabled(): Boolean {
63+
if (Minecraft.getInstance().options == null) {
64+
return false
65+
}
66+
67+
return PolySprintConfig.isEnabled && PolySprintConfig.toggleFlyBoost
68+
}
69+
6370
fun isFlyBoosting(): Boolean {
6471
val client = Minecraft.getInstance()
6572
val player = client.player ?: return false
66-
val sprintKey = client.options.keySprint
67-
return sprintKey.isDown && PolySprintConfig.isEnabled && PolySprintConfig.toggleFlyBoost && player.abilities.flying && player.abilities.instabuild
73+
if (!PolySprintConfig.isEnabled || !PolySprintConfig.toggleFlyBoost) return false
74+
if (!player.abilities.flying || !player.abilities.instabuild) return false
75+
return PolySprintClient.isKeyPhysicallyDown(client.options.keySprint)
6876
}
6977

7078
private fun optionallyStateful(keyBinding: KeyMapping?, consumer: () -> Boolean): Boolean {

0 commit comments

Comments
 (0)