Skip to content

Commit 4848282

Browse files
authored
fixed timer value based on distance to unloaded chunk
1 parent 402aa67 commit 4848282

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import com.lambda.module.tag.ModuleTag
2828
import com.lambda.util.Communication.info
2929
import com.lambda.util.NamedEnum
3030
import com.lambda.util.SpeedUnit
31-
import com.lambda.util.math.dist
31+
import com.lambda.util.math.distCenter
3232
import com.lambda.util.world.fastEntitySearch
3333
import net.minecraft.client.network.ClientPlayerEntity
3434
import net.minecraft.client.world.ClientWorld
@@ -105,7 +105,25 @@ object ElytraAltitudeControl : Module(
105105
ControlState.Pitch40Fly -> updatePitch40Controls()
106106
}
107107

108-
updateTimerUsage()
108+
if (useTimerOnChunkLoad) {
109+
nearestUnloadedChunk(world, player)
110+
?.distCenter(player.pos)
111+
?.let {
112+
if (it <= timerMinChunkDistance * 16.0) {
113+
val speedFactor = 0.1f + (it / (timerMinChunkDistance * 16.0)) * 0.9f
114+
Timer.enable()
115+
Timer.timer = speedFactor.coerceIn(0.1, 1.0)
116+
}
117+
}
118+
?: run {
119+
// FixMe:
120+
// When the timer is changed in an unloaded chunk and the player stop gliding,
121+
// the timer value is never set back.
122+
if (Timer.isEnabled)
123+
Timer.timer = timerReturnValue
124+
}
125+
}
126+
109127
lastPos = player.pos
110128
}
111129
}
@@ -213,24 +231,6 @@ object ElytraAltitudeControl : Module(
213231
}
214232
}
215233

216-
private fun SafeContext.updateTimerUsage() {
217-
if (useTimerOnChunkLoad) {
218-
nearestUnloadedChunk(world, player)
219-
?.dist(player.pos)
220-
?.let {
221-
if (it / 16.0 <= timerMinChunkDistance) {
222-
val speedFactor = 0.1f + (it / timerMinChunkDistance * 16.0) * 0.9f
223-
Timer.enable()
224-
Timer.timer = speedFactor.coerceIn(0.1, 1.0)
225-
}
226-
}
227-
?: run {
228-
if (Timer.isEnabled)
229-
Timer.timer = timerReturnValue
230-
}
231-
}
232-
}
233-
234234
fun nearestUnloadedChunk(world: ClientWorld, player: ClientPlayerEntity): ChunkPos? {
235235
val scanRangeInt = 25
236236
var nearestChunk: ChunkPos? = null

0 commit comments

Comments
 (0)