Skip to content

Commit f99fc16

Browse files
committed
Optimized mc code
1 parent 1b41667 commit f99fc16

File tree

1 file changed

+22
-32
lines changed
  • src/main/kotlin/com/lambda/client/module/modules/movement

1 file changed

+22
-32
lines changed

src/main/kotlin/com/lambda/client/module/modules/movement/SafeWalk.kt

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,36 @@ object SafeWalk : Module(
3131

3232
var x = event.x
3333
var z = event.z
34-
while (x != 0.0 && world.getCollisionBoxes(player, player.entityBoundingBox.offset(x, (-player.stepHeight).toDouble(), 0.0)).isEmpty()) {
35-
if (x < 0.05 && x >= -0.05) {
36-
x = 0.0
37-
} else if (x > 0.0) {
38-
x -= 0.05
39-
} else {
40-
x += 0.05
41-
}
42-
}
43-
while (z != 0.0 && world.getCollisionBoxes(player, player.entityBoundingBox.offset(0.0, (-player.stepHeight).toDouble(), z)).isEmpty()) {
44-
if (z < 0.05 && z >= -0.05) {
45-
z = 0.0
46-
} else if (z > 0.0) {
47-
z -= 0.05
48-
} else {
49-
z += 0.05
50-
}
34+
35+
var boundingBox = player.entityBoundingBox.offset(0.0, (-player.stepHeight).toDouble(), 0.0)
36+
37+
while (x != 0.0 && world.getCollisionBoxes(player, boundingBox.offset(x, 0.0, 0.0)).isEmpty()) {
38+
x = updateCoordinate(x)
5139
}
52-
while (x != 0.0 && z != 0.0 && world.getCollisionBoxes(player, player.entityBoundingBox.offset(x, (-player.stepHeight).toDouble(), z)).isEmpty()) {
53-
if (x < 0.05 && x >= -0.05) {
54-
x = 0.0
55-
} else if (x > 0.0) {
56-
x -= 0.05
57-
} else {
58-
x += 0.05
59-
}
60-
if (z < 0.05 && z >= -0.05) {
61-
z = 0.0
62-
} else if (z > 0.0) {
63-
z -= 0.05
64-
} else {
65-
z += 0.05
66-
}
40+
41+
boundingBox = boundingBox.offset(x, 0.0, 0.0)
42+
43+
while (z != 0.0 && world.getCollisionBoxes(player, boundingBox.offset(0.0, 0.0, z)).isEmpty()) {
44+
z = updateCoordinate(z)
6745
}
46+
6847
event.x = x
6948
event.z = z
7049
}
7150
}
7251
}
7352

53+
private fun updateCoordinate(coordinate: Double): Double {
54+
return if (coordinate < 0.05 && coordinate >= -0.05) {
55+
0.0
56+
} else if (coordinate > 0.0) {
57+
coordinate - 0.05
58+
} else {
59+
coordinate + 0.05
60+
}
61+
}
62+
63+
7464
private val isEdgeSafe: Boolean
7565
get() = runSafeR {
7666
val pos = player.flooredPosition.toVec3d(0.5, 0.0, 0.5)

0 commit comments

Comments
 (0)