Skip to content

Commit 958c1b1

Browse files
emyfopsIceTank
authored andcommitted
fixed timer value based on distance to unloaded chunk
1 parent 7ae4223 commit 958c1b1

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
@@ -30,7 +30,7 @@ import com.lambda.module.tag.ModuleTag
3030
import com.lambda.util.Communication.info
3131
import com.lambda.util.NamedEnum
3232
import com.lambda.util.SpeedUnit
33-
import com.lambda.util.math.dist
33+
import com.lambda.util.math.distCenter
3434
import com.lambda.util.world.fastEntitySearch
3535
import net.minecraft.client.network.ClientPlayerEntity
3636
import 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

Comments
 (0)