Skip to content

Commit 8be6c5f

Browse files
committed
Fix rotation validity checks and crystal placement
1 parent 6791554 commit 8be6c5f

File tree

8 files changed

+56
-33
lines changed

8 files changed

+56
-33
lines changed

common/src/main/kotlin/com/lambda/interaction/RotationManager.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,22 @@ object RotationManager : Loadable {
6666
block: RequestRotationBuilder.() -> Unit,
6767
) {
6868
val builder = RequestRotationBuilder().apply(block)
69-
var lastCtx: RotationContext? = null
69+
var requested: RotationContext? = null
7070

7171
listen<RotationEvent.Update>(priority, alwaysListen) { event ->
7272
builder.onUpdate?.invoke(this, event.context)?.let { context ->
7373
if (!context.config.rotate) return@let
7474
event.context = context
75-
lastCtx = context
75+
requested = context
7676
}
7777
}
7878

7979
listen<RotationEvent.Post> { event ->
80-
if (!event.context.config.rotate) return@listen
81-
if (event.context == lastCtx) {
82-
builder.onReceive?.invoke(this, event.context)
83-
}
80+
val context = event.context
81+
if (!context.config.rotate) return@listen
82+
if (context != requested) return@listen
83+
if (!context.isValid) return@listen
84+
builder.onReceive?.invoke(this, context)
8485
}
8586
}
8687

