diff --git a/src/main/java/com/lambda/mixin/entity/MixinEntity.java b/src/main/java/com/lambda/mixin/entity/MixinEntity.java index 06cc5bd0f..1bb391ac2 100644 --- a/src/main/java/com/lambda/mixin/entity/MixinEntity.java +++ b/src/main/java/com/lambda/mixin/entity/MixinEntity.java @@ -1,6 +1,5 @@ package com.lambda.mixin.entity; -import com.lambda.client.module.modules.movement.SafeWalk; import com.lambda.client.module.modules.movement.Step; import com.lambda.client.module.modules.movement.Velocity; import com.lambda.client.module.modules.player.Freecam; @@ -22,7 +21,6 @@ public abstract class MixinEntity { @Shadow private int entityId; @Shadow private AxisAlignedBB boundingBox; - private boolean modifiedSneaking = false; float storedStepHeight = -1; @Inject(method = "applyEntityCollision", at = @At("HEAD"), cancellable = true) @@ -30,22 +28,6 @@ public void applyEntityCollisionHead(Entity entityIn, CallbackInfo ci) { Velocity.handleApplyEntityCollision((Entity) (Object) this, entityIn, ci); } - @Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSneaking()Z", ordinal = 0, shift = At.Shift.BEFORE)) - public void moveInvokeIsSneakingPre(MoverType type, double x, double y, double z, CallbackInfo ci) { - if (SafeWalk.shouldSafewalk(this.entityId)) { - modifiedSneaking = true; - SafeWalk.setSneaking(true); - } - } - - @Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSneaking()Z", ordinal = 0, shift = At.Shift.AFTER)) - public void moveInvokeIsSneakingPost(MoverType type, double x, double y, double z, CallbackInfo ci) { - if (modifiedSneaking) { - modifiedSneaking = false; - SafeWalk.setSneaking(false); - } - } - // Makes the camera guy instead of original player turn around when we move mouse @Inject(method = "turn", at = @At("HEAD"), cancellable = true) public void turn(float yaw, float pitch, CallbackInfo ci) { diff --git a/src/main/kotlin/com/lambda/client/module/modules/movement/SafeWalk.kt b/src/main/kotlin/com/lambda/client/module/modules/movement/SafeWalk.kt index cfa2226fc..38d68e8da 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/movement/SafeWalk.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/movement/SafeWalk.kt @@ -1,43 +1,66 @@ package com.lambda.client.module.modules.movement +import com.lambda.client.event.events.PlayerMoveEvent import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.module.modules.player.Scaffold import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.Wrapper import com.lambda.client.util.math.VectorUtils.toVec3d import com.lambda.client.util.threads.runSafeR -import com.lambda.mixin.entity.MixinEntity +import com.lambda.client.util.threads.safeListener -/** - * @see MixinEntity.moveInvokeIsSneakingPre - * @see MixinEntity.moveInvokeIsSneakingPost - */ object SafeWalk : Module( name = "SafeWalk", description = "Keeps you from walking off edges", - category = Category.MOVEMENT + category = Category.MOVEMENT, + alwaysListening = true ) { - private val checkFallDist by setting("Check Fall Distance", true, description = "Check fall distance from edge") + private val checkFallDist by setting("Safe Fall Allowed", false, description = "Check fall distance from edge") init { - onToggle { - BaritoneUtils.settings?.assumeSafeWalk?.value = it + safeListener { event -> + if ((isEnabled || (Scaffold.isEnabled && Scaffold.safeWalk)) + && player.onGround + && !BaritoneUtils.isPathing + && if (checkFallDist) !isEdgeSafe else true) { + /** + * Code here is from net.minecraft.Entity::move + * Cannot do a mixin on this method's sneak section due to mixin compatibility issues with Future (and possibly other clients) + */ + + var x = event.x + var z = event.z + + var boundingBox = player.entityBoundingBox.offset(0.0, (-player.stepHeight).toDouble(), 0.0) + + while (x != 0.0 && world.getCollisionBoxes(player, boundingBox.offset(x, 0.0, 0.0)).isEmpty()) { + x = updateCoordinate(x) + } + + boundingBox = boundingBox.offset(x, 0.0, 0.0) + + while (z != 0.0 && world.getCollisionBoxes(player, boundingBox.offset(0.0, 0.0, z)).isEmpty()) { + z = updateCoordinate(z) + } + + event.x = x + event.z = z + } } } - @JvmStatic - fun shouldSafewalk(entityID: Int) = - (Wrapper.player?.let { !it.isSneaking && it.entityId == entityID } ?: false) - && (isEnabled || Scaffold.isEnabled && Scaffold.safeWalk) - && (!checkFallDist && !BaritoneUtils.isPathing || !isEdgeSafe) - - @JvmStatic - fun setSneaking(state: Boolean) { - Wrapper.player?.movementInput?.sneak = state + private fun updateCoordinate(coordinate: Double): Double { + return if (coordinate < 0.05 && coordinate >= -0.05) { + 0.0 + } else if (coordinate > 0.0) { + coordinate - 0.05 + } else { + coordinate + 0.05 + } } + private val isEdgeSafe: Boolean get() = runSafeR { val pos = player.flooredPosition.toVec3d(0.5, 0.0, 0.5) diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/Scaffold.kt b/src/main/kotlin/com/lambda/client/module/modules/player/Scaffold.kt index 979610a49..4d4dbab86 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/Scaffold.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/Scaffold.kt @@ -12,7 +12,6 @@ import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket import com.lambda.client.mixin.extension.syncCurrentPlayItem import com.lambda.client.module.Category import com.lambda.client.module.Module -import com.lambda.client.module.modules.player.Scaffold.isUsableItem import com.lambda.client.setting.settings.impl.collection.CollectionSetting import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.MovementUtils.speed @@ -27,7 +26,6 @@ import com.lambda.client.util.world.PlaceInfo import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isFullBox import com.lambda.client.util.world.placeBlock -import com.lambda.mixin.entity.MixinEntity import net.minecraft.block.Block import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks @@ -42,10 +40,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent import java.util.concurrent.ConcurrentHashMap -/** - * @see MixinEntity.moveInvokeIsSneakingPre - * @see MixinEntity.moveInvokeIsSneakingPost - */ object Scaffold : Module( name = "Scaffold", description = "Places blocks under you",