Skip to content

Commit 4248e14

Browse files
committed
Build result rendering, ping based rotation delay
1 parent 5f9f63c commit 4248e14

File tree

22 files changed

+308
-122
lines changed

22 files changed

+308
-122
lines changed

common/src/main/kotlin/com/lambda/config/groups/BuildConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ interface BuildConfig {
1111
val breaksPerTick: Int
1212
val rotateForBreak: Boolean
1313
val rotateForPlace: Boolean
14+
val pingTimeout: Boolean
1415
}

common/src/main/kotlin/com/lambda/config/groups/BuildSettings.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class BuildSettings(
77
vis: () -> Boolean = { true }
88
) : BuildConfig {
99
enum class Page {
10-
BREAK, PLACE, PATHING
10+
BREAK, PLACE, GENERAL
1111
}
1212

1313
val page by c.setting("Build Page", Page.BREAK, "Current page", vis)
@@ -17,11 +17,13 @@ class BuildSettings(
1717
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.BREAK }
1818
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 10, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.BREAK }
1919
override val rotateForBreak by c.setting("Rotate For Break", false, "Rotate towards block while breaking") { vis() && page == Page.BREAK }
20+
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks") { vis() && page == Page.BREAK }
2021

2122
override val placeCooldown by c.setting("Place Cooldown", 0, 0..1000, 1, "Delay between placing blocks", " ms") { vis() && page == Page.PLACE }
22-
override val placeConfirmation by c.setting("Place Confirmation", false, "Wait for block placement confirmation") { vis() && page == Page.PLACE }
23-
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks") { vis() && page == Page.PLACE }
23+
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation") { vis() && page == Page.PLACE }
24+
2425
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() && page == Page.PLACE }
2526

26-
override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.PATHING }
27+
override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.GENERAL }
28+
override val pingTimeout by c.setting("Ping Timeout", true, "Timeout on high ping") { vis() && page == Page.GENERAL }
2729
}

common/src/main/kotlin/com/lambda/core/Loader.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ object Loader {
2828
HudGuiConfigurable,
2929
FriendRegistry,
3030
SoundRegistry,
31+
TimerManager,
32+
PingManager,
3133
ContainerManager
3234
)
3335

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.lambda.core
2+
3+
import com.lambda.event.events.PacketEvent
4+
import com.lambda.event.events.TickEvent
5+
import com.lambda.event.listener.SafeListener.Companion.listener
6+
import com.lambda.util.collections.LimitedOrderedSet
7+
import net.minecraft.network.packet.c2s.query.QueryPingC2SPacket
8+
import net.minecraft.network.packet.s2c.query.PingResultS2CPacket
9+
import net.minecraft.util.Util
10+
11+
object PingManager : Loadable {
12+
private val pings: LimitedOrderedSet<Long> = LimitedOrderedSet(100)
13+
private const val INTERVAL = 1
14+
15+
val lastPing: Long
16+
get() = pings.lastOrNull() ?: 0
17+
18+
init {
19+
listener<TickEvent.Pre> {
20+
connection.sendPacket(QueryPingC2SPacket(Util.getMeasuringTimeMs()))
21+
}
22+
23+
listener<PacketEvent.Receive.Pre> { event ->
24+
if (event.packet !is PingResultS2CPacket) return@listener
25+
26+
pings.add(Util.getMeasuringTimeMs() - event.packet.startTime)
27+
}
28+
}
29+
}

common/src/main/kotlin/com/lambda/core/TimerManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.lambda.event.events.ClientEvent
55
import com.lambda.event.events.TickEvent
66
import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener
77

8-
object TimerManager {
8+
object TimerManager : Loadable {
99
@JvmStatic
1010
var tickLength = 50f; private set
1111

common/src/main/kotlin/com/lambda/graphics/renderer/esp/DirectionMask.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.lambda.graphics.renderer.esp
22

3-
import com.lambda.util.BlockUtils.blockState
4-
import net.minecraft.block.BlockState
53
import net.minecraft.util.math.BlockPos
64
import net.minecraft.util.math.Direction
7-
import net.minecraft.world.BlockView
85

96
object DirectionMask {
107
const val EAST = 1 // X +
@@ -19,7 +16,10 @@ object DirectionMask {
1916
const val ALL = EAST or WEST or UP or DOWN or SOUTH or NORTH
2017
const val NONE = 0
2118

19+
fun Int.include(dir: Int) = this or dir
20+
fun Int.include(direction: Direction) = include(direction.mask)
2221
fun Int.exclude(dir: Int) = this xor dir
22+
fun Int.exclude(direction: Direction) = exclude(direction.mask)
2323
fun Int.hasDirection(dir: Int) = (this and dir) != 0
2424

2525
fun buildSideMesh(blockPos: BlockPos, filter: (BlockPos) -> Boolean): Int {

common/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import net.minecraft.util.math.Direction
1111
import net.minecraft.util.math.Vec3d
1212

1313
data class BreakContext(
14-
val pov: Vec3d,
15-
val result: BlockHitResult,
16-
val rotation: RotationContext,
14+
override val pov: Vec3d,
15+
override val result: BlockHitResult,
16+
override val rotation: RotationContext,
1717
override val checkedState: BlockState,
1818
override var hand: Hand,
1919
val instantBreak: Boolean,
@@ -32,7 +32,7 @@ data class BreakContext(
3232

3333
override val expectedState = checkedState.fluidState.blockState
3434

35-
override fun compareTo(other: ComparableContext): Int {
35+
override fun compareTo(other: BuildContext): Int {
3636
return when (other) {
3737
is BreakContext -> compareBy<BreakContext> {
3838
it.distance
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package com.lambda.interaction.construction.context
22

3+
import com.lambda.interaction.rotation.RotationContext
34
import net.minecraft.block.BlockState
45
import net.minecraft.util.Hand
6+
import net.minecraft.util.hit.BlockHitResult
57
import net.minecraft.util.math.BlockPos
8+
import net.minecraft.util.math.Vec3d
69

7-
interface BuildContext : ComparableContext {
10+
interface BuildContext : Comparable<BuildContext> {
11+
val pov: Vec3d
12+
val result: BlockHitResult
813
val distance: Double
914
val expectedState: BlockState
1015
val checkedState: BlockState
1116
val hand: Hand
1217
val resultingPos: BlockPos
18+
val rotation: RotationContext
19+
20+
override fun compareTo(other: BuildContext): Int {
21+
return compareBy<BuildContext> {
22+
it.distance
23+
}.compare(this, other)
24+
}
1325
}

common/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import net.minecraft.util.math.BlockPos
1010
import net.minecraft.util.math.Vec3d
1111

1212
data class PlaceContext(
13-
val pov: Vec3d,
14-
val result: BlockHitResult,
15-
val rotation: RotationContext,
13+
override val pov: Vec3d,
14+
override val result: BlockHitResult,
15+
override val rotation: RotationContext,
1616
override val distance: Double,
1717
override val expectedState: BlockState,
1818
override val checkedState: BlockState,
19-
val targetState: TargetState,
2019
override val hand: Hand,
20+
val targetState: TargetState,
2121
val sneak: Boolean,
2222
val insideBlock: Boolean,
2323
) : BuildContext {
2424
override val resultingPos: BlockPos
2525
get() = result.blockPos.offset(result.side)
2626

27-
override fun compareTo(other: ComparableContext): Int {
27+
override fun compareTo(other: BuildContext): Int {
2828
return when (other) {
2929
is PlaceContext -> compareBy<PlaceContext> {
3030
BlockUtils.fluids.indexOf(it.checkedState.fluidState.fluid)

common/src/main/kotlin/com/lambda/interaction/construction/result/BreakResult.kt

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ package com.lambda.interaction.construction.result
22

33
import baritone.api.pathing.goals.GoalBlock
44
import baritone.api.pathing.goals.GoalInverted
5+
import com.lambda.context.SafeContext
56
import com.lambda.interaction.construction.context.BreakContext
67
import com.lambda.interaction.material.ContainerManager.findBestAvailableTool
78
import com.lambda.interaction.material.ContainerManager.transfer
89
import com.lambda.interaction.material.StackSelection.Companion.select
910
import com.lambda.interaction.material.StackSelection.Companion.selectStack
1011
import com.lambda.interaction.material.container.MainHandContainer
11-
import com.lambda.task.Task.Companion.emptyTask
1212
import com.lambda.task.Task.Companion.failTask
1313
import com.lambda.task.tasks.BreakBlock.Companion.breakBlock
14-
import com.lambda.task.tasks.GoalTask.Companion.moveToGoalUntil
1514
import net.minecraft.block.BlockState
1615
import net.minecraft.item.Item
1716
import net.minecraft.util.math.BlockPos
18-
import net.minecraft.util.math.Box
1917
import net.minecraft.util.math.Direction
18+
import java.awt.Color
2019

2120
sealed class BreakResult : BuildResult() {
2221

@@ -27,10 +26,17 @@ sealed class BreakResult : BuildResult() {
2726
data class Success(
2827
override val blockPos: BlockPos,
2928
val context: BreakContext
30-
) : Resolvable, BreakResult() {
29+
) : Resolvable, Drawable, BreakResult() {
3130
override val rank = Rank.BREAK_SUCCESS
31+
private val color = Color(222, 0, 0, 100)
3232

33-
override val resolve get() = breakBlock(context)
33+
var collectDrop = false
34+
35+
override val resolve get() = breakBlock(context, collectDrop = collectDrop)
36+
37+
override fun SafeContext.buildRenderer() {
38+
withPos(context.resultingPos, color, context.result.side)
39+
}
3440

3541
override fun compareTo(other: ComparableResult<Rank>): Int {
3642
return when (other) {
@@ -48,11 +54,16 @@ sealed class BreakResult : BuildResult() {
4854
data class NotExposed(
4955
override val blockPos: BlockPos,
5056
val side: Direction
51-
) : Resolvable, BreakResult() {
57+
) : Resolvable, Drawable, BreakResult() {
5258
override val rank = Rank.BREAK_NOT_EXPOSED
59+
private val color = Color(46, 0, 0, 30)
5360

5461
override val resolve get() = failTask("Block is not exposed to air.")
5562

63+
override fun SafeContext.buildRenderer() {
64+
withPos(blockPos, color, side)
65+
}
66+
5667
override fun compareTo(other: ComparableResult<Rank>): Int {
5768
return when (other) {
5869
is NotExposed -> blockPos.compareTo(other.blockPos)
@@ -70,8 +81,12 @@ sealed class BreakResult : BuildResult() {
7081
override val blockPos: BlockPos,
7182
val blockState: BlockState,
7283
val badItem: Item
73-
) : Resolvable, BreakResult() {
84+
) : Resolvable, Drawable, BreakResult() {
7485
override val rank = Rank.BREAK_ITEM_CANT_MINE
86+
private val color = Color(255, 0, 0, 100)
87+
88+
override val pausesParent get() = true
89+
7590
override val resolve get() = findBestAvailableTool(blockState)
7691
?.select()
7792
?.transfer(MainHandContainer)
@@ -81,6 +96,10 @@ sealed class BreakResult : BuildResult() {
8196
}.transfer(MainHandContainer)?.solve ?: failTask("No item found or space")
8297
}
8398

99+
override fun SafeContext.buildRenderer() {
100+
withPos(blockPos, color)
101+
}
102+
84103
override fun compareTo(other: ComparableResult<Rank>): Int {
85104
return when (other) {
86105
is ItemCantMine -> badItem.name.string.compareTo(other.badItem.name.string)
@@ -97,8 +116,13 @@ sealed class BreakResult : BuildResult() {
97116
override val blockPos: BlockPos,
98117
val blockState: BlockState,
99118
val submerge: Set<BuildResult>
100-
) : BreakResult() {
119+
) : Drawable, BreakResult() {
101120
override val rank = Rank.BREAK_SUBMERGE
121+
private val color = Color(114, 27, 255, 100)
122+
123+
override fun SafeContext.buildRenderer() {
124+
withPos(blockPos, color)
125+
}
102126
}
103127

104128
/**
@@ -107,8 +131,13 @@ sealed class BreakResult : BuildResult() {
107131
data class BlockedByLiquid(
108132
override val blockPos: BlockPos,
109133
val blockState: BlockState
110-
) : BreakResult() {
134+
) : Drawable, BreakResult() {
111135
override val rank = Rank.BREAK_IS_BLOCKED_BY_LIQUID
136+
private val color = Color(50, 12, 112, 100)
137+
138+
override fun SafeContext.buildRenderer() {
139+
withPos(blockPos, color)
140+
}
112141
}
113142

114143
/**
@@ -117,9 +146,14 @@ sealed class BreakResult : BuildResult() {
117146
data class PlayerOnTop(
118147
override val blockPos: BlockPos,
119148
val blockState: BlockState
120-
) : Navigable, BreakResult() {
149+
) : Navigable, Drawable, BreakResult() {
121150
override val rank = Rank.BREAK_PLAYER_ON_TOP
151+
private val color = Color(252, 3, 207, 100)
122152

123153
override val goal = GoalInverted(GoalBlock(blockPos))
154+
155+
override fun SafeContext.buildRenderer() {
156+
withPos(blockPos, color)
157+
}
124158
}
125159
}

0 commit comments

Comments
 (0)