Skip to content

Commit 9aa4984

Browse files
committed
Simpler killaura module
1 parent 91be7d4 commit 9aa4984

File tree

1 file changed

+46
-165
lines changed
  • common/src/main/kotlin/com/lambda/module/modules/combat

1 file changed

+46
-165
lines changed

common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt

Lines changed: 46 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,31 @@ import com.lambda.config.groups.InteractionSettings
2121
import com.lambda.config.groups.RotationSettings
2222
import com.lambda.config.groups.Targeting
2323
import com.lambda.context.SafeContext
24-
import com.lambda.event.events.PacketEvent
2524
import com.lambda.event.events.PlayerPacketEvent
2625
import com.lambda.event.events.TickEvent
2726
import com.lambda.event.listener.SafeListener.Companion.listen
27+
import com.lambda.interaction.material.StackSelection.Companion.select
28+
import com.lambda.interaction.material.container.ContainerManager.transfer
29+
import com.lambda.interaction.material.container.containers.MainHandContainer
2830
import com.lambda.interaction.request.rotation.RotationManager
2931
import com.lambda.interaction.request.rotation.visibilty.lookAtEntity
3032
import com.lambda.module.Module
3133
import com.lambda.module.tag.ModuleTag
32-
import com.lambda.util.math.MathUtils.random
34+
import com.lambda.task.RootTask.run
35+
import com.lambda.util.math.random
36+
import com.lambda.util.player.SlotUtils.combined
3337
import com.lambda.util.world.raycast.InteractionMask
3438
import com.lambda.util.world.raycast.RayCastUtils.entityResult
39+
import net.minecraft.enchantment.EnchantmentHelper
40+
import net.minecraft.entity.EntityGroup
3541
import net.minecraft.entity.EquipmentSlot
3642
import net.minecraft.entity.LivingEntity
3743
import net.minecraft.entity.attribute.EntityAttributeModifier
3844
import net.minecraft.entity.attribute.EntityAttributes
39-
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket
40-
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket
41-
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket
45+
import net.minecraft.item.SwordItem
4246
import net.minecraft.util.Hand
4347
import net.minecraft.util.math.Vec3d
4448

