1717
1818package com.lambda.interaction.construction.context
1919
20+ import com.lambda.context.Automated
2021import com.lambda.graphics.renderer.esp.DirectionMask
2122import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2223import com.lambda.graphics.renderer.esp.ShapeBuilder
@@ -27,12 +28,16 @@ import com.lambda.interaction.request.LogContext.Companion.getLogContextBuilder
2728import com.lambda.interaction.request.breaking.BreakConfig
2829import com.lambda.interaction.request.hotbar.HotbarManager
2930import com.lambda.interaction.request.rotating.RotationRequest
31+ import com.lambda.threading.runSafe
3032import com.lambda.util.BlockUtils.emptyState
33+ import net.minecraft.block.Block
3134import net.minecraft.block.BlockState
3235import net.minecraft.block.FallingBlock
3336import net.minecraft.util.hit.BlockHitResult
3437import net.minecraft.util.math.BlockPos
38+ import net.minecraft.util.math.Vec3d
3539import java.awt.Color
40+ import kotlin.math.sqrt
3641import kotlin.random.Random
3742
3843data class BreakContext (
@@ -42,8 +47,9 @@ data class BreakContext(
4247 var itemSelection : StackSelection ,
4348 var instantBreak : Boolean ,
4449 override var cachedState : BlockState ,
45- val sortMode : BreakConfig .SortMode
46- ) : BuildContext(), LogContext {
50+ val sortMode : BreakConfig .SortMode ,
51+ private val automated : Automated
52+ ) : BuildContext(), LogContext, Automated by automated {
4753 private val baseColor = Color (222 , 0 , 0 , 25 )
4854 private val sideColor = Color (222 , 0 , 0 , 100 )
4955
@@ -52,28 +58,37 @@ data class BreakContext(
5258
5359 val random = Random .nextDouble()
5460
55- override fun compareTo (other : BuildContext ): Int {
61+ override fun compareTo (other : BuildContext ): Int = runSafe {
5662 return when (other) {
57- is BreakContext -> compareBy<BreakContext > {
63+ is BreakContext -> compareByDescending<BreakContext > {
64+ if (sortMode == BreakConfig .SortMode .Tool ) it.hotbarIndex == HotbarManager .serverSlot
65+ else 0
66+ }.thenBy {
5867 when (sortMode) {
59- BreakConfig .SortMode .Closest -> it.distance
60- BreakConfig .SortMode .Farthest -> - it. distance
61- BreakConfig .SortMode .Tool -> it.hotbarIndex != HotbarManager .serverSlot
68+ BreakConfig .SortMode .Tool ,
69+ BreakConfig .SortMode .Closest -> player.eyePos. distance(it.result.pos, it.cachedState.block)
70+ BreakConfig .SortMode .Farthest -> - player.eyePos.distance( it.result.pos, it.cachedState.block)
6271 BreakConfig .SortMode .Rotation -> it.rotation.target.angleDistance
6372 BreakConfig .SortMode .Random -> it.random
6473 }
65- }.thenBy {
66- it.distance
67- }.thenBy {
68- it.instantBreak
6974 }.thenByDescending {
70- if (it.cachedState.block is FallingBlock ) it.blockPos.y else 0
71- }.thenBy {
7275 it.hotbarIndex == HotbarManager .serverSlot
73- }.compare(this , other)
76+ }.thenBy {
77+ it.instantBreak
78+ }.compare(this @BreakContext, other)
7479
7580 else -> 1
7681 }
82+ } ? : 0
83+
84+ private fun Vec3d.distance (vec : Vec3d , block : Block ): Double {
85+ val d = vec.x - x
86+ val e = (vec.y - y).let {
87+ if (block is FallingBlock ) it - (interactionConfig.attackReach / 2 )
88+ else it
89+ }
90+ val f = vec.z - z
91+ return sqrt(d * d + e * e + f * f)
7792 }
7893
7994 override fun ShapeBuilder.buildRenderer () {
0 commit comments