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)
This commit is contained in:
parent
94075ba509
commit
b0dfd4273b
3 changed files with 29 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue