@@ -30,7 +30,7 @@ import com.lambda.module.tag.ModuleTag
3030import com.lambda.util.Communication.info
3131import com.lambda.util.NamedEnum
3232import com.lambda.util.SpeedUnit
33- import com.lambda.util.math.dist
33+ import com.lambda.util.math.distCenter
3434import com.lambda.util.world.fastEntitySearch
3535import net.minecraft.client.network.ClientPlayerEntity
3636import net.minecraft.client.world.ClientWorld
@@ -113,7 +113,25 @@ object ElytraAltitudeControl : Module(
113113 ControlState .Pitch40Fly -> updatePitch40Controls()
114114 }
115115
116- updateTimerUsage()
116+ if (useTimerOnChunkLoad) {
117+ nearestUnloadedChunk(world, player)
118+ ?.distCenter(player.pos)
119+ ?.let {
120+ if (it <= timerMinChunkDistance * 16.0 ) {
121+ val speedFactor = 0.1f + (it / (timerMinChunkDistance * 16.0 )) * 0.9f
122+ Timer .enable()
123+ Timer .timer = speedFactor.coerceIn(0.1 , 1.0 )
124+ }
125+ }
126+ ? : run {
127+ // FixMe:
128+ // When the timer is changed in an unloaded chunk and the player stop gliding,
129+ // the timer value is never set back.
130+ if (Timer .isEnabled)
131+ Timer .timer = timerReturnValue
132+ }
133+ }
134+
117135 lastPos = player.pos
118136 }
119137 }
@@ -208,24 +226,6 @@ object ElytraAltitudeControl : Module(
208226 }
209227 }
210228
211- private fun SafeContext.updateTimerUsage () {
212- if (useTimerOnChunkLoad) {
213- nearestUnloadedChunk(world, player)
214- ?.dist(player.pos)
215- ?.let {
216- if (it / 16.0 <= timerMinChunkDistance) {
217- val speedFactor = 0.1f + (it / timerMinChunkDistance * 16.0 ) * 0.9f
218- Timer .enable()
219- Timer .timer = speedFactor.coerceIn(0.1 , 1.0 )
220- }
221- }
222- ? : run {
223- if (Timer .isEnabled)
224- Timer .timer = timerReturnValue
225- }
226- }
227- }
228-
229229 fun nearestUnloadedChunk (world : ClientWorld , player : ClientPlayerEntity ): ChunkPos ? {
230230 val scanRangeInt = 25
231231 var nearestChunk: ChunkPos ? = null
0 commit comments