From b0dfd4273b1a7a6f37c657b32657fcda4c4864cb Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Wed, 9 Mar 2022 01:30:31 +0000 Subject: [PATCH] Use the player.input for Flight movement vector calculation This means that using Flight with hard or max mode won't move the player around when trying to move the camera around in Freecam (i.e. when not controlling the player) --- .../som/hibiscus/features/movement/Flight.kt | 7 +++-- .../som/hibiscus/features/visual/Freecam.kt | 5 ++-- .../som/hibiscus/util/math/MovementVector.kt | 30 ++++++++++++++----- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt b/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt index 64365af..e21bc47 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt @@ -9,7 +9,8 @@ import codes.som.hibiscus.mixins.MixinExtUpdatePlayerAbilitiesC2SPacket import codes.som.hibiscus.player import codes.som.hibiscus.subsystems.tps.TPSDetectionSubsystem import codes.som.hibiscus.util.ext.requireExtension -import codes.som.hibiscus.util.math.constructMovementVectorFromKeyboard +import codes.som.hibiscus.util.math.calcMoveVec +import codes.som.hibiscus.util.math.getMoveInputVecFromPlayerInput import codes.som.hibiscus.world import net.minecraft.entity.MovementType import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket @@ -37,7 +38,7 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) { return@on val movement = - constructMovementVectorFromKeyboard(player.yaw) + calcMoveVec(getMoveInputVecFromPlayerInput(player.input), player.yaw) .multiply(if (player.isSprinting) 1.5 else 0.75) .multiply(1.0, 0.75, 1.0) .multiply(speed.toDouble()) @@ -67,7 +68,7 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) { val currTime = System.currentTimeMillis() val movement = if (lastMoveTime == -1L || currTime - lastMoveTime >= (1000.0 / 21.0) * tpsMultiplier) { - constructMovementVectorFromKeyboard(player.yaw) + calcMoveVec(getMoveInputVecFromPlayerInput(player.input), player.yaw) .normalize() .multiply(speed.toDouble() * (10.0 - 1 / 8)) .multiply(1.0, 0.5, 1.0) diff --git a/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt b/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt index cc788cf..8d560ad 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt @@ -9,7 +9,8 @@ import codes.som.hibiscus.mixins.MixinExtPlayerInteractEntityC2SPacket import codes.som.hibiscus.player import codes.som.hibiscus.util.ext.requireExtension import codes.som.hibiscus.util.graphics.MinecraftRenderPipelineProgress -import codes.som.hibiscus.util.math.constructMovementVectorFromKeyboard +import codes.som.hibiscus.util.math.calcMoveVec +import codes.som.hibiscus.util.math.getMoveInputVecFromKeys import codes.som.hibiscus.world import net.minecraft.client.input.Input import net.minecraft.client.network.ClientPlayerEntity @@ -81,7 +82,7 @@ class Freecam : Feature("Freecam", FeatureCategory.VISUAL) { } if (!isControllingPlayer) { - val movement = constructMovementVectorFromKeyboard(view.yaw) + val movement = calcMoveVec(getMoveInputVecFromKeys(), view.yaw) .multiply(speed.toDouble()) // Update entity positional state properly by calling move() view.move(MovementType.SELF, movement) diff --git a/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt b/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt index 32ddaa8..3cbc54e 100644 --- a/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt +++ b/src/main/kotlin/codes/som/hibiscus/util/math/MovementVector.kt @@ -1,14 +1,23 @@ package codes.som.hibiscus.util.math import codes.som.hibiscus.mc +import net.minecraft.client.input.Input import net.minecraft.util.math.MathHelper import net.minecraft.util.math.Vec3d +import kotlin.math.sign -fun constructMovementVectorFromKeyboard(yawDeg: Float): Vec3d { - val yaw = MathHelper.RADIANS_PER_DEGREE * yawDeg - val lookVec = Vec3d(-MathHelper.sin(yaw).toDouble(), 0.0, MathHelper.cos(yaw).toDouble()) +fun getMoveInputVecFromPlayerInput(input: Input): Vec3d { + var y = 0.0 + if (input.jumping) + y += 1.0 + if (input.sneaking) + y -= 1.0 + return Vec3d(input.sidewaysMovement.toDouble().sign, y, input.forwardMovement.toDouble().sign) +} + +fun getMoveInputVecFromKeys(): Vec3d { var movement = Vec3d.ZERO if (mc.options.forwardKey.isPressed) movement = movement.add(0.0, 0.0, 1.0) @@ -23,10 +32,15 @@ fun constructMovementVectorFromKeyboard(yawDeg: Float): Vec3d { if (mc.options.sneakKey.isPressed) movement = movement.add(0.0, -1.0, 0.0) - movement = lookVec - .multiply(movement.z) - .add(lookVec.rotateY(-MathHelper.HALF_PI).multiply(movement.x)) - .add(0.0, movement.y, 0.0) - return movement } + +fun calcMoveVec(moveInputVec: Vec3d, yawDeg: Float): Vec3d { + val yaw = MathHelper.RADIANS_PER_DEGREE * yawDeg + val lookVec = Vec3d(-MathHelper.sin(yaw).toDouble(), 0.0, MathHelper.cos(yaw).toDouble()) + + return lookVec + .multiply(moveInputVec.z) + .add(lookVec.rotateY(-MathHelper.HALF_PI).multiply(moveInputVec.x)) + .add(0.0, moveInputVec.y, 0.0) +}