[feature] Added DirectionMode to Freecam (#1650)

Co-authored-by: Dominika <sokolov.dominika@gmail.com>
This commit is contained in:
FriedrichM 2020-12-04 00:17:33 +01:00 committed by GitHub
parent 239221805f
commit 0866cf514a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -36,10 +36,15 @@ import kotlin.math.sin
)
object Freecam : Module() {
private val horizontalSpeed = register(Settings.floatBuilder("HorizontalSpeed").withValue(20f).withRange(1f, 50f).withStep(1f))
private val verticalSpeed = register(Settings.floatBuilder("VerticalSpeed").withValue(20f).withRange(1f, 50f).withStep(1f))
private val verticalSpeed = register(Settings.floatBuilder("VerticalSpeed").withValue(20f).withRange(1f, 50f).withStep(1f).withVisibility { directionMode.value == DirectionMode.CREATIVE })
private val autoRotate = register(Settings.b("AutoRotate", true))
private val arrowKeyMove = register(Settings.b("ArrowKeyMove", true))
private val disableOnDisconnect = register(Settings.b("DisconnectDisable", true))
private val directionMode = register(Settings.e<DirectionMode>("DirectionMode", DirectionMode.CREATIVE))
private enum class DirectionMode {
CREATIVE, SOURCE
}
private var prevThirdPersonViewSetting = -1
var cameraGuy: EntityPlayer? = null; private set
@ -209,9 +214,16 @@ object Freecam : Module() {
val yawRad = Math.toRadians(rotationYaw - RotationUtils.getRotationFromVec(Vec3d(moveStrafing.toDouble(), 0.0, moveForward.toDouble())).x)
val speed = (horizontalSpeed.value / 20f) * min(abs(moveForward) + abs(moveStrafing), 1f)
motionX = -sin(yawRad) * speed
motionY = moveVertical.toDouble() * (verticalSpeed.value / 20f)
motionZ = cos(yawRad) * speed
if (directionMode.value == DirectionMode.SOURCE) {
val pitchRad = Math.toRadians(rotationPitch.toDouble()) * moveForward
motionX = -sin(yawRad) * cos(pitchRad) * speed
motionY = -sin(pitchRad) * speed
motionZ = cos(yawRad) * cos(pitchRad) * speed
} else {
motionX = -sin(yawRad) * speed
motionY = moveVertical.toDouble() * (verticalSpeed.value / 20f)
motionZ = cos(yawRad) * speed
}
if (isSprinting) {
motionX *= 1.5