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

Commit

Permalink
implementation of new rotations
Browse files Browse the repository at this point in the history
implemented the new rotations in mobkiller, genericbosskiller, revenant and pathexecutor. all done thanks to osama and his help
  • Loading branch information
MqsterMorro committed Apr 8, 2024
1 parent 13585aa commit 415db85
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestCommand {
private fun rotate(lock: Boolean = false) {
if (rotationTargetBlock == null) return
if(!AutoRotation.getInstance().enabled) {
AutoRotation.getInstance().easeTo(Target(rotationTargetBlock!!), 500, if (lock) LockType.INSTANT else LockType.NONE)
AutoRotation.getInstance().easeTo(Target(rotationTargetBlock!!), 500, if (lock) LockType.SMOOTH else LockType.NONE, false, 400)
}else{
AutoRotation.getInstance().disable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,30 @@ class SwiftSlayerConfig : Config(Mod("SwiftSlayer", ModType.SKYBLOCK), "swiftsla
return (macroGuiDelay + Math.random().toFloat() * macroGuiDelayRandomness).toLong()
}

@Slider(
name = "Rotation time",
category = "General",
subcategory = "Rotation delays",
description = "The time for rotations",
min = 200f,
max = 500f
)
var macroRotationTime: Float = 250f

@Slider(
name = "Rotation time randomness",
category = "General",
subcategory = "Rotation delays",
description = "Additional randomness ADDED to the rotation time",
min = 300f,
max = 700f
)
var macroRotationTimeRandomness: Float = 350f

fun getRandomRotationTime(): Long {
return (macroRotationTime + Math.random().toFloat() * macroRotationTimeRandomness).toLong()
}

init {
initialize()
registerKeyBind(toggleMacro) { macroManager.toggle() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AutoRotation: AbstractFeature() {

private var lockType: LockType = LockType.NONE
private var smoothLockTime = 0
private var isOverriden = false

companion object{
private var instance: AutoRotation? = null
Expand All @@ -34,7 +35,9 @@ class AutoRotation: AbstractFeature() {
}
}

fun easeTo(target: Target, time: Int, lockType: LockType = LockType.NONE, smoothLockTime: Int = 200, easeFunction: (Float) -> Float = EaseUtil.easingFunctions.random()){
fun easeTo(target: Target, time: Int, lockType: LockType = LockType.NONE, override: Boolean, smoothLockTime: Int = 200, easeFunction: (Float) -> Float = EaseUtil.easingFunctions.random()){
if(AutoRotation.getInstance().isOverriden) return;
AutoRotation.getInstance().isOverriden = override;
this.enabled = true
this.forceEnable = true
this.lockType = lockType
Expand Down Expand Up @@ -74,7 +77,7 @@ class AutoRotation: AbstractFeature() {
enabled = false
forceEnable = false
easeFunction = null

isOverriden = false
startAngle = null
target = null

Expand Down Expand Up @@ -107,7 +110,7 @@ class AutoRotation: AbstractFeature() {
player.rotationYaw += angChange.yaw
player.rotationPitch += angChange.pitch
} else {
this.easeTo(this.target!!, 200, LockType.SMOOTH, this.smoothLockTime)
this.easeTo(this.target!!, 200, LockType.SMOOTH, false, this.smoothLockTime)
}
}
}
Expand Down
26 changes: 11 additions & 15 deletions src/main/kotlin/dev/macrohq/swiftslayer/macro/GenericBossKiller.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package dev.macrohq.swiftslayer.macro

import dev.macrohq.swiftslayer.util.InventoryUtil
import dev.macrohq.swiftslayer.util.KeyBindUtil
import dev.macrohq.swiftslayer.util.Logger
import dev.macrohq.swiftslayer.util.PathingUtil
import dev.macrohq.swiftslayer.util.RotationUtil
import dev.macrohq.swiftslayer.util.SlayerUtil
import dev.macrohq.swiftslayer.util.config
import dev.macrohq.swiftslayer.util.getStandingOnCeil
import dev.macrohq.swiftslayer.util.player
import dev.macrohq.swiftslayer.util.world
import dev.macrohq.swiftslayer.feature.helper.Target
import dev.macrohq.swiftslayer.feature.helper.Angle
import dev.macrohq.swiftslayer.feature.implementation.AutoRotation
import dev.macrohq.swiftslayer.feature.implementation.LockType
import dev.macrohq.swiftslayer.util.*
import net.minecraft.entity.EntityLiving
import net.minecraft.init.Blocks
import net.minecraft.util.BlockPos
Expand All @@ -33,7 +28,7 @@ class GenericBossKiller {
return
}

RotationUtil.lock(target!!, 850, true)
AutoRotation.getInstance().easeTo(Target(target!!), 700, LockType.INSTANT, true)

var y = target!!.getStandingOnCeil().y
while (world.getBlockState(BlockPos(target!!.posX, y.toDouble(), target!!.posZ)).block == Blocks.air) {
Expand All @@ -58,16 +53,17 @@ class GenericBossKiller {
// macroManager.disable()
return
}
RotationUtil.stop()
RotationUtil.ease(RotationUtil.Rotation(player.rotationYaw, 90f), 350, true)
AutoRotation.getInstance().disable()
//RotationUtil.ease(RotationUtil.Rotation(player.rotationYaw, 90f), 350, true)
AutoRotation.getInstance().easeTo(Target(Angle(player.rotationYaw, 90f)), 500, LockType.NONE, true)
KeyBindUtil.rightClick(8)
}
}

fun enable() {
if (enabled) return
Logger.info("Enabling GenericBossKiller")
RotationUtil.stop()
AutoRotation.getInstance().disable()
PathingUtil.stop()
target = null
enabled = true
Expand All @@ -77,7 +73,7 @@ class GenericBossKiller {
if (!enabled) return
Logger.info("Disabling GenericBossKiller")
enabled = false
RotationUtil.stop()
AutoRotation.getInstance().disable()
PathingUtil.stop()
KeyBindUtil.stopClicking()
}
Expand Down
39 changes: 22 additions & 17 deletions src/main/kotlin/dev/macrohq/swiftslayer/macro/MobKiller.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package dev.macrohq.swiftslayer.macro

import dev.macrohq.swiftslayer.SwiftSlayer
import dev.macrohq.swiftslayer.feature.helper.Angle
import dev.macrohq.swiftslayer.feature.helper.Target
import dev.macrohq.swiftslayer.feature.implementation.AutoRotation
import dev.macrohq.swiftslayer.feature.implementation.LockType
import dev.macrohq.swiftslayer.util.AngleUtil
import dev.macrohq.swiftslayer.util.EntityUtil
import dev.macrohq.swiftslayer.util.InventoryUtil
import dev.macrohq.swiftslayer.util.KeyBindUtil
import dev.macrohq.swiftslayer.util.Logger
import dev.macrohq.swiftslayer.util.PathingUtil
import dev.macrohq.swiftslayer.util.RenderUtil
import dev.macrohq.swiftslayer.util.RotationUtil
import dev.macrohq.swiftslayer.util.SlayerUtil
import dev.macrohq.swiftslayer.util.Timer
import dev.macrohq.swiftslayer.util.config
Expand All @@ -31,7 +35,7 @@ class MobKiller {
private var stuckTimer = Timer(Long.MAX_VALUE)
private var lookTimer = Timer(Long.MAX_VALUE)
private var fireVeilTimer = Timer(Long.MAX_VALUE)
private lateinit var angle: RotationUtil.Rotation
private lateinit var angle: Target

@SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
Expand Down Expand Up @@ -78,7 +82,7 @@ class MobKiller {
}

State.LOOK_AT_TARGET -> {
RotationUtil.stop()
AutoRotation.getInstance().disable()
lookAtEntity(targetEntity!!)
lookTimer = Timer(1500)
}
Expand All @@ -89,12 +93,12 @@ class MobKiller {
lookTimer = Timer(Long.MAX_VALUE)
state = State.CHOOSE_TARGET
blacklist.add(targetEntity!!)
RotationUtil.stop()
AutoRotation.getInstance().disable()
return
}
if (lookDone()) {
lookTimer = Timer(Long.MAX_VALUE)
RotationUtil.stop()
AutoRotation.getInstance().disable()
holdWeapon()
} else {
return
Expand Down Expand Up @@ -123,25 +127,26 @@ class MobKiller {
Logger.info("Disabling MobKiller.")
enabled = false
PathingUtil.stop()
RotationUtil.stop()
AutoRotation.getInstance().disable()
}

private fun lookAtEntity(entity: EntityLiving) {
angle = angleForWeapon(entity)
angle = Target(angleForWeapon(entity))
when (config.mobKillerWeapon) {
0 -> RotationUtil.ease(angle, 200, true)
1 -> RotationUtil.ease(angle, 200, true)

0 -> AutoRotation.getInstance().easeTo(angle, SwiftSlayer.instance.config.getRandomRotationTime().toInt(), LockType.NONE, true)
1 -> AutoRotation.getInstance().easeTo(angle, SwiftSlayer.instance.config.getRandomRotationTime().toInt(), LockType.NONE, true )
2 -> {}
3 -> RotationUtil.ease(angle, 200, true);
3 -> AutoRotation.getInstance().easeTo(angle, SwiftSlayer.instance.config.getRandomRotationTime().toInt(), LockType.NONE, true)
}
}

private fun angleForWeapon(entity: EntityLiving): RotationUtil.Rotation {
private fun angleForWeapon(entity: EntityLiving): Angle {
return when (config.mobKillerWeapon) {
0 -> RotationUtil.Rotation(AngleUtil.getAngles(targetEntity!!).yaw, 45f)
1 -> AngleUtil.getAngles(entity.positionVector.addVector(0.0, 0.8, 0.0))
3 -> AngleUtil.getAngles(entity.positionVector.addVector(0.0, 0.8, 0.0));
else -> RotationUtil.Rotation(0f, 0f)
0 -> AngleUtil.getAngle(entity.positionVector.addVector(0.0, 0.8, 0.0));
1 -> AngleUtil.getAngle(entity.positionVector.addVector(0.0, 0.8, 0.0))
3 -> AngleUtil.getAngle(entity.positionVector.addVector(0.0, 0.8, 0.0));
else -> Angle(0f,0f)
}
}

Expand Down Expand Up @@ -190,8 +195,8 @@ class MobKiller {
}

private fun lookDone(): Boolean {
val yawDiff = abs(AngleUtil.yawTo360(player.rotationYaw) - AngleUtil.yawTo360(angle.yaw))
val pitchDiff = abs(mc.thePlayer.rotationPitch - angle.pitch)
val yawDiff = abs(AngleUtil.yawTo360(player.rotationYaw) - AngleUtil.yawTo360(angle.getAngle().yaw))
val pitchDiff = abs(mc.thePlayer.rotationPitch - angle.getAngle().pitch)
return when (config.mobKillerWeapon) {
0 -> pitchDiff < 2
1 -> yawDiff < 10 && pitchDiff < 5
Expand Down
18 changes: 8 additions & 10 deletions src/main/kotlin/dev/macrohq/swiftslayer/macro/Revenant.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package dev.macrohq.swiftslayer.macro

import dev.macrohq.swiftslayer.util.KeyBindUtil
import dev.macrohq.swiftslayer.feature.implementation.AutoRotation
import dev.macrohq.swiftslayer.util.Logger.info
import dev.macrohq.swiftslayer.util.PathingUtil
import dev.macrohq.swiftslayer.util.RenderUtil
import dev.macrohq.swiftslayer.util.RotationUtil
import dev.macrohq.swiftslayer.util.config
import dev.macrohq.swiftslayer.util.mobKiller
import dev.macrohq.swiftslayer.util.player
import dev.macrohq.swiftslayer.util.world
import dev.macrohq.swiftslayer.feature.helper.Angle
import dev.macrohq.swiftslayer.feature.implementation.LockType
import dev.macrohq.swiftslayer.feature.helper.Target
import dev.macrohq.swiftslayer.util.*

import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.entity.monster.EntityZombie
Expand Down Expand Up @@ -76,8 +74,8 @@ class Revenant {
}
State.LOOKING -> {
info("looking")
if (config.bossKillerWeapon == 1) RotationUtil.ease(RotationUtil.Rotation(player.rotationYaw, 90f), 200)
else RotationUtil.lock(mob!!, 200, true)
if (config.bossKillerWeapon == 1) AutoRotation.getInstance().easeTo(Target(Angle(player.rotationYaw, 90f)), 300, LockType.NONE, true)
else AutoRotation.getInstance().easeTo(Target(AngleUtil.getAngle(mob!!)), 500, LockType.NONE, true)
state = State.KILLING
}
State.KILLING -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package dev.macrohq.swiftslayer.pathfinding

import dev.macrohq.swiftslayer.feature.helper.Angle
import dev.macrohq.swiftslayer.feature.implementation.AutoRotation
import dev.macrohq.swiftslayer.feature.implementation.LockType
import dev.macrohq.swiftslayer.util.AngleUtil
import dev.macrohq.swiftslayer.feature.helper.Target
import dev.macrohq.swiftslayer.util.InventoryUtil
import dev.macrohq.swiftslayer.util.KeyBindUtil
import dev.macrohq.swiftslayer.util.Logger
Expand Down Expand Up @@ -54,7 +58,8 @@ class PathExecutor {

if (isOnPath()) {
next = path[path.indexOf(getStandingOn()!!) + 1]
RotationUtil.ease(RotationUtil.Rotation(AngleUtil.getAngles(next!!.toVec3Top()).yaw, 20f), 500)
// RotationUtil.ease(RotationUtil.Rotation(AngleUtil.getAngles(next!!.toVec3Top()).yaw, 20f), 500)
AutoRotation.getInstance().easeTo(Target(Angle(AngleUtil.getAngle(next!!.toVec3Top()).yaw, 20f)), 300, LockType.NONE, false)
RenderUtil.markers.clear()
RenderUtil.markers.add(next!!)
}
Expand All @@ -76,7 +81,8 @@ class PathExecutor {
aotving = false
}

val rotation = RotationUtil.Rotation(AngleUtil.getAngles(next!!.toVec3Top()).yaw, 20f)
// val rotation = RotationUtil.Rotation(AngleUtil.getAngles(next!!.toVec3Top()).yaw, 20f)
val rotation = Angle(AngleUtil.getAngle(next!!.toVec3Top()).yaw, 20f)
directionYaw = rotation.yaw
gameSettings.keyBindSprint.setPressed(AngleUtil.yawTo360(player.rotationYaw) in AngleUtil.yawTo360(player.rotationYaw) - 45..AngleUtil.yawTo360(player.rotationYaw) + 45)
gameSettings.keyBindForward.setPressed(true)
Expand Down

0 comments on commit 415db85

Please sign in to comment.