diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/command/DequeCommand.kt b/src/main/kotlin/dev/macrohq/swiftslayer/command/DequeCommand.kt index e69de29..950e63f 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/command/DequeCommand.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/command/DequeCommand.kt @@ -0,0 +1,15 @@ +package dev.macrohq.swiftslayer.command; + +import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; +import dev.macrohq.swiftslayer.util.LockRotationUtil; + + +@Command("deque") +public class DequeCommand{ + + @SubCommand + public fun pri() { + System.out.println(LockRotationUtil.getInstance().lastYaws.toString()); + } +} diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/command/DirectionTest.kt b/src/main/kotlin/dev/macrohq/swiftslayer/command/DirectionTest.kt index 04fb2bc..2b1fdc4 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/command/DirectionTest.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/command/DirectionTest.kt @@ -2,7 +2,9 @@ package dev.macrohq.swiftslayer.command import cc.polyfrost.oneconfig.utils.commands.annotations.Command import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand -import dev.macrohq.swiftslayer.util.* +import dev.macrohq.swiftslayer.util.BlockUtil +import dev.macrohq.swiftslayer.util.PathingUtil +import dev.macrohq.swiftslayer.util.RenderUtil import net.minecraft.client.Minecraft import net.minecraft.util.BlockPos import net.minecraftforge.client.event.RenderWorldLastEvent @@ -13,15 +15,17 @@ import java.awt.Color class DirectionTest { - var mc: Minecraft = Minecraft.getMinecraft() @SubCommand private fun direction(lock: Boolean) { //gameSettings.keyBindSneak.setPressed(true) - blockPos = BlockUtil.getBlocks( SlayerUtil.getFakeBoss()!!.position.add(0, -1, 0), 2, 1, 2)[0] + enabled = lock - PathingUtil.goto(blockPos.add(0, -1, 0)) + if(blockPoss.isNotEmpty()) { + PathingUtil.goto(blockPoss[0]) + } + } @@ -29,20 +33,60 @@ class DirectionTest { fun onWorldRender(event: RenderWorldLastEvent) { if(enabled) { - // RenderUtil.drawBox(event, BlockUtil.getCornerBlocks(SlayerUtil.getFakeBoss()!!.position, 2, 1, 2).first, Color.GREEN, true) + // RenderUtil.drawBox(event, BlockUtil.getCornerBlocks(SlayerUtil.getFakeBoss()!!.position, 2, 1, 2).first, Color.GREEN, true) // RenderUtil.drawBox(event, BlockUtil.getCornerBlocks(SlayerUtil.getFakeBoss()!!.position, 2, 1, 2).second, Color.GREEN, true) - if(BlockUtil.getBlocks( SlayerUtil.getFakeBoss()!!.position.add(0, -1, 0), 2, 1, 2).isEmpty().not()) - for(block: BlockPos in BlockUtil.getBlocks( SlayerUtil.getFakeBoss()!!.position.add(0, -1, 0), 2, 1, 2)) { + + // draw all columns that are higher than 4 blocks + /* if(BlockUtil.getColumns( mc.thePlayer.position.add(0, -1, 0), 4, 5, 4, 4).isEmpty().not()) { + for(block: BlockPos in BlockUtil.getColumns( mc.thePlayer.position.add(0, -1, 0), 4, 5, 4, 4)) { RenderUtil.drawBox(event, block, Color.RED, true) + + + } + */ + + // check if there are more than 2 columns higher than 4 blocks + /* if(BlockUtil.getColumns( mc.thePlayer.position.add(0, -1, 0), 4, 5, 4, 4).size >= 2) { + // get all the columns higher than 4 blocks and put in arrayList + var cornerBlocks = BlockUtil.getColumns( mc.thePlayer.position.add(0, -1, 0), 4, 5, 4, 4) + // this is where things go wrong ig + BlockUtil.getAllCornerBlocks(cornerBlocks) + for (blockPos: BlockPos in BlockUtil.getAllCornerBlocks(cornerBlocks)) + RenderUtil.drawBox(event, blockPos, Color.BLUE, true) + } else { + println("nah") + } + } + + */ + blockPoss.clear() + if (BlockUtil.getBlocks(mc.thePlayer.position, 15, 4, 15).isEmpty()) return + + for(block: BlockPos in BlockUtil.getBlocks(mc.thePlayer.position, 15, 5, 15)) { + if(BlockUtil.isSingleCorner(block)) { + if(BlockUtil.blocksBetweenValid(block,mc.thePlayer.position.add(0, 0, 0))) { + RenderUtil.drawBox(event, block, Color.BLUE, true) + blockPoss.add(block) + } + + } - } + } + /* GenericBossKiller.blockPoss = BlockUtil.getBlocks(dev.macrohq.swiftslayer.util.mc.thePlayer.position, 5, 5, 5) as ArrayList + + for (blockk: BlockPos in GenericBossKiller.blockPoss) { + // if(BlockUtil.blocksBetweenValid(player.position.add(0, 0, 0), blockk.add(0, 0, 0))) { + RenderUtil.drawBox(event, blockk, Color.WHITE, true) + } */ + // } + } } companion object { var enabled: Boolean = false - lateinit var blockPos: BlockPos + var blockPoss: ArrayList = ArrayList() } } \ No newline at end of file diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/command/LockTest.kt b/src/main/kotlin/dev/macrohq/swiftslayer/command/LockTest.kt index dbbff25..5c6fee6 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/command/LockTest.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/command/LockTest.kt @@ -3,13 +3,10 @@ package dev.macrohq.swiftslayer.command import cc.polyfrost.oneconfig.utils.commands.annotations.Command import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand import dev.macrohq.swiftslayer.SwiftSlayer -import dev.macrohq.swiftslayer.feature.implementation.AutoRotation import dev.macrohq.swiftslayer.util.RotationMath import dev.macrohq.swiftslayer.util.SlayerUtil +import net.minecraft.client.Minecraft import net.minecraft.entity.EntityLiving -import net.minecraft.util.AxisAlignedBB -import net.minecraft.util.BlockPos -import net.minecraftforge.fml.common.Mod.EventHandler import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent @@ -23,7 +20,6 @@ class LockTest { private fun rotate(lock: Boolean) { rotationTargetEntity = SlayerUtil.getFakeBoss()!! enabled = lock - println("error or sokmething") println(enabled) } @@ -32,13 +28,16 @@ class LockTest { if (enabled) { + rotationTargetEntity = SlayerUtil.getFakeBoss()!! - val boundingBox: AxisAlignedBB = rotationTargetEntity.entityBoundingBox - val deltaX = boundingBox.maxX - boundingBox.minX - val deltaY = boundingBox.maxY - boundingBox.minY - val deltaZ = boundingBox.maxZ - boundingBox.minZ + + if(rotationTargetEntity.isDead) enabled = false; + val randomPositionOnBoundingBox = - BlockPos(boundingBox.minX + deltaX , boundingBox.minY + deltaY, boundingBox.minZ + deltaZ) + rotationTargetEntity.position.add(0, (rotationTargetEntity.height*0.75).toInt(), 0) + + if (Minecraft.getMinecraft().objectMouseOver.entityHit == rotationTargetEntity) return + SwiftSlayer.instance.rotation.setYaw(RotationMath.getYaw(randomPositionOnBoundingBox), SwiftSlayer.instance.config.macroLockSmoothness.toInt(), true) SwiftSlayer.instance.rotation.setPitch(RotationMath.getPitch(randomPositionOnBoundingBox), SwiftSlayer.instance.config.macroLockSmoothness.toInt(), true) diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/config/SwiftSlayerConfig.kt b/src/main/kotlin/dev/macrohq/swiftslayer/config/SwiftSlayerConfig.kt index faaa64a..65c3e19 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/config/SwiftSlayerConfig.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/config/SwiftSlayerConfig.kt @@ -156,44 +156,6 @@ class SwiftSlayerConfig : Config(Mod("SwiftSlayer", ModType.SKYBLOCK), "swiftsla ) var macroGuiDelayRandomness: Float = 350f - - // ============================== - // Pathfinder Debug Config - // ============================== - @Switch( - name = "allowJump", - category = "PF" - ) - var allowJump = true - - - @Switch( - name = "holdSneak", - category = "PF" - ) - var holdSneak = true - - @Switch( - name = "allowDiagonalAscend", - category = "PF" - ) - var allowDiagonalAscend = true - - - @Switch( - name = "allowDiagonalDescend", - category = "PF" - ) - var allowDiagonalDescend = true - - @Slider( - name = "maxFallHeight", - category = "PF", - min = 1f, - max = 256f - ) - var maxFallHeight = 20 - fun getRandomGUIMacroDelay(): Long { return (macroGuiDelay + Math.random().toFloat() * macroGuiDelayRandomness).toLong() } @@ -231,7 +193,15 @@ class SwiftSlayerConfig : Config(Mod("SwiftSlayer", ModType.SKYBLOCK), "swiftsla max = 10f ) var macroLockSmoothness: Float = 4f - + + @Dropdown( + name = "BossKiller Movement", + category = "General", + subcategory = "Slayer", + options = ["Find corner", "Walk back"] + ) + var moveementType = 0 + init { initialize() registerKeyBind(toggleMacro) { macroManager.toggle() } diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/feature/Failsafe.kt b/src/main/kotlin/dev/macrohq/swiftslayer/feature/Failsafe.kt index ec0caeb..193b35d 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/feature/Failsafe.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/feature/Failsafe.kt @@ -24,7 +24,7 @@ class Failsafe { macroManager.disable() } -// @SubscribeEvent + @SubscribeEvent fun onItemChange(event: ReceivePacketEvent) { if (!macroManager.enabled) return if (event.packet !is S09PacketHeldItemChange) return diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/feature/helper/Angle.kt b/src/main/kotlin/dev/macrohq/swiftslayer/feature/helper/Angle.kt index f1dcb98..d9c4bb0 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/feature/helper/Angle.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/feature/helper/Angle.kt @@ -1,3 +1,3 @@ package dev.macrohq.swiftslayer.feature.helper -data class Angle(val yaw: Float, val pitch: Float) \ No newline at end of file +data class Angle(val yaw: Float, var pitch: Float) \ No newline at end of file diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/macro/GenericBossKiller.kt b/src/main/kotlin/dev/macrohq/swiftslayer/macro/GenericBossKiller.kt index d373424..b29d22e 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/macro/GenericBossKiller.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/macro/GenericBossKiller.kt @@ -4,16 +4,19 @@ 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.BossKillerMovement 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.AxisAlignedBB import net.minecraft.util.BlockPos +import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent -private var timeout = Timer(1000) +private var timeout = Timer(0) + class GenericBossKiller { @@ -34,13 +37,21 @@ class GenericBossKiller { disable() return } - + if(tickCounter > 20) { + tickCounter = 0 + } else { + tickCounter++ + } + println(ticksSinceLastMovement) + if(BossKillerMovement.getInstance().getDistanceBetweenBlocks(playerLastPos, mc.thePlayer.position) > 0.8) { + ticksSinceLastMovement = 0 + } else { + ticksSinceLastMovement++ + } //AutoRotation.getInstance().easeTo(Target(target!!), 700, LockType.INSTANT, true) val boundingBox: AxisAlignedBB = target!!.entityBoundingBox - val deltaX = boundingBox.maxX - boundingBox.minX - val deltaY = boundingBox.maxY - boundingBox.minY - val deltaZ = boundingBox.maxZ - boundingBox.minZ - val randomPositionOnBoundingBox = BlockPos(boundingBox.minX + deltaX, boundingBox.minY + deltaY, boundingBox.minZ + deltaZ) + + val randomPositionOnBoundingBox = target!!.position.add(0, (target!!.height*0.75).toInt(), 0) SwiftSlayer.instance.rotation.setYaw(RotationMath.getYaw(randomPositionOnBoundingBox), SwiftSlayer.instance.config.macroLockSmoothness.toInt(), true) SwiftSlayer.instance.rotation.setPitch(RotationMath.getPitch(randomPositionOnBoundingBox), SwiftSlayer.instance.config.macroLockSmoothness.toInt(), true) @@ -49,22 +60,75 @@ class GenericBossKiller { y-- } + + if( SwiftSlayer.instance.config.moveementType == 0 && blockPoss.isNotEmpty() && !inCorner) { + PathingUtil.goto(blockPoss[0]) + gameSettings.keyBindSneak.setPressed(true) + chosenCorner = blockPoss[0] + inCorner = true + } + + if( SwiftSlayer.instance.config.moveementType == 0 && inCorner) { + if(BossKillerMovement.getInstance().getDistanceBetweenBlocks(player.position, chosenCorner) > 2) { + PathingUtil.goto(chosenCorner) + } + } + + + if(SwiftSlayer.instance.config.moveementType == 1 && timeout.isDone) { + gameSettings.keyBindForward.setPressed(false) + + if(ticksSinceLastMovement > 100) { + gameSettings.keyBindSneak.setPressed(false) + gameSettings.keyBindBack.setPressed(false) + gameSettings.keyBindRight.setPressed(false) + timeout = Timer(1000) + + } + else if(tickCounter > 10) { + gameSettings.keyBindSneak.setPressed(true) + gameSettings.keyBindBack.setPressed(true) + gameSettings.keyBindRight.setPressed(true) + } else { + gameSettings.keyBindBack.setPressed(false) + gameSettings.keyBindRight.setPressed(false) + } + + + } else if(SwiftSlayer.instance.config.moveementType == 1 && !timeout.isDone){ + gameSettings.keyBindForward.setPressed(true) + if(SwiftSlayer.instance.rotation.canEnable()) SwiftSlayer.instance.rotation.disable() + + } + + + + + /* if (player.getDistanceToEntity(target!!) > 4.5) { PathingUtil.goto(BlockPos(target!!.posX, y.toDouble(), target!!.posZ)) } else { - // PathingUtil.stop() + // PathingUtil.stop() } + */ + + +/* if(player.getDistanceToEntity(target!!) < 4 && timeout.isDone) { - if(BlockUtil.getBlocks( target!!.position.add(0, -1, 0), 2, 1, 2).isEmpty().not()) - PathingUtil.goto(BlockUtil.getBlocks( target!!.position.add(0, -1, 0), 5, 2, 5)[0].add(0, -1, 0)) + if(BlockUtil.getBlocks( target!!.position.add(0, 0, 0), 4, 2, 4).isEmpty().not()) + PathingUtil.goto(BlockUtil.getBlocks( target!!.position.add(0, 0, 0), 5, 2, 5)[0].add(0, 0, 0)) timeout = Timer(1000) } + */ // Melee if (config.bossKillerWeapon == 0) { player.inventory.currentItem = config.meleeWeaponSlot - 1 - KeyBindUtil.leftClick(8) + if(mc.thePlayer.getDistanceToEntity(target!!) < 4) { + KeyBindUtil.leftClick(8) + } + // Hyperion } else if (config.bossKillerWeapon == 1) { @@ -78,8 +142,31 @@ class GenericBossKiller { AutoRotation.getInstance().easeTo(Target(Angle(player.rotationYaw, 90f)), 500, LockType.NONE, true) KeyBindUtil.rightClick(8) } + + playerLastPos = mc.thePlayer.position } + @SubscribeEvent + fun onWorld(event: RenderWorldLastEvent) { + if(!enabled) return + + blockPoss.clear() + if(BlockUtil.getBlocks(mc.thePlayer.position, 15, 4, 15).isEmpty()) return + + if(SwiftSlayer.instance.config.moveementType == 0) { + for(block: BlockPos in BlockUtil.getBlocks(mc.thePlayer.position, 15, 5, 15)) { + if(BlockUtil.isSingleCorner(block)) { + if(BlockUtil.blocksBetweenValid(block,mc.thePlayer.position.add(0, 0, 0))) { + blockPoss.add(block) + } + + } + + } + } + + + } fun enable() { if (enabled) return Logger.info("Enabling GenericBossKiller") @@ -87,6 +174,7 @@ class GenericBossKiller { PathingUtil.stop() target = null enabled = true + playerLastPos = mc.thePlayer.position } fun disable() { @@ -96,5 +184,23 @@ class GenericBossKiller { AutoRotation.getInstance().disable() PathingUtil.stop() KeyBindUtil.stopClicking() + SwiftSlayer.instance.rotation.disable() + blockPoss.clear() + inCorner = false + tryUnstuck = false + gameSettings.keyBindSneak.setPressed(false) + gameSettings.keyBindBack.setPressed(false) + gameSettings.keyBindRight.setPressed(false) + } + + companion object { + var blockPoss: ArrayList = ArrayList() + var inCorner: Boolean = false + lateinit var chosenCorner: BlockPos + var ticksSinceLastMovement: Int = 0 + var tryUnstuck: Boolean = false + lateinit var playerLastPos: BlockPos + var tickCounter: Int = 0 + } } \ No newline at end of file diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/macro/MobKiller.kt b/src/main/kotlin/dev/macrohq/swiftslayer/macro/MobKiller.kt index 3ed779b..4c4a662 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/macro/MobKiller.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/macro/MobKiller.kt @@ -5,20 +5,7 @@ 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.SlayerUtil -import dev.macrohq.swiftslayer.util.Timer -import dev.macrohq.swiftslayer.util.config -import dev.macrohq.swiftslayer.util.getStandingOnCeil -import dev.macrohq.swiftslayer.util.lastTickPositionCeil -import dev.macrohq.swiftslayer.util.mc -import dev.macrohq.swiftslayer.util.player +import dev.macrohq.swiftslayer.util.* import net.minecraft.entity.EntityLiving import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent @@ -143,9 +130,9 @@ class MobKiller { private fun angleForWeapon(entity: EntityLiving): Angle { return when (config.mobKillerWeapon) { - 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)); + 0 -> AngleUtil.getAngle(entity.position.add(0, (entity.height*0.75).toInt(), 0)); + 1 -> AngleUtil.getAngle(entity.position.add(0, (entity.height*0.75).toInt(), 0)) + 3 -> AngleUtil.getAngle(entity.position.add(0, (entity.height*0.75).toInt(), 0)); else -> Angle(0f,0f) } } diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/util/BlockUtil.kt b/src/main/kotlin/dev/macrohq/swiftslayer/util/BlockUtil.kt index e816f04..35bab24 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/util/BlockUtil.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/util/BlockUtil.kt @@ -1,8 +1,6 @@ package dev.macrohq.swiftslayer.util -import dev.macrohq.swiftslayer.feature.implementation.BossKillerMovement import dev.macrohq.swiftslayer.pathfinding.AStarPathfinder -import net.minecraft.block.Block import net.minecraft.block.BlockStairs import net.minecraft.block.material.Material import net.minecraft.entity.EntityLiving @@ -17,12 +15,11 @@ object BlockUtil { fun canWalkOnBlock(pos: BlockPos): Boolean { val block = world.getBlockState(pos.add(0, 0, 0)).block - val blockAbove = world.getBlockState(pos.up()).block // Get the block above + val blockAbove = world.getBlockState(pos.up()).block val material: Material = block.material val materialAbove: Material = blockAbove.material - // Check if both the block and the space above it are walkable return material.isSolid && !material.isLiquid && materialAbove == Material.air } @@ -45,26 +42,54 @@ object BlockUtil { fun getBlocks(centerPos: BlockPos, width: Int, height: Int, depth: Int, entity: EntityLiving? = null): MutableList { var pos2: BlockPos - val blocks = getBlocksBetweenCorners(getCornerBlocks(centerPos,width, height, depth).first,getCornerBlocks(centerPos,width, height, depth).second).asSequence() - .filter { canWalkOnBlock(it.add(0, -1, 0)) } - .filter { blocksBetweenValid(mc.thePlayer.position, it) } - .filter { BossKillerMovement.getInstance().getDistanceBetweenBlocks(it, mc.thePlayer.position) > 1} + val blocks = getBlocksBetweenCorners(getCornerBlocks(centerPos, width, height, depth).first,getCornerBlocks(centerPos, width, height, depth).second).asSequence() + .filter { canWalkOnBlock(it.add(0, 0, 0)) } + .filter { world.isBlockFullCube(it) } .toMutableList() - if(entity != null) { - blocks.filter { BossKillerMovement.getInstance().getDistanceBetweenBlocks(it, mc.thePlayer.position) > BossKillerMovement.getInstance().getDistanceBetweenBlocks(it, entity.position)} - } else { - blocks.filter { BossKillerMovement.getInstance().getDistanceBetweenBlocks(it, mc.thePlayer.position) > 1} - } + return blocks } - + + fun getCornerBlocks(centerBlock: BlockPos, radiusX: Int, radiusY: Int, radiusZ: Int): Pair { val topLeft = BlockPos(centerBlock.x - radiusX, centerBlock.y - radiusY, centerBlock.z - radiusZ) val bottomRight = BlockPos(centerBlock.x + radiusX, centerBlock.y + radiusY, centerBlock.z + radiusZ) return topLeft to bottomRight } + fun isSingleCorner(pos: BlockPos): Boolean { + val top = pos.add(1, 0, 0) + val right = pos.add(0, 0, 1) + val bottom = pos.add(-1, 0, 0) + val left = pos.add(0, 0, -1) + val topAbove = pos.add(1, 1, 0) + val rightAbove = pos.add(0, 1, 1) + val bottomAbove = pos.add(-1, 1, 0) + val leftAbove = pos.add(0, 1, -1) + + if(!isValidBlock(topAbove)) return false + if(!isValidBlock(bottomAbove)) return false + if(!isValidBlock(leftAbove)) return false + if(!isValidBlock(rightAbove)) return false + + + val r1 = !canWalkOnBlock(top) && !canWalkOnBlock(right); + val r2 = !canWalkOnBlock(bottom) && !canWalkOnBlock(right); + val r3 = !canWalkOnBlock(top) && !canWalkOnBlock(left); + val r4 = !canWalkOnBlock(bottom) && !canWalkOnBlock(left); + + return (r1.and(r2.not()) .and(r3.not()) .and(r4.not()) + .or(r2.and(r1.not()) .and(r3.not()) .and(r4.not())) + .or(r3.and(r1.not()) .and(r2.not()) .and(r4.not())) + .or(r4.and(r1.not()) .and(r2.not()) .and(r3.not()))); + } + + + fun isValidBlock(block: BlockPos):Boolean { + return !(!world.isAirBlock(block) && !world.getBlockState(block).block.isBlockNormalCube) + } + fun neighbourGenerator(mainBlock: BlockPos, size: Int): List { return neighbourGenerator(mainBlock, size, size, size) } @@ -109,7 +134,6 @@ object BlockUtil { if(world.isAirBlock(it)) blockFail++ else blockFail=0 if(blockFail>3) return false - lastBlockY = it.y lastFullBlock = world.isBlockFullCube(it) isLastBlockSlab = isStairSlab(it) @@ -133,7 +157,6 @@ object BlockUtil { // } // return true } - fun bresenham(start: Vec3, end: Vec3): List { var start0 = start val blocks = mutableListOf(start0.toBlockPos()) @@ -143,7 +166,6 @@ object BlockUtil { var x0 = MathHelper.floor_double(start0.xCoord) var y0 = MathHelper.floor_double(start0.yCoord) var z0 = MathHelper.floor_double(start0.zCoord) - var iterations = 200 while (iterations-- >= 0) { if (x0 == x1 && y0 == y1 && z0 == z1) { @@ -207,5 +229,6 @@ object BlockUtil { } return blocks } - } + + diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/util/LockRotationUtil.kt b/src/main/kotlin/dev/macrohq/swiftslayer/util/LockRotationUtil.kt index 84cbd80..c08c192 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/util/LockRotationUtil.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/util/LockRotationUtil.kt @@ -1,12 +1,12 @@ package dev.macrohq.swiftslayer.util; import dev.macrohq.swiftslayer.feature.AbstractFeature -import dev.macrohq.swiftslayer.feature.implementation.AutoRotation -import dev.macrohq.swiftslayer.feature.implementation.LockType import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent import kotlin.math.abs +import kotlin.math.max +import kotlin.math.min public class LockRotationUtil: AbstractFeature() { override val featureName: String = "LockRotation" @@ -18,7 +18,8 @@ public class LockRotationUtil: AbstractFeature() { private var pitchGoal = 0f private var yawSmooth = 0 private var pitchSmooth = 0 - public var isOverriden = false + var isOverriden = false + var lastYaws: ArrayDeque = ArrayDeque(80) companion object{ private var instance: LockRotationUtil? = null @@ -30,19 +31,29 @@ public class LockRotationUtil: AbstractFeature() { } } fun setYaw(yaw: Float, smoothing: Int, override: Boolean = false) { + var mutYaw = yaw + while (mutYaw >= 180) { + mutYaw-=360 + } + + while (mutYaw < -180) { + mutYaw+=360 + } LockRotationUtil.getInstance().isOverriden = override; - yawGoal = yaw + yawGoal = mutYaw yawSmooth = smoothing updateYaw = true } fun setPitch(pitch: Float, smoothing: Int, override: Boolean = false) { - LockRotationUtil.getInstance().isOverriden = override; - pitchGoal = pitch + + val mutPitch = max(-90.0f, min(90.0f, pitch)) + + LockRotationUtil.getInstance().isOverriden = override + pitchGoal = mutPitch pitchSmooth = smoothing updatePitch = true - } fun reset() { @@ -68,8 +79,9 @@ public class LockRotationUtil: AbstractFeature() { fun clientTick(event: ClientTickEvent?) { if (updateYaw) { + mc.thePlayer.rotationYaw = RotationMath.interpolate(yawGoal, mc.thePlayer.rotationYaw, 1f / yawSmooth) - if (abs(mc.thePlayer.rotationYaw - yawGoal) < Math.random() / 2) { + if (abs(mc.thePlayer.rotationYaw - yawGoal) < Math.random() * 2) { updateYaw = false } } @@ -77,11 +89,13 @@ public class LockRotationUtil: AbstractFeature() { if (updatePitch) { mc.thePlayer.rotationPitch = RotationMath.interpolate(pitchGoal, mc.thePlayer.rotationPitch, 1f / pitchSmooth) - if (abs(mc.thePlayer.rotationPitch - pitchGoal) < Math.random() / 2) { + if (abs(mc.thePlayer.rotationPitch - pitchGoal) < Math.random() * 2) { updatePitch = false } } } + + } diff --git a/src/main/kotlin/dev/macrohq/swiftslayer/util/RotationMath.kt b/src/main/kotlin/dev/macrohq/swiftslayer/util/RotationMath.kt index 34c7fc9..f66f739 100644 --- a/src/main/kotlin/dev/macrohq/swiftslayer/util/RotationMath.kt +++ b/src/main/kotlin/dev/macrohq/swiftslayer/util/RotationMath.kt @@ -4,8 +4,6 @@ import net.minecraft.client.Minecraft import net.minecraft.util.BlockPos import net.minecraft.util.Vec3 import kotlin.math.atan2 -import kotlin.math.max -import kotlin.math.min import kotlin.math.sqrt public class RotationMath { @@ -20,18 +18,12 @@ public class RotationMath { } fun interpolate(goal: Float, current: Float, time: Float): Float { - var current = current - while (goal - current > 180) { - current += 360f - } - while (goal - current < -180) { - current -= 360f - } - val t = easeInOut(time) - return current + (goal - current) * t + val difference = goal - current + val shortestPathDifference = (difference + 180) % 360 - 180 + val target = current + shortestPathDifference * t + return target } - fun toClock(seconds: Int): String { val hours = seconds / 3600 val minutes = (seconds % 3600) / 60 @@ -58,20 +50,11 @@ public class RotationMath { val deltaX: Double = blockPos.x + 0.5 - mc.thePlayer.posX val deltaZ: Double = blockPos.z + 0.5 - mc.thePlayer.posZ val yawToBlock = atan2(-deltaX, deltaZ) - var yaw = Math.toDegrees(yawToBlock) - - yaw = (yaw + 360) % 360 - if (yaw > 180) { - yaw -= 360.0 - } + val yaw = Math.toDegrees(yawToBlock) return yaw.toFloat() } - fun fromBlockPos(pos: BlockPos): Vec3 { - return Vec3(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble()) - } - fun getPitch(blockPos: BlockPos): Float { val deltaX: Double = blockPos.x + 0.5 - mc.thePlayer.posX val deltaY: Double = blockPos.y + 0.5 - mc.thePlayer.posY - mc.thePlayer.getEyeHeight() @@ -79,10 +62,16 @@ public class RotationMath { val distanceXZ = sqrt(deltaX * deltaX + deltaZ * deltaZ) val pitchToBlock = -atan2(deltaY, distanceXZ) var pitch = Math.toDegrees(pitchToBlock) - pitch = max(-90.0, min(90.0, pitch)) + return pitch.toFloat() } + fun fromBlockPos(pos: BlockPos): Vec3 { + return Vec3(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble()) + } + + + fun getXZDistance(pos1: BlockPos, pos2: BlockPos): Double { val xDiff = (pos1.x - pos2.x).toDouble() val zDiff = (pos1.z - pos2.z).toDouble()