Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
updatged rotation util
Browse files Browse the repository at this point in the history
Signed-off-by: TomJuri <[email protected]>
  • Loading branch information
TomJuri committed Sep 10, 2023
1 parent 61d22ba commit d6a5d5e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class EndermanBossKiller {
}
when(state) {
State.HIT -> {
RotationUtil.easeToEntity(target, 250, aimLock = true, true)
RotationUtil.lock(target, 250, true)
if(player.getDistanceSqToEntity(target) < 10.0) gameSettings.keyBindBack.setPressed(true) else gameSettings.keyBindBack.setPressed(false)
if(player.worldObj.loadedEntityList.filterIsInstance<EntityZombie>().any { it.getDistanceSqToEntity(target) > 4.0 }) return
InventoryUtil.holdItem("Reaper Scythe")
KeyBindUtil.rightClick()
}

State.DAMAGE -> {
RotationUtil.easeToEntity(target, 250, aimLock = true, true)
RotationUtil.lock(target, 250, true)
if(player.getDistanceSqToEntity(target) > 3.0) gameSettings.keyBindForward.setPressed(true) else gameSettings.keyBindForward.setPressed(false)
if (timer.isDone) {
gameSettings.keyBindSneak.setPressed(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GenericBossKiller {
}
if (!hasRotated) {
if (config.bossKillerWeapon == 1) {
RotationUtil.easeToEntity(target, 500, aimLock = true, true)
RotationUtil.lock(target, 500, true)
} else {
RotationUtil.ease(RotationUtil.Rotation(player.rotationYaw, 90f), 500)
}
Expand Down
64 changes: 27 additions & 37 deletions src/main/kotlin/dev/macrohq/swiftslayer/util/RotationUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,7 @@ object RotationUtil {
private var startTime = 0L
private var endTime = 0L
private var done = true

private lateinit var entity: Entity
private var lockAim = false
private var eyes = false

fun easeToEntity(entity: Entity, durationMillis: Long, aimLock: Boolean = false, eyes: Boolean) {
if (!done) return
done = false
this.entity = entity
this.lockAim = aimLock
this.eyes = eyes
startRotation = Rotation(player.rotationYaw, player.rotationPitch)
val rotation = AngleUtil.getAngles(entity.positionVector)
val neededChange = AngleUtil.getNeededChange(startRotation, rotation)
endRotation = Rotation(startRotation.yaw + neededChange.yaw, startRotation.pitch + neededChange.pitch)
startTime = System.currentTimeMillis()
endTime = startTime + durationMillis
}
private var lock: Pair<Entity, Double>? = null

fun ease(rotation: Rotation, durationMillis: Long) {
done = false
Expand All @@ -38,22 +21,18 @@ object RotationUtil {
endTime = startTime + durationMillis
}

private fun lock(entity: Entity, eyes: Boolean) {
runAsync {
while(lockAim) {
if(entity.isDead) break
val rotation = AngleUtil.getAngles(
entity.positionVector.addVector(
0.0,
if (eyes) entity.eyeHeight.toDouble() else 0.0,
0.0
)
fun lock(entity: Entity, durationMillis: Long, eyes: Boolean) {
done = false
ease(
AngleUtil.getAngles(
entity.positionVector.addVector(
0.0,
if (eyes) entity.eyeHeight.toDouble() else 0.0,
0.0
)
player.rotationYaw = rotation.yaw
player.rotationPitch = rotation.pitch
}
stop()
}
), durationMillis
)
lock = Pair(entity, if (eyes) entity.eyeHeight.toDouble() else 0.0)
}

fun onRenderWorldLast() {
Expand All @@ -65,8 +44,19 @@ object RotationUtil {
}
player.rotationYaw = endRotation.yaw
player.rotationPitch = endRotation.pitch
done = true
if (lockAim) lock(entity, eyes)
if (lock != null) {
runAsync {
while (lock != null) {
if (lock!!.first.isDead) break
val rotation = AngleUtil.getAngles(lock!!.first.positionVector.addVector(0.0, lock!!.second, 0.0))
player.rotationYaw = rotation.yaw
player.rotationPitch = rotation.pitch
}
stop()
}
} else {
stop()
}
}

private fun interpolate(start: Float, end: Float): Float {
Expand All @@ -79,9 +69,9 @@ object RotationUtil {
return (1.0 - (1.0 - number).pow(3.0)).toFloat()
}

fun stop(){
lockAim = false
fun stop() {
done = true
lock = null
}

data class Rotation(val yaw: Float, val pitch: Float)
Expand Down

0 comments on commit d6a5d5e

Please sign in to comment.