Skip to content

Commit 1b41667

Browse files
committed
SafeWalk Compatibility
1 parent 9b5e426 commit 1b41667

File tree

3 files changed

+54
-50
lines changed

3 files changed

+54
-50
lines changed

src/main/java/com/lambda/mixin/entity/MixinEntity.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,22 @@
11
package com.lambda.mixin.entity;
22

3-
import com.lambda.client.module.modules.movement.SafeWalk;
43
import com.lambda.client.module.modules.movement.Velocity;
54
import com.lambda.client.module.modules.player.Freecam;
65
import com.lambda.client.module.modules.player.ViewLock;
76
import net.minecraft.entity.Entity;
8-
import net.minecraft.entity.MoverType;
97
import org.spongepowered.asm.mixin.Mixin;
10-
import org.spongepowered.asm.mixin.Shadow;
118
import org.spongepowered.asm.mixin.injection.At;
129
import org.spongepowered.asm.mixin.injection.Inject;
1310
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1411

1512
@Mixin(value = Entity.class, priority = Integer.MAX_VALUE)
1613
public abstract class MixinEntity {
1714

18-
@Shadow private int entityId;
19-
20-
private boolean modifiedSneaking = false;
21-
2215
@Inject(method = "applyEntityCollision", at = @At("HEAD"), cancellable = true)
2316
public void applyEntityCollisionHead(Entity entityIn, CallbackInfo ci) {
2417
Velocity.handleApplyEntityCollision((Entity) (Object) this, entityIn, ci);
2518
}
2619

27-
@Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSneaking()Z", ordinal = 0, shift = At.Shift.BEFORE))
28-
public void moveInvokeIsSneakingPre(MoverType type, double x, double y, double z, CallbackInfo ci) {
29-
if (SafeWalk.shouldSafewalk(this.entityId)) {
30-
modifiedSneaking = true;
31-
SafeWalk.setSneaking(true);
32-
}
33-
}
34-
35-
@Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSneaking()Z", ordinal = 0, shift = At.Shift.AFTER))
36-
public void moveInvokeIsSneakingPost(MoverType type, double x, double y, double z, CallbackInfo ci) {
37-
if (modifiedSneaking) {
38-
modifiedSneaking = false;
39-
SafeWalk.setSneaking(false);
40-
}
41-
}
42-
4320
// Makes the camera guy instead of original player turn around when we move mouse
4421
@Inject(method = "turn", at = @At("HEAD"), cancellable = true)
4522
public void turn(float yaw, float pitch, CallbackInfo ci) {

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

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,74 @@
11
package com.lambda.client.module.modules.movement
22

3+
import com.lambda.client.event.events.PlayerMoveEvent
34
import com.lambda.client.module.Category
45
import com.lambda.client.module.Module
56
import com.lambda.client.module.modules.player.Scaffold
67
import com.lambda.client.util.BaritoneUtils
78
import com.lambda.client.util.EntityUtils.flooredPosition
8-
import com.lambda.client.util.Wrapper
99
import com.lambda.client.util.math.VectorUtils.toVec3d
1010
import com.lambda.client.util.threads.runSafeR
11-
import com.lambda.mixin.entity.MixinEntity
11+
import com.lambda.client.util.threads.safeListener
1212

13-
/**
14-
* @see MixinEntity.moveInvokeIsSneakingPre
15-
* @see MixinEntity.moveInvokeIsSneakingPost
16-
*/
1713
object SafeWalk : Module(
1814
name = "SafeWalk",
1915
description = "Keeps you from walking off edges",
20-
category = Category.MOVEMENT
16+
category = Category.MOVEMENT,
17+
alwaysListening = true
2118
) {
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")
2320

2421
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+
*/
2931

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+
}
3972
}
4073

4174
private val isEdgeSafe: Boolean

src/main/kotlin/com/lambda/client/module/modules/player/Scaffold.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket
1212
import com.lambda.client.mixin.extension.syncCurrentPlayItem
1313
import com.lambda.client.module.Category
1414
import com.lambda.client.module.Module
15-
import com.lambda.client.module.modules.player.Scaffold.isUsableItem
1615
import com.lambda.client.setting.settings.impl.collection.CollectionSetting
1716
import com.lambda.client.util.EntityUtils.flooredPosition
1817
import com.lambda.client.util.MovementUtils.speed
@@ -27,7 +26,6 @@ import com.lambda.client.util.world.PlaceInfo
2726
import com.lambda.client.util.world.getNeighbour
2827
import com.lambda.client.util.world.isFullBox
2928
import com.lambda.client.util.world.placeBlock
30-
import com.lambda.mixin.entity.MixinEntity
3129
import net.minecraft.block.Block
3230
import net.minecraft.block.state.IBlockState
3331
import net.minecraft.init.Blocks
@@ -42,10 +40,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent
4240
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
4341
import java.util.concurrent.ConcurrentHashMap
4442

45-
/**
46-
* @see MixinEntity.moveInvokeIsSneakingPre
47-
* @see MixinEntity.moveInvokeIsSneakingPost
48-
*/
4943
object Scaffold : Module(
5044
name = "Scaffold",
5145
description = "Places blocks under you",

0 commit comments

Comments
 (0)