[enhancement] Added air strafe, rendering, and stuck check to HoleSnap

This commit is contained in:
Xiaro 2021-03-03 18:22:07 -05:00
parent db553ac34e
commit f22b25441e
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
3 changed files with 89 additions and 16 deletions

View File

@ -1,25 +1,35 @@
package org.kamiblue.client.module.modules.combat
import net.minecraft.network.play.server.SPacketPlayerPosLook
import net.minecraft.util.MovementInputFromOptions
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import net.minecraftforge.client.event.InputUpdateEvent
import org.kamiblue.client.event.SafeClientEvent
import org.kamiblue.client.event.events.PacketEvent
import org.kamiblue.client.event.events.PlayerMoveEvent
import org.kamiblue.client.event.events.PlayerTravelEvent
import org.kamiblue.client.event.events.RenderWorldEvent
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.module.modules.movement.Strafe
import org.kamiblue.client.util.EntityUtils
import org.kamiblue.client.util.EntityUtils.flooredPosition
import org.kamiblue.client.util.MovementUtils.resetMove
import org.kamiblue.client.util.MovementUtils.speed
import org.kamiblue.client.util.combat.SurroundUtils
import org.kamiblue.client.util.combat.SurroundUtils.checkHole
import org.kamiblue.client.util.graphics.KamiTessellator
import org.kamiblue.client.util.math.RotationUtils
import org.kamiblue.client.util.math.VectorUtils
import org.kamiblue.client.util.math.VectorUtils.distanceTo
import org.kamiblue.client.util.math.VectorUtils.toBlockPos
import org.kamiblue.client.util.math.VectorUtils.toVec3d
import org.kamiblue.client.util.threads.safeAsyncListener
import org.kamiblue.client.util.threads.safeListener
import org.kamiblue.commons.extension.ceilToInt
import org.kamiblue.commons.extension.toRadian
import org.kamiblue.event.listener.listener
import org.lwjgl.opengl.GL11.*
import kotlin.math.*
internal object HoleSnap : Module(
@ -27,37 +37,89 @@ internal object HoleSnap : Module(
description = "Move you into the hole nearby",
category = Category.COMBAT
) {
private val airStrafe by setting("Air Strafe", true)
private val disableStrafe by setting("Disable Strafe", true)
private val range by setting("Range", 2.5f, 0.5f..4.0f, 0.25f)
private var holePos: BlockPos? = null
private var stuckTicks = 0
init {
onDisable {
holePos = null
stuckTicks = 0
}
safeListener<RenderWorldEvent>(1) {
holePos?.let {
if (player.flooredPosition == it) return@safeListener
val posFrom = EntityUtils.getInterpolatedPos(player, KamiTessellator.pTicks())
val posTo = it.toVec3d(0.5, 0.0, 0.5)
val buffer = KamiTessellator.buffer
glLineWidth(3.0f)
glDisable(GL_DEPTH_TEST)
KamiTessellator.begin(GL_LINES)
buffer.pos(posFrom.x, posFrom.y, posFrom.z).color(32, 255, 32, 2500).endVertex()
buffer.pos(posTo.x, posTo.y, posTo.z).color(32, 255, 32, 255).endVertex()
KamiTessellator.render()
glLineWidth(1.0f)
glEnable(GL_DEPTH_TEST)
}
}
listener<PacketEvent.Receive> {
if (it.packet is SPacketPlayerPosLook) disable()
}
listener<InputUpdateEvent>(-69) {
if (it.movementInput is MovementInputFromOptions && holePos != null) {
it.movementInput.resetMove()
}
}
safeAsyncListener<PlayerMoveEvent> {
if (checkHole(player) != SurroundUtils.HoleType.NONE) {
if (!player.isEntityAlive) return@safeAsyncListener
val currentSpeed = player.speed
if (shouldDisable(currentSpeed)) {
disable()
return@safeAsyncListener
}
findHole()?.let {
getHole()?.let {
if (disableStrafe) Strafe.disable()
if (player.onGround && !isAboveHole(it)) {
if ((airStrafe || player.onGround) && !isAboveHole(it)) {
val playerPos = player.positionVector
val targetPos = Vec3d(it.x + 0.5, player.posY, it.z + 0.5)
val yawRad = RotationUtils.getRotationTo(playerPos, targetPos).x.toRadian()
val dist = playerPos.distanceTo(targetPos)
val speed = min(0.2805, dist / 2.0)
val speed = if (player.onGround) min(0.2805, dist / 2.0) else currentSpeed + 0.02
player.motionX = -sin(yawRad) * speed
player.motionZ = cos(yawRad) * speed
if (player.collidedHorizontally) stuckTicks++
else stuckTicks = 0
}
}
}
}
private fun SafeClientEvent.shouldDisable(currentSpeed: Double) =
holePos?.let { player.posY < it.y } ?: false
|| stuckTicks > 5 && currentSpeed < 0.1
|| currentSpeed < 0.01 && checkHole(player) != SurroundUtils.HoleType.NONE
private fun SafeClientEvent.getHole() =
if (player.ticksExisted % 10 == 0) findHole()
else holePos ?: findHole()
private fun SafeClientEvent.findHole(): BlockPos? {
var closestHole = Pair(69.69, BlockPos.ORIGIN)
val playerPos = player.positionVector.toBlockPos()
@ -76,7 +138,8 @@ internal object HoleSnap : Module(
}
}
return if (closestHole.second != BlockPos.ORIGIN) closestHole.second else null
return if (closestHole.second != BlockPos.ORIGIN) closestHole.second.also { holePos = it }
else null
}
private fun SafeClientEvent.isAboveHole(holePos: BlockPos): Boolean {

View File

@ -25,6 +25,8 @@ import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.util.*
import org.kamiblue.client.util.MovementUtils.calcMoveYaw
import org.kamiblue.client.util.MovementUtils.resetJumpSneak
import org.kamiblue.client.util.MovementUtils.resetMove
import org.kamiblue.client.util.math.RotationUtils
import org.kamiblue.client.util.math.RotationUtils.getRotationTo
import org.kamiblue.client.util.math.VectorUtils.toBlockPos
@ -168,16 +170,9 @@ internal object Freecam : Module(
}
private fun resetMovementInput(movementInput: MovementInput?) {
if (movementInput !is MovementInputFromOptions) return
movementInput.apply {
moveForward = 0f
moveStrafe = 0f
forwardKeyDown = false
backKeyDown = false
leftKeyDown = false
rightKeyDown = false
jump = false
sneak = false
if (movementInput is MovementInputFromOptions) {
movementInput.resetMove()
movementInput.resetJumpSneak()
}
}

View File

@ -3,6 +3,7 @@ package org.kamiblue.client.util
import net.minecraft.client.Minecraft
import net.minecraft.entity.Entity
import net.minecraft.init.MobEffects
import net.minecraft.util.MovementInput
import org.kamiblue.client.event.SafeClientEvent
import kotlin.math.cos
import kotlin.math.hypot
@ -50,4 +51,18 @@ object MovementUtils {
player.getActivePotionEffect(MobEffects.SPEED)?.let {
speed * (1.0 + (it.amplifier + 1) * 0.2)
} ?: speed
fun MovementInput.resetMove() {
moveForward = 0.0f
moveStrafe = 0.0f
forwardKeyDown = false
backKeyDown = false
leftKeyDown = false
rightKeyDown = false
}
fun MovementInput.resetJumpSneak() {
jump = false
sneak = false
}
}