Skip to content

Commit 70a6fe6

Browse files
committed
Grim SafeWalk
1 parent ca58b38 commit 70a6fe6

File tree

1 file changed

+41
-5
lines changed
  • common/src/main/kotlin/com/lambda/module/modules/movement

1 file changed

+41
-5
lines changed

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

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,57 @@ import com.lambda.event.events.MovementEvent
44
import com.lambda.event.listener.SafeListener.Companion.listener
55
import com.lambda.module.Module
66
import com.lambda.module.tag.ModuleTag
7+
import net.minecraft.entity.LivingEntity
78

89
object SafeWalk : Module(
910
name = "SafeWalk",
1011
description = "Keeps you at the edge",
1112
defaultTags = setOf(ModuleTag.MOVEMENT)
1213
) {
13-
private val realisticCollision by setting("Collide", true, "Realistic collision on the edge")
14+
private val sneakOnLedge by setting("Sneak On Ledge", true)
15+
private val ledgeDistance by setting("Ledge Distance", 0.25, 0.0..0.5, 0.05, unit = " blocks")
16+
private val stepHeight by setting("Minimum Step Height", 1.0, 0.0..4.0, 0.1, unit = " blocks")
1417

1518
init {
16-
// listener<MovementEvent.Post> {
17-
// if (realisticCollision) player.velocity = Vec3d.ZERO
18-
// }
19+
listener<MovementEvent.InputUpdate> {
20+
if (sneakOnLedge && player.isOnGround && player.isNearLedge(ledgeDistance, stepHeight)) {
21+
it.input.sneaking = true
22+
}
23+
}
1924

2025
listener<MovementEvent.ClipAtLedge> {
21-
it.clip = true
26+
if (!sneakOnLedge) it.clip = true
2227
}
2328
}
29+
30+
private fun LivingEntity.isNearLedge(distance: Double, stepHeight: Double): Boolean {
31+
fun checkDirection(deltaX: Double, deltaZ: Double): Boolean {
32+
var dx = deltaX
33+
var dz = deltaZ
34+
while (dx != 0.0 || dz != 0.0) {
35+
if (world.isSpaceEmpty(this, boundingBox.offset(dx, -stepHeight, dz))) {
36+
return true
37+
}
38+
if (dx != 0.0) dx = adjustDelta(dx)
39+
if (dz != 0.0) dz = adjustDelta(dz)
40+
}
41+
return false
42+
}
43+
44+
return checkDirection(distance, 0.0) || // Positive X
45+
checkDirection(-distance, 0.0) || // Negative X
46+
checkDirection(0.0, distance) || // Positive Z
47+
checkDirection(0.0, -distance) || // Negative Z
48+
checkDirection(distance, distance) || // Positive X, Positive Z
49+
checkDirection(-distance, distance) || // Negative X, Positive Z
50+
checkDirection(distance, -distance) || // Positive X, Negative Z
51+
checkDirection(-distance, -distance) // Negative X, Negative Z
52+
}
53+
54+
private fun adjustDelta(delta: Double) =
55+
when {
56+
delta < 0.05 && delta >= -0.05 -> 0.0
57+
delta > 0.0 -> delta - 0.05
58+
else -> delta + 0.05
59+
}
2460
}

0 commit comments

Comments
 (0)