45-
// ToDo: Rewrite me plz
4649
object KillAura : Module(
4750
name = "KillAura",
4851
description = "Attacks entities",
@@ -52,36 +55,25 @@ object KillAura : Module(
5255

5356
// Interact
5457
private val interactionSettings = InteractionSettings(this, InteractionMask.Entity) { page == Page.Interact }
58+
private val swap by setting("Swap", true, "Swap to the item with the highest damage")
5559
private val attackMode by setting("Attack Mode", AttackMode.Cooldown) { page == Page.Interact }
56-
private val delaySync by setting("Client-side Delay", true) { page == Page.Interact && attackMode == AttackMode.Cooldown }
57-
private val cooldownSync by setting("Client-side Cooldown", true) { page == Page.Interact && attackMode == AttackMode.Cooldown }
58-
private val timerSync by setting("Assume Timer", true) { page == Page.Interact && attackMode == AttackMode.Cooldown && delaySync }
5960
private val cooldownOffset by setting("Cooldown Offset", 0, -5..5, 1) { page == Page.Interact && attackMode == AttackMode.Cooldown }
6061
private val hitDelay1 by setting("Hit Delay 1", 2.0, 0.0..20.0, 1.0) { page == Page.Interact && attackMode == AttackMode.Delay }
6162
private val hitDelay2 by setting("Hit Delay 2", 6.0, 0.0..20.0, 1.0) { page == Page.Interact && attackMode == AttackMode.Delay }
62-
private val criticalSync by setting("Critical Sync", true) { page == Page.Interact && attackMode == AttackMode.Cooldown }
6363

6464
// Targeting
6565
private val targeting = Targeting.Combat(this) { page == Page.Targeting }
6666

6767
// Aiming
6868
private val rotate by setting("Rotate", true) { page == Page.Aiming }
6969
private val rotation = RotationSettings(this) { page == Page.Aiming && rotate }
70-
private val stabilize by setting("Stabilize", true) { page == Page.Aiming && !rotation.instant && rotate }
71-
private val stabilizationSpeed by setting("Stabilization Speed", 1.0, 0.1..3.0, 0.01) { page == Page.Aiming && !rotation.instant && rotate && stabilize }
72-
private val centerFactor by setting("Center Factor", 0.4, 0.0..1.0, 0.01) { page == Page.Aiming && rotate }
73-
private val shakeFactor by setting("Shake Factor", 0.4, 0.0..1.0, 0.01) { page == Page.Aiming && rotate }
74-
private val shakeChance by setting("Shake Chance", 0.2, 0.05..1.0, 0.01) { page == Page.Aiming && shakeFactor > 0.0 && rotate }
75-
private val selfPredict by setting("Self Predict", 1.0, 0.0..2.0, 0.1) { page == Page.Aiming && rotate }
76-
private val targetPredict by setting("Target Predict", 0.0, 0.0..2.0, 0.1) { page == Page.Aiming && rotate }
7770

7871
val target: LivingEntity?
7972
get() = targeting.target()
8073

8174
private var shakeRandom = Vec3d.ZERO
8275
private var speedMultiplier = 1.0
8376

84-
private var attackTicks = 0
8577
private var lastAttackTime = 0L
8678
private var hitDelay = 100.0
8779

@@ -109,148 +101,49 @@ object KillAura : Module(
109101
}
110102

111103
listen<TickEvent.Pre> {
112-
if (!timerSync) attackTicks++
113-
114-
115104
target?.let { entity ->
116-
if (lookAtEntity(entity).requestBy(rotation).done) {
117-
runAttack(entity)
105+
if (swap) {
106+
val selection = player.combined
107+
.maxBy { stack ->
108+
stack.getAttributeModifiers(EquipmentSlot.MAINHAND)[EntityAttributes.GENERIC_ATTACK_DAMAGE]
109+
.filter { it.operation == EntityAttributeModifier.Operation.ADDITION }
110+
.sumOf { it.value } +
111+
EnchantmentHelper.getAttackDamage(stack, EntityGroup.DEFAULT)
112+
}
113+
.takeIf { it.item is SwordItem }
114+
?.select()
115+
116+
selection?.let {
117+
if (!it.selector(player.mainHandStack)) {
118+
it.transfer(MainHandContainer)
119+
?.finally {
120+
// Wait until the rotation has a hit result on the entity
121+
if (lookAtEntity(entity).requestBy(rotation).done) runAttack(entity)
122+
}?.run()
123+
124+
return@listen
125+
}
126+
}
118127
}
119-
}
120-
}
121-
122-
listen<PacketEvent.Send.Post> { event ->
123-
if (event.packet !is HandSwingC2SPacket &&
124-
event.packet !is UpdateSelectedSlotC2SPacket &&
125-
event.packet !is PlayerInteractEntityC2SPacket
126-
) return@listen
127-
128-
attackTicks = 0
129-
}
130-
131-
onEnable(::reset)
132-
onDisable(::reset)
133-
}
134-
135-
/*private fun SafeContext.buildRotation(target: LivingEntity) {
136-
val currentRotation = RotationManager.currentRotation
137-
138-
val prediction = buildPlayerPrediction()
139-
140-
val eye = when {
141-
selfPredict < 1 -> {
142-
lerp(selfPredict, player.eyePos, prediction.next().eyePos)
143-
}
144-
145-
selfPredict < 2 -> {
146-
val pos1 = prediction.next().eyePos
147-
val pos2 = prediction.next().eyePos
148-
149-
lerp(selfPredict - 1, pos1, pos2)
150-
}
151-
152-
else -> {
153-
prediction.next().next().eyePos
154-
}
155-
}
156-
157-
val box = target.boundingBox
158-
159-
val reach = targeting.targetingRange + 2.0
160-
161-
// Rotation stabilizer
162-
speedMultiplier = if (stabilize && !rotation.instant) {
163-
val slowDown = currentRotation.castBox(box, reach, eye) != null
164-
165-
with(rotation) {
166-
val targetSpeed = if (slowDown) 0.0 else 1.0
167-
val acceleration = if (slowDown) 0.2 * stabilizationSpeed else 0.1 / stabilizationSpeed
168-
169-
targetSpeed.coerceIn(
170-
speedMultiplier - acceleration,
171-
speedMultiplier + acceleration
172-
)
173-
}
174-
} else 1.0
175128

176-
// Update shake vector
177-
if (random(0.0, 1.0) < shakeChance) {
178-
shakeRandom = Vec3d(
179-
random(0.0, 1.0),
180-
random(0.0, 1.0),
181-
random(0.0, 1.0),
182-
)
183-
}
184-
185-
// Find the closest point to the player's eyes
186-
var vec = Vec3d(
187-
eye.x.coerceIn(box.minX, box.maxX),
188-
eye.y.coerceIn(box.minY, box.maxY),
189-
eye.z.coerceIn(box.minZ, box.maxZ)
190-
)
191-
192-
val random = Vec3d(
193-
lerp(shakeRandom.x, box.minX, box.maxX),
194-
lerp(shakeRandom.x, box.minY, box.maxY),
195-
lerp(shakeRandom.x, box.minZ, box.maxZ)
196-
)
197-
198-
vec = lerp(centerFactor, vec, box.center) // Mix with center
199-
vec = lerp(shakeFactor, vec, random) // Apply shaking
200-
201-
// Raycast
202-
run {
203-
if (!interactionSettings.useRayCast) return@run
204-
205-
val vecRotation = eye.rotationTo(vec)
206-
if (vecRotation.rayCast(reach, eye)?.entityResult?.entity == target) return@run
207-
208-
// Get visible point set
209-
val validHits = collectHitsFor(
210-
listOf(target.boundingBox),
211-
reach
212-
) {
213-
hit.entityResult?.entity == target
129+
// Wait until the rotation has a hit result on the entity
130+
if (lookAtEntity(entity).requestBy(rotation).done) runAttack(entity)
214131
}
215-
216-
// Switch to the closest visible point
217-
//vec = validHits.minByOrNull { vecRotation dist it.value }?.key ?: return null
218132
}
219133

220-
val predictOffset = target.moveDiff * targetPredict
221-
222-
return RotationRequest(
223-
eye.rotationTo(),
224-
rotation,
225-
speedMultiplier
226-
) {
227-
rayCast(reach, eye)?.entityResult == target
228-
}
229-
}*/
134+
onEnable { reset() }
135+
onDisable { reset() }
136+
}
230137

231138
private fun SafeContext.runAttack(target: LivingEntity) {
232-
// Critical hit check
233-
run {
234-
if (!criticalSync || attackMode != AttackMode.Cooldown) return@run
235-
236-
onGroundTicks++
237-
if (!lastOnGround) onGroundTicks = 0
238-
239-
val motionY = lastY - prevY
240-
if (motionY > -0.05 || (lastOnGround && onGroundTicks < 5)) return
241-
}
242-
243139
// Cooldown check
244-
run {
245-
when (attackMode) {
246-
AttackMode.Cooldown -> {
247-
val attackedTicks = if (delaySync) attackTicks else player.lastAttackedTicks
248-
if (attackedTicks < getAttackCooldown() + cooldownOffset) return
249-
}
140+
when (attackMode) {
141+
AttackMode.Cooldown -> {
142+
if (player.lastAttackedTicks < getAttackCooldown() + cooldownOffset) return
143+
}
250144

251-
AttackMode.Delay -> {
252-
if (System.currentTimeMillis() - lastAttackTime < hitDelay) return
253-
}
145+
AttackMode.Delay -> {
146+
if (System.currentTimeMillis() - lastAttackTime < hitDelay) return
254147
}
255148
}
256149

@@ -273,24 +166,12 @@ object KillAura : Module(
273166
if (interactionSettings.swingHand) player.swingHand(Hand.MAIN_HAND)
274167

275168
lastAttackTime = System.currentTimeMillis()
276-
hitDelay = random(hitDelay1, hitDelay2) * 50
169+
hitDelay = (hitDelay1..hitDelay2).random() * 50
277170
}
278171

279-
private fun SafeContext.getAttackCooldown(): Double {
280-
val attr = EntityAttributes.GENERIC_ATTACK_SPEED
281-
282-
val attackSpeed = if (!cooldownSync) player.getAttributeValue(attr) else {
283-
player.mainHandStack.item
284-
.getAttributeModifiers(EquipmentSlot.MAINHAND)[attr]
285-
.filter { it.operation == EntityAttributeModifier.Operation.ADDITION }
286-
.sumOf { it.value } + 4
287-
}
288-
289-
return 20.0 / attackSpeed
290-
}
172+
private fun SafeContext.getAttackCooldown() = 20.0 / player.getAttributeValue(EntityAttributes.GENERIC_ATTACK_SPEED)
291173

292-
private fun reset(ctx: SafeContext) = ctx.apply {
293-
attackTicks = player.lastAttackedTicks
174+
private fun reset() {
294175
speedMultiplier = 1.0
295176
shakeRandom = Vec3d.ZERO
296177

0 commit comments

Comments
 (0)