Skip to content

Commit 4d63c79

Browse files
committed
Move breaking into build task. Item pickup strategy still missing
1 parent 30cc651 commit 4d63c79

File tree

13 files changed

+94
-60
lines changed

13 files changed

+94
-60
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ interface BuildConfig {
2424
val pathing: Boolean
2525
val stayInRange: Boolean
2626
val collectDrops: Boolean
27+
val maxPendingInteractions: Int
28+
val interactionTimeout: Int
2729

2830
// Breaking
2931
val rotateForBreak: Boolean
3032
val breakConfirmation: Boolean
31-
val maxPendingBreaks: Int
3233
val breaksPerTick: Int
3334
val breakWeakBlocks: Boolean
3435
val forceSilkTouch: Boolean
@@ -37,7 +38,5 @@ interface BuildConfig {
3738
// Placing
3839
val rotateForPlace: Boolean
3940
val placeConfirmation: Boolean
40-
val placeTimeout: Int
41-
val maxPendingPlacements: Int
4241
val placementsPerTick: Int
4342
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class BuildSettings(
3434
override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.General }
3535
override val stayInRange by c.setting("Stay In Range", true, "Stay in range of blocks") { vis() && page == Page.General && pathing }
3636
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks") { vis() && page == Page.General }
37+
override val maxPendingInteractions by c.setting("Max Pending Interactions", 1, 1..10, 1, "Dont wait for this many interactions for the server response") { vis() && page == Page.General }
3738

3839
// Breaking
3940
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() && page == Page.Break }
4041
override val breakConfirmation by c.setting("Break Confirmation", false, "Wait for block break confirmation") { vis() && page == Page.Break }
41-
override val maxPendingBreaks by c.setting("Max Pending Breaks", 1, 1..10, 1, "Maximum pending block breaks") { vis() && page == Page.Break }
4242
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.Break }
4343
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.Break }
4444
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() && page == Page.Break }
@@ -47,7 +47,7 @@ class BuildSettings(
4747
// Placing
4848
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() && page == Page.Place }
4949
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation") { vis() && page == Page.Place }
50-
override val placeTimeout by c.setting("Place Timeout", 10, 1..30, 1, "Timeout for block placement in ticks", unit = " ticks") { vis() && page == Page.Place && placeConfirmation }
51-
override val maxPendingPlacements by c.setting("Max Pending Places", 1, 1..10, 1, "Maximum pending block places") { vis() && page == Page.Place }
5250
override val placementsPerTick by c.setting("Instant Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick") { vis() && page == Page.Place }
51+
52+
override val interactionTimeout by c.setting("Interaction Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks") { vis() && (page == Page.Place && placeConfirmation || page == Page.Break && breakConfirmation) }
5353
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@
1717

1818
package com.lambda.interaction.construction.context
1919

20+
import com.lambda.config.groups.BuildConfig
2021
import com.lambda.context.SafeContext
22+
import com.lambda.graphics.renderer.esp.DirectionMask
23+
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
24+
import com.lambda.interaction.construction.verify.TargetState
2125
import com.lambda.interaction.request.rotation.RotationRequest
26+
import com.lambda.threading.runSafe
2227
import com.lambda.util.world.raycast.RayCastUtils.distanceTo
2328
import net.minecraft.block.BlockState
2429
import net.minecraft.util.Hand
2530
import net.minecraft.util.hit.BlockHitResult
2631
import net.minecraft.util.math.BlockPos
2732
import net.minecraft.util.math.Direction
2833
import net.minecraft.util.math.Vec3d
34+
import java.awt.Color
2935

