class SpookyTime : AngleMode("SpookyTime") {
private val fastRandom = FastRandom()
private fun lerpAngle(start: Float, end: Float, t: Float): Float {
var delta = MathHelper.wrapDegrees(end - start)
return start + delta * t
}
override fun limitAngleChange(
currentAngle: Angle,
targetAngle: Angle,
vec3d: Vec3d?,
entity: Entity?
): Angle {
val angleDelta = AngleUtil.calculateDelta(currentAngle, targetAngle)
val yawDelta = angleDelta.yaw
val pitchDelta = angleDelta.pitch
val rotationDifference = hypot(abs(yawDelta.toDouble()), abs(pitchDelta.toDouble())).toFloat()
val isLookingAtTarget = entity is LivingEntity &&
AngleUtil.isAngleLookingAtEntity(entity, currentAngle, 6.0f)
val distanceFactor = if (entity != null) {
max(min(mc.player!!.distanceTo(entity) / 2f, 1.0f), 0.1f)
} else 0.5f
val lineYaw = (abs(yawDelta / rotationDifference) * 90f) * distanceFactor
val linePitch = (abs(pitchDelta / rotationDifference) * 90f) * distanceFactor
val moveYaw = MathHelper.clamp(yawDelta, -lineYaw, lineYaw)
val movePitch = MathHelper.clamp(pitchDelta, -linePitch, linePitch)
val lerpFactor = if (isLookingAtTarget) {
0.6f + fastRandom.nextFloat(0f, 0.1f)
} else 1.0f
val pitchFactor = 0.6f + fastRandom.nextFloat(0f, 0.1f)
val newYaw = lerpAngle(currentAngle.yaw, currentAngle.yaw + moveYaw, lerpFactor)
val newPitch = MathHelper.lerp(pitchFactor, currentAngle.pitch, currentAngle.pitch + movePitch)
return Angle(newYaw, newPitch)
}
override fun limitAngleChangeReturn(
currentAngle: Angle,
targetAngle: Angle,
vec3d: Vec3d?,
entity: Entity?
): Angle {
val currentYaw = currentAngle.yaw
val currentPitch = currentAngle.pitch
val targetYaw = targetAngle.yaw
val targetPitch = targetAngle.pitch
val yawLerp = 0.7f + fastRandom.nextFloat(0f, 0.1f)
val pitchLerp = 0.6f + fastRandom.nextFloat(0f, 0.1f)
val interpolatedYaw = lerpAngle(currentYaw, targetYaw, yawLerp)
val interpolatedPitch = MathHelper.lerp(pitchLerp, currentPitch, targetPitch)
var yawDelta = MathHelper.wrapDegrees(interpolatedYaw - currentYaw)
var pitchDelta = interpolatedPitch - currentPitch
yawDelta = MathHelper.clamp(yawDelta, -40.0f, 55.0f)
pitchDelta = MathHelper.clamp(pitchDelta, -25.0f, 30.0f)
val newYaw = currentYaw + yawDelta
var newPitch = currentPitch + pitchDelta
newPitch = MathHelper.clamp(newPitch, -89.0f, 89.0f)
return Angle(newYaw, newPitch)
}
override fun randomValue(): Vec3d {
return Vec3d(0.08, 0.01, 0.02)
}
}