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

Commit

Permalink
eman boss killing almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJuri committed Sep 4, 2023
1 parent b7146c0 commit 76c9a27
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
23 changes: 21 additions & 2 deletions src/main/kotlin/dev/macrohq/swiftslayer/macro/EndermanMacro.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package dev.macrohq.swiftslayer.macro

import cc.polyfrost.oneconfig.utils.dsl.runAsync
import dev.macrohq.swiftslayer.util.*
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.entity.monster.EntityZombie
import net.minecraft.util.Vec3
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
import java.security.Key

class EndermanMacro {

Expand All @@ -18,10 +22,25 @@ class EndermanMacro {
if(!enabled) return
when(state) {
State.HIT -> {
if(determineState() != State.HIT) state = State.DAMAGE
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, true)
if(player.getDistanceSqToEntity(target) > 3.0) gameSettings.keyBindForward.setPressed(true) else gameSettings.keyBindForward.setPressed(false)
runAsync {
while(state == State.DAMAGE) {
gameSettings.keyBindSneak.setPressed(true)
Thread.sleep(100)
KeyBindUtil.leftClick()
gameSettings.keyBindSneak.setPressed(false)
}
}
}

State.DAMAGE -> TODO()
State.LASER -> TODO()
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/kotlin/dev/macrohq/swiftslayer/util/InventoryUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package dev.macrohq.swiftslayer.util

object InventoryUtil {

fun holdItem(name: String): Boolean{
if(getSlotFromName(name)<9){
player.inventory.currentItem = getSlotFromName(name)
fun holdItem(name: String): Boolean {
if (getSlotForItem(name) < 9) {
player.inventory.currentItem = getSlotForItem(name)
return true
}
return false
}
private fun getSlotFromName(name: String): Int{

fun getSlotForItem(name: String): Int {
val inventory = player.inventory
for(i in 0..8){
for (i in 0..8) {
val currItem = inventory.getStackInSlot(i)
if(currItem!=null && currItem.displayName.contains(name, true)) return i
if (currItem != null && currItem.displayName.contains(name, true)) return i
}
return 100
}
Expand Down
28 changes: 26 additions & 2 deletions src/main/kotlin/dev/macrohq/swiftslayer/util/KeyBindUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ package dev.macrohq.swiftslayer.util
import dev.macrohq.swiftslayer.mixin.MinecraftInvoker

object KeyBindUtil {
fun leftClick() { (mc as MinecraftInvoker).invokeClickMouse() }
fun rightClick() { (mc as MinecraftInvoker).invokeRightClickMouse() }

private var cpsReset = 0L
private var leftCps = 0
private var rightCps = 0

fun leftClick() {
if(System.currentTimeMillis() - cpsReset > 1000) {
cpsReset = System.currentTimeMillis()
leftCps = 0
rightCps = 0
}
if(leftCps > 12) return
(mc as MinecraftInvoker).invokeClickMouse()
leftCps++
}

fun rightClick() {
if(System.currentTimeMillis() - cpsReset > 1000) {
cpsReset = System.currentTimeMillis()
leftCps = 0
rightCps = 0
}
if(rightCps > 12) return
(mc as MinecraftInvoker).invokeRightClickMouse()
rightCps++
}
}
17 changes: 6 additions & 11 deletions src/main/kotlin/dev/macrohq/swiftslayer/util/RotationUtil.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.macrohq.swiftslayer.util

import cc.polyfrost.oneconfig.utils.dsl.runAsync
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLiving
import net.minecraft.util.MathHelper
import kotlin.math.pow
Expand All @@ -11,18 +12,18 @@ object RotationUtil {
private var startTime = 0L
private var endTime = 0L
private var done = true
private lateinit var entity: EntityLiving
private lateinit var entity: Entity
private var lockAim = false

fun easeToEntity(entity: EntityLiving, durationMillis: Long, aimLock: Boolean = false) {
fun easeToEntity(entity: Entity, durationMillis: Long, aimLock: Boolean = false) {
if (!done) return
done = false
this.entity = entity
this.lockAim = aimLock

startRotation = Rotation(player.rotationYaw, player.rotationPitch)
val rotation = AngleUtil.getAngles(entity.positionVector)
val neededChange = getNeededChange(startRotation, rotation)
val neededChange = AngleUtil.getNeededChange(startRotation, rotation)
endRotation = Rotation(startRotation.yaw + neededChange.yaw, startRotation.pitch + neededChange.pitch)
startTime = System.currentTimeMillis()
endTime = startTime + durationMillis
Expand All @@ -32,7 +33,7 @@ object RotationUtil {
// if (!done) return
done = false
startRotation = Rotation(player.rotationYaw, player.rotationPitch)
val neededChange = getNeededChange(startRotation, rotation)
val neededChange = AngleUtil.getNeededChange(startRotation, rotation)
endRotation = Rotation(startRotation.yaw + neededChange.yaw, startRotation.pitch + neededChange.pitch)
startTime = System.currentTimeMillis()
endTime = startTime + durationMillis
Expand All @@ -49,7 +50,7 @@ object RotationUtil {
endTime = startTime + durationMillis
}

private fun lock(entity: EntityLiving) {
private fun lock(entity: Entity) {
runAsync {
while(lockAim) {
if(entity.isDead) break
Expand Down Expand Up @@ -84,12 +85,6 @@ object RotationUtil {
return (1.0 - (1.0 - number).pow(3.0)).toFloat()
}

private fun getNeededChange(startRot: Rotation, endRot: Rotation): Rotation {
var yawChange = MathHelper.wrapAngleTo180_float(endRot.yaw) - MathHelper.wrapAngleTo180_float(startRot.yaw)
if (yawChange <= -180.0f) yawChange += 360.0f else if (yawChange > 180.0f) yawChange += -360.0f
return Rotation(yawChange, endRot.pitch - startRot.pitch)
}

fun stop(){
lockAim = false
done = true
Expand Down

0 comments on commit 76c9a27

Please sign in to comment.