3036
data class BreakContext(
3137
override val pov: Vec3d,
@@ -35,6 +41,19 @@ data class BreakContext(
3541
override var hand: Hand,
3642
val instantBreak: Boolean,
3743
) : BuildContext {
44+
override val targetState = TargetState.Air
45+
private val baseColor = Color(222, 0, 0, 25)
46+
private val sideColor = Color(222, 0, 0, 100)
47+
48+
override fun interact(swingHand: Boolean) {
49+
runSafe {
50+
if (interaction.updateBlockBreakingProgress(result.blockPos, result.side)) {
51+
if (player.isCreative) interaction.blockBreakingCooldown = 0
52+
if (swingHand) player.swingHand(hand)
53+
}
54+
}
55+
}
56+
3857
override val expectedPos: BlockPos
3958
get() = result.blockPos
4059

@@ -59,7 +78,10 @@ data class BreakContext(
5978
}
6079
}
6180

62-
override fun SafeContext.buildRenderer() {
81+
override fun shouldRotate(config: BuildConfig) = config.rotateForBreak
6382

83+
override fun SafeContext.buildRenderer() {
84+
withState(checkedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side))
85+
withState(checkedState, expectedPos, sideColor, result.side)
6486
}
6587
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
package com.lambda.interaction.construction.context
1919

20+
import com.lambda.config.groups.BuildConfig
2021
import com.lambda.interaction.construction.result.Drawable
22+
import com.lambda.interaction.construction.verify.TargetState
2123
import com.lambda.interaction.request.rotation.RotationRequest
2224
import net.minecraft.block.BlockState
2325
import net.minecraft.util.Hand
@@ -30,14 +32,19 @@ interface BuildContext : Comparable<BuildContext>, Drawable {
3032
val result: BlockHitResult
3133
val distance: Double
3234
val expectedState: BlockState
35+
val targetState: TargetState
3336
val expectedPos: BlockPos
3437
val checkedState: BlockState
3538
val hand: Hand
3639
val rotation: RotationRequest
3740

41+
fun interact(swingHand: Boolean)
42+
3843
override fun compareTo(other: BuildContext): Int {
3944
return compareBy<BuildContext> {
4045
it.distance
4146
}.compare(this, other)
4247
}
48+
49+
fun shouldRotate(config: BuildConfig): Boolean
4350
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.interaction.construction.context
1919

20+
import com.lambda.config.groups.BuildConfig
2021
import com.lambda.context.SafeContext
2122
import com.lambda.graphics.renderer.esp.DirectionMask
2223
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
@@ -42,16 +43,15 @@ data class PlaceContext(
4243
override val checkedState: BlockState,
4344
override val hand: Hand,
4445
override val expectedPos: BlockPos,
45-
val targetState: TargetState,
46+
override val targetState: TargetState,
4647
val sneak: Boolean,
4748
val insideBlock: Boolean,
4849
val primeDirection: Direction?,
4950
) : BuildContext {
50-
var placeTick = 0L
5151
private val baseColor = Color(35, 188, 254, 25)
5252
private val sideColor = Color(35, 188, 254, 100)
5353

54-
fun place(swingHand: Boolean) {
54+
override fun interact(swingHand: Boolean) {
5555
runSafe {
5656
val actionResult = interaction.interactBlock(
5757
player, hand, result
@@ -65,7 +65,6 @@ data class PlaceContext(
6565
if (!player.getStackInHand(hand).isEmpty && interaction.hasCreativeInventory()) {
6666
mc.gameRenderer.firstPersonRenderer.resetEquipProgress(hand)
6767
}
68-
placeTick = mc.uptimeInTicks
6968
} else {
7069
warn("Internal interaction failed with $actionResult")
7170
}
@@ -95,4 +94,6 @@ data class PlaceContext(
9594
withState(expectedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
9695
withState(expectedState, expectedPos, sideColor, result.side.opposite)
9796
}
97+
98+
override fun shouldRotate(config: BuildConfig) = config.rotateForPlace
9899
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,12 @@ sealed class BreakResult : BuildResult() {
4343
*/
4444
data class Break(
4545
override val blockPos: BlockPos,
46-
val context: BreakContext,
47-
) : Drawable, Resolvable, BreakResult() {
46+
override val context: BreakContext,
47+
) : Drawable, Contextual, BreakResult() {
4848
override val rank = Rank.BREAK_SUCCESS
49-
private val color = Color(222, 0, 0, 100)
50-
51-
var collectDrop = false
52-
override val pausesParent get() = collectDrop
53-
54-
override fun resolve() = BreakBlock(context, collectDrop)
5549

5650
override fun SafeContext.buildRenderer() {
57-
withPos(context.expectedPos, color, context.result.side)
51+
with(context) { buildRenderer() }
5852
}
5953

6054
override fun compareTo(other: ComparableResult<Rank>): Int {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
4242
open val pausesParent = false
4343
override val name: String get() = "${this::class.simpleName} at ${blockPos.toShortString()}"
4444

45+
interface Contextual {
46+
val context: BuildContext
47+
}
48+
4549
/**
4650
* The build action is done.
4751
*/
@@ -197,7 +201,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
197201
) : Drawable, Resolvable, BuildResult() {
198202
override val name: String get() = "Wrong item ($currentItem) for ${blockPos.toShortString()} need ${neededItem.name.string}"
199203
override val rank = Rank.WRONG_ITEM
200-
private val color = Color(3, 252, 169, 100)
204+
private val color = Color(3, 252, 169, 25)
201205

202206
override val pausesParent get() = true
203207

@@ -233,7 +237,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
233237
) : Drawable, Resolvable, BuildResult() {
234238
override val name: String get() = "Wrong stack for $blockPos need $neededStack."
235239
override val rank = Rank.WRONG_ITEM
236-
private val color = Color(3, 252, 169, 100)
240+
private val color = Color(3, 252, 169, 25)
237241

238242
override val pausesParent get() = true
239243

@@ -269,7 +273,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
269273
) : Navigable, Drawable, BuildResult() {
270274
override val name: String get() = "Out of reach at $blockPos."
271275
override val rank = Rank.OUT_OF_REACH
272-
private val color = Color(252, 3, 207, 100)
276+
private val color = Color(252, 3, 207, 25)
273277

274278
val distance: Double by lazy {
275279
misses.minOfOrNull { pov.distanceTo(it) } ?: 0.0

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ sealed class PlaceResult : BuildResult() {
4242
*/
4343
data class Place(
4444
override val blockPos: BlockPos,
45-
val context: PlaceContext,
46-
) : PlaceResult() {
45+
override val context: PlaceContext,
46+
) : Contextual, Drawable, PlaceResult() {
4747
override val rank = Rank.PLACE_SUCCESS
4848

49+
override fun SafeContext.buildRenderer() {
50+
with(context) { buildRenderer() }
51+
}
52+
4953
override fun compareTo(other: ComparableResult<Rank>): Int {
5054
return when (other) {
5155
is Place -> context.compareTo(other.context)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ object RotationManager : RequestHandler<RotationRequest>(), Loadable {
9898

9999
// Update the current rotation
100100
prevRotation = currentRotation
101-
currentRotation = targetRotation.fixSensitivity(prevRotation)
101+
currentRotation = targetRotation/*.fixSensitivity(prevRotation)*/
102102

103103
// Handle LOCK mode
104104
if (currentRequest?.mode == RotationMode.Lock) {

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/VisibilityChecker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ object VisibilityChecker {
136136
scan: SurfaceScan = SurfaceScan.DEFAULT,
137137
check: (Direction, Vec3d) -> Unit,
138138
) {
139-
val margin = 0.1
139+
val margin = 0.01
140140

141141
excludedSides.forEach { side ->
142142
if (excludedSides.isNotEmpty() && side !in excludedSides) return@forEach

0 commit comments

Comments
 (0)