Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeWalk Compatibility #480

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/main/java/com/lambda/mixin/entity/MixinEntity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,30 +21,13 @@ 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)
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PlayerMoveEvent> { 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
Expand Down