|
17 | 17 |
|
18 | 18 | package com.lambda.module.modules.movement |
19 | 19 |
|
20 | | -import com.lambda.event.events.RotationEvent |
| 20 | +import com.lambda.config.ConfigEditor.forEachSetting |
| 21 | +import com.lambda.config.ConfigEditor.hideAllExcept |
| 22 | +import com.lambda.config.blocks.WorldLineSettings |
| 23 | +import com.lambda.config.withEdits |
| 24 | +import com.lambda.context.SafeContext |
| 25 | +import com.lambda.event.events.MovementEvent |
21 | 26 | import com.lambda.event.events.TickEvent |
22 | 27 | import com.lambda.event.listener.SafeListener.Companion.listen |
| 28 | +import com.lambda.graphics.mc.renderer.ImmediateRenderer.Companion.immediateRenderer |
23 | 29 | import com.lambda.interaction.managers.rotating.Rotation.Companion.rotationTo |
24 | 30 | import com.lambda.module.Module |
25 | 31 | import com.lambda.module.modules.combat.KillAura |
26 | 32 | import com.lambda.module.tag.ModuleTag |
27 | | -import com.lambda.util.math.distSq |
28 | | -import com.lambda.util.player.MovementUtils.update |
29 | | -import kotlin.math.pow |
| 33 | +import net.minecraft.entity.effect.StatusEffects |
| 34 | +import net.minecraft.util.math.Vec3d |
| 35 | +import java.awt.Color |
| 36 | +import kotlin.math.cos |
| 37 | +import kotlin.math.sin |
| 38 | +import kotlin.math.sqrt |
30 | 39 |
|
31 | 40 | object TargetStrafe : Module( |
32 | 41 | name = "TargetStrafe", |
33 | | - description = "Automatically strafes around entities", |
| 42 | + description = "Strafes around a target in a circle. The default settings work great for old NCP.", |
34 | 43 | tag = ModuleTag.MOVEMENT, |
35 | 44 | ) { |
36 | | - private val targetDistance by setting("Strafe Distance", 1.0, 0.0..5.0, 0.1) |
37 | | - private val jitterCompensation by setting("Jitter Compensation", 0.0, 0.0..1.0, 0.1) |
38 | | - private val stabilize by setting("Stabilize", StabilizationMode.Normal) |
39 | | - |
40 | | - enum class StabilizationMode { |
41 | | - None, |
42 | | - Weak, |
43 | | - Normal, |
44 | | - Strong |
45 | | - } |
| 45 | + private val autoJump by setting("AutoJump", true) |
| 46 | + private val distanceSetting by setting("PreferredDistance", 1f, 0f..6f, 0.1f) |
| 47 | + private val maxDistance by setting("MaxDistance", 10f, 1f..32f, 0.5f) |
| 48 | + private val turnAmount by setting("TurnAmount", 5f, 1f..90f, 0.5f) |
| 49 | + private val hSpeed by setting("HSpeed", 0.2873f, 0.001f..10.0f, 0.0001f) |
| 50 | + |
| 51 | + private val needsAura by setting("NeedsAura", true) |
| 52 | + private val antiStuck by setting("AntiStuck", true) |
| 53 | + |
| 54 | + private val renderCircle by setting("RenderCircle", true) |
| 55 | + private val renderCircleColor by setting("RenderCircleColor", Color(255, 255, 255, 100)) { renderCircle } |
| 56 | + private val renderThickness by configBlock(WorldLineSettings(this)) |
| 57 | + .withEdits { |
| 58 | + hideAllExcept( |
| 59 | + ::distanceScaling, |
| 60 | + ::worldWidthSetting, |
| 61 | + ::screenWidthSetting |
| 62 | + ) |
| 63 | + forEachSetting { |
| 64 | + visibility { old -> { old() && renderCircle } } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private var direction = 1 |
46 | 69 |
|
47 | | - private var forwardDirection = 1.0 |
48 | | - private var strafeDirection = 1.0 |
| 70 | + private var currentDistance = 0.0 |
| 71 | + private var currentTargetVec: Vec3d? = null |
49 | 72 |
|
50 | | - @JvmStatic |
51 | | - val isActive get() = isEnabled && KillAura.isEnabled && KillAura.target != null |
| 73 | + private var strafing = false |
52 | 74 |
|
53 | 75 | init { |
54 | 76 | listen<TickEvent.Post> { |
55 | | - if (player.horizontalCollision) strafeDirection *= -1 |
| 77 | + if (strafing && autoJump && player.isOnGround) { |
| 78 | + player.jump() |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + listen<MovementEvent.Player.Pre> { event -> |
| 83 | + if (player.horizontalCollision && antiStuck) { |
| 84 | + switchDirection() |
| 85 | + } |
| 86 | + if (canStrafe()) { |
| 87 | + val rotations = KillAura.target?.let { it1 -> player.eyePos?.rotationTo(it1.pos) } ?: return@listen |
| 88 | + KillAura.target?.let { it1 -> doStrafeAtSpeed(event, rotations.yawF, it1.pos) } |
| 89 | + currentTargetVec = KillAura.target?.pos |
56 | 90 |
|
57 | | - if (KillAura.target == null) { |
58 | | - forwardDirection = 1.0 |
59 | | - strafeDirection = 1.0 |
| 91 | + strafing = true |
| 92 | + } else { |
| 93 | + strafing = false |
60 | 94 | } |
61 | 95 | } |
62 | 96 |
|
63 | | - listen<RotationEvent.StrafeInput> { event -> |
64 | | - KillAura.target?.let { target -> |
65 | | - event.strafeYaw = player.eyePos.rotationTo(target.boundingBox.center).yaw |
| 97 | + immediateRenderer("TargetStrafe immediate renderer") { |
| 98 | + if (strafing && renderCircle) { |
| 99 | + circleLine( |
| 100 | + currentTargetVec ?: return@immediateRenderer, |
| 101 | + distanceSetting.toDouble(), |
| 102 | + renderCircleColor, |
| 103 | + renderThickness.width, |
| 104 | + segments = 64 |
| 105 | + ) |
| 106 | + } |
| 107 | + } |
| 108 | + } |
66 | 109 |
|
67 | | - val distSq = player.pos distSq target.pos |
68 | | - val keepRange = 0.5 * jitterCompensation |
| 110 | + private fun SafeContext.doStrafeAtSpeed(event: MovementEvent.Player.Pre, rotation: Float, target: Vec3d): Boolean { |
| 111 | + var playerSpeed = hSpeed |
| 112 | + var rotationYaw = rotation + (90f * direction) |
69 | 113 |
|
70 | | - forwardDirection = when { |
71 | | - distSq > (targetDistance + keepRange).pow(2) -> 1.0 |
72 | | - distSq < (targetDistance - keepRange).pow(2) -> -1.0 |
73 | | - else -> forwardDirection |
74 | | - } |
75 | 114 |
|
76 | | - // Premium code, do not touch it bites |
77 | | - var shouldStabilize = when (stabilize) { |
78 | | - StabilizationMode.None -> false |
79 | | - StabilizationMode.Weak -> player.age % 4 == 0 // 1/4 |
80 | | - StabilizationMode.Normal -> player.age % 2 == 0 // 2/4 |
81 | | - StabilizationMode.Strong -> player.age % 4 != 0 // 3/4 |
82 | | - } |
| 115 | + val disX = player.pos.x - target.x |
| 116 | + val disZ = player.pos.z - target.z |
83 | 117 |
|
84 | | - shouldStabilize = shouldStabilize && distSq > (targetDistance + 0.5).pow(2) |
| 118 | + val distance = sqrt(disX * disX + disZ * disZ) |
85 | 119 |
|
86 | | - val strafe = if (shouldStabilize) 0.0 else strafeDirection |
87 | | - event.input.update(forwardDirection, strafe, jump = true) |
| 120 | + if (distance < maxDistance) { |
| 121 | + if (distance > distanceSetting) { |
| 122 | + rotationYaw -= turnAmount * direction |
| 123 | + } else if (distance < distanceSetting) { |
| 124 | + rotationYaw += turnAmount * direction |
88 | 125 | } |
| 126 | + } else { |
| 127 | + rotationYaw = rotation |
89 | 128 | } |
90 | 129 |
|
91 | | - onEnable { |
92 | | - forwardDirection = 1.0 |
93 | | - strafeDirection = 1.0 |
| 130 | + currentDistance = distance |
| 131 | + |
| 132 | + // speed |
| 133 | + val speed = player.getStatusEffect(StatusEffects.SPEED) |
| 134 | + if (speed != null) { |
| 135 | + |
| 136 | + playerSpeed *= 1.0f + 0.2f * (speed.amplifier + 1) |
94 | 137 | } |
| 138 | + |
| 139 | + event.movement = Vec3d(playerSpeed * cos(Math.toRadians((rotationYaw + 90.0f).toDouble())), event.movement.y, playerSpeed * sin(Math.toRadians((rotationYaw + 90.0f).toDouble()))) |
| 140 | + return false |
| 141 | + } |
| 142 | + |
| 143 | + private fun canStrafe(): Boolean { |
| 144 | + return (KillAura.isEnabled || !needsAura) && KillAura.target != null |
| 145 | + } |
| 146 | + |
| 147 | + private fun switchDirection() { |
| 148 | + direction = -direction |
95 | 149 | } |
96 | 150 | } |
0 commit comments