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)
main
Charlotte Som 2022-03-09 01:30:31 +00:00
parent 94075ba509
commit b0dfd4273b
3 changed files with 29 additions and 13 deletions

View File

@ -9,7 +9,8 @@ import codes.som.hibiscus.mixins.MixinExtUpdatePlayerAbilitiesC2SPacket
import codes.som.hibiscus.player import codes.som.hibiscus.player
import codes.som.hibiscus.subsystems.tps.TPSDetectionSubsystem import codes.som.hibiscus.subsystems.tps.TPSDetectionSubsystem
import codes.som.hibiscus.util.ext.requireExtension 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 codes.som.hibiscus.world
import net.minecraft.entity.MovementType import net.minecraft.entity.MovementType
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
@ -37,7 +38,7 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) {
return@on return@on
val movement = val movement =
constructMovementVectorFromKeyboard(player.yaw) calcMoveVec(getMoveInputVecFromPlayerInput(player.input), player.yaw)
.multiply(if (player.isSprinting) 1.5 else 0.75) .multiply(if (player.isSprinting) 1.5 else 0.75)
.multiply(1.0, 0.75, 1.0) .multiply(1.0, 0.75, 1.0)
.multiply(speed.toDouble()) .multiply(speed.toDouble())
@ -67,7 +68,7 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) {
val currTime = System.currentTimeMillis() val currTime = System.currentTimeMillis()
val movement = val movement =
if (lastMoveTime == -1L || currTime - lastMoveTime >= (1000.0 / 21.0) * tpsMultiplier) { if (lastMoveTime == -1L || currTime - lastMoveTime >= (1000.0 / 21.0) * tpsMultiplier) {
constructMovementVectorFromKeyboard(player.yaw) calcMoveVec(getMoveInputVecFromPlayerInput(player.input), player.yaw)
.normalize() .normalize()
.multiply(speed.toDouble() * (10.0 - 1 / 8)) .multiply(speed.toDouble() * (10.0 - 1 / 8))
.multiply(1.0, 0.5, 1.0) .multiply(1.0, 0.5, 1.0)

View File

@ -9,7 +9,8 @@ import codes.som.hibiscus.mixins.MixinExtPlayerInteractEntityC2SPacket
import codes.som.hibiscus.player import codes.som.hibiscus.player
import codes.som.hibiscus.util.ext.requireExtension import codes.som.hibiscus.util.ext.requireExtension
import codes.som.hibiscus.util.graphics.MinecraftRenderPipelineProgress 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 codes.som.hibiscus.world
import net.minecraft.client.input.Input import net.minecraft.client.input.Input
import net.minecraft.client.network.ClientPlayerEntity import net.minecraft.client.network.ClientPlayerEntity
@ -81,7 +82,7 @@ class Freecam : Feature("Freecam", FeatureCategory.VISUAL) {
} }
if (!isControllingPlayer) { if (!isControllingPlayer) {
val movement = constructMovementVectorFromKeyboard(view.yaw) val movement = calcMoveVec(getMoveInputVecFromKeys(), view.yaw)
.multiply(speed.toDouble()) .multiply(speed.toDouble())
// Update entity positional state properly by calling move() // Update entity positional state properly by calling move()
view.move(MovementType.SELF, movement) view.move(MovementType.SELF, movement)

View File

@ -1,14 +1,23 @@
package codes.som.hibiscus.util.math package codes.som.hibiscus.util.math
import codes.som.hibiscus.mc import codes.som.hibiscus.mc
import net.minecraft.client.input.Input
import net.minecraft.util.math.MathHelper import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d import net.minecraft.util.math.Vec3d
import kotlin.math.sign
fun constructMovementVectorFromKeyboard(yawDeg: Float): Vec3d { fun getMoveInputVecFromPlayerInput(input: Input): Vec3d {
val yaw = MathHelper.RADIANS_PER_DEGREE * yawDeg var y = 0.0
val lookVec = Vec3d(-MathHelper.sin(yaw).toDouble(), 0.0, MathHelper.cos(yaw).toDouble()) 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 var movement = Vec3d.ZERO
if (mc.options.forwardKey.isPressed) if (mc.options.forwardKey.isPressed)
movement = movement.add(0.0, 0.0, 1.0) movement = movement.add(0.0, 0.0, 1.0)
@ -23,10 +32,15 @@ fun constructMovementVectorFromKeyboard(yawDeg: Float): Vec3d {
if (mc.options.sneakKey.isPressed) if (mc.options.sneakKey.isPressed)
movement = movement.add(0.0, -1.0, 0.0) 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 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)
}