|
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 |
| 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 | + */ |
| 31 | + |
| 32 | + var x = event.x |
| 33 | + var z = event.z |
| 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) |
| 39 | + } |
| 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) |
| 45 | + } |
| 46 | + |
| 47 | + event.x = x |
| 48 | + event.z = z |
| 49 | + } |
27 | 50 | }
|
28 | 51 | }
|
29 | 52 |
|
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 |
| 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 | + } |
39 | 61 | }
|
40 | 62 |
|
| 63 | + |
41 | 64 | private val isEdgeSafe: Boolean
|
42 | 65 | get() = runSafeR {
|
43 | 66 | val pos = player.flooredPosition.toVec3d(0.5, 0.0, 0.5)
|
|
0 commit comments