|
1 | 1 | package com.lambda.client.module.modules.movement
|
2 | 2 |
|
| 3 | +import com.lambda.client.event.events.PlayerMoveEvent |
3 | 4 | import com.lambda.client.module.Category
|
4 | 5 | import com.lambda.client.module.Module
|
5 | 6 | import com.lambda.client.module.modules.player.Scaffold
|
6 | 7 | import com.lambda.client.util.BaritoneUtils
|
7 | 8 | import com.lambda.client.util.EntityUtils.flooredPosition
|
8 |
| -import com.lambda.client.util.Wrapper |
9 | 9 | import com.lambda.client.util.math.VectorUtils.toVec3d
|
10 | 10 | import com.lambda.client.util.threads.runSafeR
|
11 |
| -import com.lambda.mixin.entity.MixinEntity |
| 11 | +import com.lambda.client.util.threads.safeListener |
12 | 12 |
|
13 |
| -/** |
14 |
| - * @see MixinEntity.moveInvokeIsSneakingPre |
15 |
| - * @see MixinEntity.moveInvokeIsSneakingPost |
16 |
| - */ |
17 | 13 | object SafeWalk : Module(
|
18 | 14 | name = "SafeWalk",
|
19 | 15 | description = "Keeps you from walking off edges",
|
20 |
| - category = Category.MOVEMENT |
| 16 | + category = Category.MOVEMENT, |
| 17 | + alwaysListening = true |
21 | 18 | ) {
|
22 |
| - private val checkFallDist by setting("Check Fall Distance", true, description = "Check fall distance from edge") |
| 19 | + private val checkFallDist by setting("Safe Fall Allowed", false, description = "Check fall distance from edge") |
23 | 20 |
|
24 | 21 | init {
|
25 |
| - onToggle { |
26 |
| - BaritoneUtils.settings?.assumeSafeWalk?.value = it |
27 |
| - } |
28 |
| - } |
| 22 | + safeListener<PlayerMoveEvent> { event -> |
| 23 | + if ((isEnabled || (Scaffold.isEnabled && Scaffold.safeWalk)) |
| 24 | + && player.onGround |
| 25 | + && !BaritoneUtils.isPathing |
| 26 | + && if (checkFallDist) !isEdgeSafe else true) { |
| 27 | + /** |
| 28 | + * Code here is from net.minecraft.Entity::move |
| 29 | + * Cannot do a mixin on this method's sneak section due to mixin compatibility issues with Future (and possibly other clients) |
| 30 | + */ |
29 | 31 |
|
30 |
| - @JvmStatic |
31 |
| - fun shouldSafewalk(entityID: Int) = |
32 |
| - (Wrapper.player?.let { !it.isSneaking && it.entityId == entityID } ?: false) |
33 |
| - && (isEnabled || Scaffold.isEnabled && Scaffold.safeWalk) |
34 |
| - && (!checkFallDist && !BaritoneUtils.isPathing || !isEdgeSafe) |
35 |
| - |
36 |
| - @JvmStatic |
37 |
| - fun setSneaking(state: Boolean) { |
38 |
| - Wrapper.player?.movementInput?.sneak = state |
| 32 | + var x = event.x |
| 33 | + 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 | + } |
| 51 | + } |
| 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 | + } |
| 67 | + } |
| 68 | + event.x = x |
| 69 | + event.z = z |
| 70 | + } |
| 71 | + } |
39 | 72 | }
|
40 | 73 |
|
41 | 74 | private val isEdgeSafe: Boolean
|
|
0 commit comments