@@ -221,45 +221,8 @@ object ElytraFly : Module(
221221
222222 if (autoPitch) rotationRequest { pitch(pitch) }.submit()
223223
224- val playerPos = player.pos
225- val validDistanceFromStart = Vec3d (playerPos.x, startPos.y, playerPos.z) dist startPos > 0.1
226- if (passObstacles && validDistanceFromStart) run obstacleChecks@{
227- val snappedDir = getSnappedDir()
228- val closestLinePoint = playerPos.findClosestPointOnLine(snappedDir)
229-
230- passingToPos?.let { passingTo ->
231- if (passingTo.isObstructed(snappedDir)) {
232- pathToValidPoint(passingTo, snappedDir)
233- }
234- return
235- }
236-
237- val notProgressing = Speedometer .calculateSpeed(true , SpeedUnit .BlocksPerSecond ) < 0.01
238- if (player.isGliding && notProgressing) {
239- pathToValidPoint(closestLinePoint, snappedDir)
240- return
241- }
242-
243- // We only want to account for horizontal and below the line rather than total
244- // distance as jumping from bounce might cause false positives
245- val distanceToLine =
246- Vec3d (
247- playerPos.x,
248- closestLinePoint.y,
249- playerPos.z
250- ).dist(closestLinePoint) + (playerPos.y - closestLinePoint.y).coerceAtMost(0.0 )
251- if (distanceToLine > acceptableOffsetRange) {
252- pathToValidPoint(closestLinePoint, snappedDir, true )
253- return
254- }
255-
256- val isObstructed = Vec3d (playerPos.x, closestLinePoint.y, playerPos.z).isObstructed(snappedDir)
257- if (isObstructed) {
258- pathToValidPoint(closestLinePoint, snappedDir)
259- } else return @obstacleChecks
260-
261- return
262- }
224+ if (passObstacles && player.isOnGround && handleObstaclePassing()) return
225+ if (BaritoneHandler .isActive) return
263226
264227 if (glidePause > 0 && applyPauseAfterBaritone) {
265228 glidePause--
@@ -287,9 +250,51 @@ object ElytraFly : Module(
287250 return lockYawToStep(travelDiff)
288251 }
289252
253+ private fun SafeContext.handleObstaclePassing (): Boolean {
254+ val playerPos = player.pos
255+ val validDistanceFromStart = Vec3d (playerPos.x, startPos.y, playerPos.z) dist startPos > 0.1
256+ if (! validDistanceFromStart) return false
257+
258+ val snappedDir = getSnappedDir()
259+ val closestLinePoint = playerPos.findClosestPointOnLine(snappedDir)
260+
261+ passingToPos?.let { passingTo ->
262+ if (passingTo.isObstructed(snappedDir)) {
263+ pathToValidPoint(passingTo, snappedDir)
264+ }
265+ return true
266+ }
267+
268+ val notProgressing = Speedometer .calculateSpeed(true , SpeedUnit .BlocksPerSecond ) < 0.01
269+ if (player.isGliding && notProgressing) {
270+ pathToValidPoint(closestLinePoint, snappedDir)
271+ return true
272+ }
273+
274+ // We only want to account for horizontal and below the line rather than total
275+ // distance as jumping from bounce might cause false positives
276+ val distanceToLine =
277+ Vec3d (
278+ playerPos.x,
279+ closestLinePoint.y,
280+ playerPos.z
281+ ).dist(closestLinePoint) + (playerPos.y - closestLinePoint.y).coerceAtMost(0.0 )
282+ if (distanceToLine > acceptableOffsetRange) {
283+ pathToValidPoint(closestLinePoint, snappedDir, true )
284+ return true
285+ }
286+
287+ val isObstructed = Vec3d (playerPos.x, closestLinePoint.y, playerPos.z).isObstructed(snappedDir)
288+ if (isObstructed) {
289+ pathToValidPoint(closestLinePoint, snappedDir)
290+ return true
291+ }
292+
293+ return false
294+ }
295+
290296 context(safeContext: SafeContext )
291297 private fun pathToValidPoint (startSearchPos : Vec3d , dir : Vec3d , initialBlockedCheck : Boolean = false) {
292- if (! safeContext.player.isOnGround) return
293298 var skippingFirstCheck = ! initialBlockedCheck
294299 var searchPos = startSearchPos
295300 while (skippingFirstCheck || searchPos.isObstructed(dir)) {
0 commit comments