@@ -92,12 +93,12 @@ object RotationManager : Loadable {
9293
var onReceive: (SafeContext.(context: RotationContext) -> Unit)? = null
9394

9495
@RotationDsl
95-
fun onUpdate(block: SafeContext.(lastContext: RotationContext?) -> RotationContext?) {
96+
fun request(block: SafeContext.(lastContext: RotationContext?) -> RotationContext?) {
9697
onUpdate = block
9798
}
9899

99100
@RotationDsl
100-
fun onReceive(block: SafeContext.(context: RotationContext) -> Unit) {
101+
fun finished(block: SafeContext.(context: RotationContext) -> Unit) {
101102
onReceive = block
102103
}
103104
}

common/src/main/kotlin/com/lambda/interaction/rotation/RotationContext.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package com.lambda.interaction.rotation
1919

2020
import com.lambda.config.groups.RotationConfig
21+
import com.lambda.interaction.RotationManager
22+
import com.lambda.threading.runSafe
2123
import com.lambda.util.world.raycast.RayCastUtils.orMiss
2224
import net.minecraft.util.hit.HitResult
2325

@@ -27,5 +29,9 @@ data class RotationContext(
2729
val hitResult: HitResult? = null,
2830
val verify: HitResult.() -> Boolean = { true },
2931
) {
30-
val isValid: Boolean get() = verify(hitResult.orMiss)
32+
val isValid: Boolean get() = runSafe {
33+
// ToDo: Use proper reach
34+
val result = RotationManager.currentRotation.rayCast(10.0, player.eyePos)
35+
verify(result.orMiss)
36+
} ?: false
3137
}

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import com.lambda.config.groups.RotationSettings
2222
import com.lambda.config.groups.Targeting
2323
import com.lambda.context.SafeContext
2424
import com.lambda.event.events.RenderEvent
25+
import com.lambda.event.events.TickEvent
2526
import com.lambda.event.listener.SafeListener.Companion.listen
2627
import com.lambda.graphics.renderer.esp.builders.ofShape
2728
import com.lambda.interaction.RotationManager.rotate
29+
import com.lambda.interaction.rotation.RotationContext
2830
import com.lambda.interaction.visibilty.VisibilityChecker.lookAtBlock
2931
import com.lambda.module.Module
3032
import com.lambda.module.tag.ModuleTag
@@ -34,10 +36,10 @@ import com.lambda.util.combat.CombatUtils.explosionDamage
3436
import com.lambda.util.math.VecUtils.dist
3537
import com.lambda.util.math.VecUtils.vec3d
3638
import com.lambda.util.math.transform
37-
import net.minecraft.block.BlockState
3839
import net.minecraft.block.Blocks
3940
import net.minecraft.entity.LivingEntity
4041
import net.minecraft.util.Hand
42+
import net.minecraft.util.hit.BlockHitResult
4143
import net.minecraft.util.math.BlockPos
4244
import net.minecraft.util.math.Box
4345
import net.minecraft.util.math.Vec3d
@@ -86,20 +88,34 @@ object CrystalAura : Module(
8688
private val placements = LimitedDecayQueue<BlockPos>(64, 1000L)
8789
private val target: LivingEntity? get() = targeting.target()
8890

91+
private var currentRotation: RotationContext? = null
92+
8993
init {
90-
rotate {
91-
onUpdate {
92-
val targetEntity = target ?: return@onUpdate null
93-
val validPositions = findTargetPositions(targetEntity)
94+
listen<TickEvent.Pre> {
95+
currentRotation?.let { rotate ->
96+
if (!rotate.isValid) return@let
97+
(rotate.hitResult as? BlockHitResult)?.let { result ->
98+
interaction.interactBlock(player, Hand.MAIN_HAND, result)
99+
placements.add(result.blockPos)
100+
currentRotation = null
101+
}
102+
}
94103

104+
target?.let { tar ->
105+
val validPositions = findTargetPositions(tar).filter { it.blockPos !in placements }
95106
testRender.addAll(validPositions.map { it.blockPos })
96-
97-
validPositions.firstNotNullOfOrNull {
98-
lookAtBlock(it.blockPos, rotation, interact)
107+
currentRotation = validPositions.firstNotNullOfOrNull {
108+
lookAtBlock(it.blockPos.toImmutable(), rotation, interact)
99109
}
100110
}
101111
}
102112

113+
rotate {
114+
request {
115+
currentRotation
116+
}
117+
}
118+
103119
listen<RenderEvent.StaticESP> {
104120
// worldCrystals(target ?: return@listen).forEach { crystal ->
105121
// it.renderer.build(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ object KillAura : Module(
113113

114114
init {
115115
rotate {
116-
onUpdate {
117-
if (!rotate) return@onUpdate null
116+
request {
117+
if (!rotate) return@request null
118118

119119
target?.let { target ->
120120
buildRotation(target)

common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ object Speed : Module(
135135
}
136136

137137
rotate(100, alwaysListen = false) {
138-
onUpdate { lastContext ->
139-
if (mode != Mode.GRIM_STRAFE) return@onUpdate null
140-
if (!shouldWork()) return@onUpdate null
138+
request { lastContext ->
139+
if (mode != Mode.GRIM_STRAFE) return@request null
140+
if (!shouldWork()) return@request null
141141

142142
var yaw = player.yaw
143143
val input = newMovementInput()
144144

145-
if (!input.isInputting) return@onUpdate null
145+
if (!input.isInputting) return@request null
146146

147147
run {
148148
if (!diagonal) return@run

common/src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ object Scaffold : Module(
124124

125125
init {
126126
rotate {
127-
onUpdate {
127+
request {
128128
lastRotation = null
129-
val info = updatePlaceInfo() ?: return@onUpdate null
130-
val rotation = rotate(info) ?: return@onUpdate null
129+
val info = updatePlaceInfo() ?: return@request null
130+
val rotation = rotate(info) ?: return@request null
131131

132132
RotationContext(rotation, rotationConfig)
133133
}

common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ class BreakBlock @Ta5kBuilder constructor(
8181

8282
init {
8383
rotate {
84-
onUpdate {
85-
if (state != State.BREAKING) return@onUpdate null
86-
if (!rotate || ctx.instantBreak) return@onUpdate null
84+
request {
85+
if (state != State.BREAKING) return@request null
86+
if (!rotate || ctx.instantBreak) return@request null
8787

8888
lookAtBlock(blockPos, rotation, interact, sides)
8989
}
90-
onReceive { context ->
90+
finished { context ->
9191
isValid = context.isValid
9292
}
9393
}

common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ class BuildTask @Ta5kBuilder constructor(
161161
}
162162

163163
rotate {
164-
onUpdate {
165-
if (currentPlacement == null) return@onUpdate null
166-
if (!build.rotateForPlace) return@onUpdate null
164+
request {
165+
if (currentPlacement == null) return@request null
166+
if (!build.rotateForPlace) return@request null
167167
currentPlacement?.rotation
168168
}
169169
}

0 commit comments

Comments
 (0)