Skip to content

Commit 3253006

Browse files
committed
build task packet mine start (not working)
1 parent ca435be commit 3253006

File tree

21 files changed

+435
-109
lines changed

21 files changed

+435
-109
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,33 @@ interface BuildConfig {
2828
val interactionTimeout: Int
2929

3030
// Breaking
31+
val breakMode: BreakMode
32+
val breakThreshold: Float
33+
val doubleBreak: Boolean
34+
val breakDelay: Int
35+
val sounds: Boolean
36+
val particles: Boolean
37+
val breakingTexture: Boolean
3138
val rotateForBreak: Boolean
32-
val breakConfirmation: Boolean
39+
val breakConfirmation: BreakConfirmationMode
3340
val breaksPerTick: Int
34-
val breakWeakBlocks: Boolean
3541
val forceSilkTouch: Boolean
3642
val ignoredBlocks: Set<Block>
3743

44+
val breakWeakBlocks: Boolean
45+
3846
// Placing
3947
val rotateForPlace: Boolean
4048
val placeConfirmation: Boolean
4149
val placementsPerTick: Int
50+
51+
enum class BreakMode {
52+
Vanilla, Packets
53+
}
54+
55+
enum class BreakConfirmationMode {
56+
None,
57+
AwaitThenBreak,
58+
BreakThenAwait
59+
}
4260
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ class BuildSettings(
3737
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 }
3838

3939
// Breaking
40+
override val breakMode by c.setting("Break Mode", BuildConfig.BreakMode.Vanilla)
41+
override val breakThreshold by c.setting("Break Threshold", 1.0f, 0.1f..1.0f, 0.1f, "The break amount at which the block is considered broken") { vis() && page == Page.Break }
42+
override val doubleBreak by c.setting("Double Break", false, "Allows breaking two blocks at once") { vis() && page == Page.Break }
43+
override val breakDelay by c.setting("Break Delay", 5, 0..5, 1, "The delay between breaking blocks", " ticks") { vis() && page == Page.Break }
44+
override val sounds by c.setting("Sounds", true, "Plays the breaking sounds") { vis() && page == Page.Break }
45+
override val particles by c.setting("Particles", true, "Renders the breaking particles") { vis() && page == Page.Break }
46+
override val breakingTexture by c.setting("Breaking Overlay", true, "Overlays the breaking texture at its different stages") { vis() && page == Page.Break }
4047
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() && page == Page.Break }
41-
override val breakConfirmation by c.setting("Break Confirmation", false, "Wait for block break confirmation") { vis() && page == Page.Break }
48+
override val breakConfirmation by c.setting("Break Confirmation", BuildConfig.BreakConfirmationMode.BreakThenAwait, "The style of confirmation used when breaking") { vis() && page == Page.Break }
4249
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.Break }
4350
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.Break }
4451
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() && page == Page.Break }
@@ -49,5 +56,5 @@ class BuildSettings(
4956
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation") { vis() && page == Page.Place }
5057
override val placementsPerTick by c.setting("Instant Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick") { vis() && page == Page.Place }
5158

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) }
59+
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 != BuildConfig.BreakConfirmationMode.None) }
5360
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ interface InventoryConfig {
3030
val providerPriority: Priority
3131
val storePriority: Priority
3232

33+
val silentSwap: Boolean
34+
3335
enum class Priority {
3436
WithMinItems,
3537
WithMaxItems;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ class InventorySettings(
2929
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones", vis)
3030
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from", vis)
3131
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to", vis)
32+
override val silentSwap by c.setting("Silent Swap", true, "", vis)
3233
}

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@ import com.lambda.context.SafeContext
2222
import com.lambda.graphics.renderer.esp.DirectionMask
2323
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2424
import com.lambda.interaction.construction.verify.TargetState
25+
import com.lambda.interaction.request.hotbar.HotbarManager
2526
import com.lambda.interaction.request.rotation.RotationRequest
26-
import com.lambda.threading.runSafe
27+
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
2728
import com.lambda.util.world.raycast.RayCastUtils.distanceTo
2829
import net.minecraft.block.BlockState
29-
import net.minecraft.util.Hand
30+
import net.minecraft.client.network.ClientPlayNetworkHandler
31+
import net.minecraft.entity.player.PlayerEntity
32+
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
33+
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action
3034
import net.minecraft.util.hit.BlockHitResult
3135
import net.minecraft.util.math.BlockPos
3236
import net.minecraft.util.math.Direction
3337
import net.minecraft.util.math.Vec3d
38+
import net.minecraft.world.BlockView
3439
import java.awt.Color
3540

3641
data class BreakContext(
@@ -39,21 +44,13 @@ data class BreakContext(
3944
override val rotation: RotationRequest,
4045
override val checkedState: BlockState,
4146
override val targetState: TargetState,
42-
override var hand: Hand,
47+
override var slotIndex: Int?,
4348
val instantBreak: Boolean,
49+
val buildConfig: BuildConfig,
4450
) : BuildContext {
4551
private val baseColor = Color(222, 0, 0, 25)
4652
private val sideColor = Color(222, 0, 0, 100)
4753

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-
5754
override val expectedPos: BlockPos
5855
get() = result.blockPos
5956

@@ -84,4 +81,33 @@ data class BreakContext(
8481
withState(checkedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side))
8582
withState(checkedState, expectedPos, sideColor, result.side)
8683
}
84+
85+
fun getBlockBreakingProgress(breakingTicks: Int, player: PlayerEntity, world: BlockView): Int {
86+
val currentItemStack = HotbarManager.mainHandStack ?: return -1
87+
val breakDelta = checkedState.calcItemBlockBreakingDelta(player, world, expectedPos, currentItemStack)
88+
val progress = breakDelta * breakingTicks
89+
return if (progress > 0.0f)
90+
((progress / buildConfig.breakThreshold) * 10.0f).toInt()
91+
else
92+
-1
93+
}
94+
95+
fun startBreakPacket(sequence: Int, connection: ClientPlayNetworkHandler) =
96+
breakPacket(Action.START_DESTROY_BLOCK, sequence, connection)
97+
98+
fun stopBreakPacket(sequence: Int, connection: ClientPlayNetworkHandler) =
99+
breakPacket(Action.STOP_DESTROY_BLOCK, sequence, connection)
100+
101+
fun abortBreakPacket(sequence: Int, connection: ClientPlayNetworkHandler) =
102+
breakPacket(Action.ABORT_DESTROY_BLOCK, sequence, connection)
103+
104+
private fun breakPacket(action: Action, sequence: Int, connection: ClientPlayNetworkHandler) =
105+
connection.sendPacket(
106+
PlayerActionC2SPacket(
107+
action,
108+
expectedPos,
109+
result.side,
110+
sequence
111+
)
112+
)
87113
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import com.lambda.interaction.construction.result.Drawable
2222
import com.lambda.interaction.construction.verify.TargetState
2323
import com.lambda.interaction.request.rotation.RotationRequest
2424
import net.minecraft.block.BlockState
25-
import net.minecraft.util.Hand
2625
import net.minecraft.util.hit.BlockHitResult
2726
import net.minecraft.util.math.BlockPos
2827
import net.minecraft.util.math.Vec3d
@@ -35,9 +34,8 @@ interface BuildContext : Comparable<BuildContext>, Drawable {
3534
val targetState: TargetState
3635
val expectedPos: BlockPos
3736
val checkedState: BlockState
38-
val hand: Hand
37+
val slotIndex: Int?
3938
val rotation: RotationRequest
4039

41-
fun interact(swingHand: Boolean)
4240
fun shouldRotate(config: BuildConfig): Boolean
4341
}

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

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ import com.lambda.graphics.renderer.esp.DirectionMask
2323
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2424
import com.lambda.interaction.construction.verify.TargetState
2525
import com.lambda.interaction.request.rotation.RotationRequest
26-
import com.lambda.threading.runSafe
2726
import com.lambda.util.BlockUtils
2827
import com.lambda.util.BlockUtils.blockState
29-
import com.lambda.util.Communication.warn
3028
import net.minecraft.block.BlockState
31-
import net.minecraft.util.Hand
3229
import net.minecraft.util.hit.BlockHitResult
3330
import net.minecraft.util.math.BlockPos
3431
import net.minecraft.util.math.Direction
@@ -42,44 +39,22 @@ data class PlaceContext(
4239
override val distance: Double,
4340
override val expectedState: BlockState,
4441
override val checkedState: BlockState,
45-
override val hand: Hand,
42+
override val slotIndex: Int?,
4643
override val expectedPos: BlockPos,
4744
override val targetState: TargetState,
4845
val sneak: Boolean,
4946
val insideBlock: Boolean,
50-
val primeDirection: Direction?,
47+
val primeDirection: Direction?
5148
) : BuildContext {
5249
private val baseColor = Color(35, 188, 254, 25)
5350
private val sideColor = Color(35, 188, 254, 100)
5451

55-
override fun interact(swingHand: Boolean) {
56-
runSafe {
57-
val actionResult = interaction.interactBlock(
58-
player, hand, result
59-
)
60-
61-
if (actionResult.isAccepted) {
62-
if (actionResult.shouldSwingHand() && swingHand) {
63-
player.swingHand(hand)
64-
}
65-
66-
if (!player.getStackInHand(hand).isEmpty && interaction.hasCreativeInventory()) {
67-
mc.gameRenderer.firstPersonRenderer.resetEquipProgress(hand)
68-
}
69-
} else {
70-
warn("Internal interaction failed with $actionResult")
71-
}
72-
}
73-
}
74-
7552
override fun compareTo(other: BuildContext) =
7653
when (other) {
7754
is PlaceContext -> compareBy<PlaceContext> {
7855
BlockUtils.fluids.indexOf(it.checkedState.fluidState.fluid)
7956
}.thenByDescending {
8057
it.checkedState.fluidState.level
81-
}.thenBy {
82-
it.hand
8358
}.thenBy {
8459
it.sneak
8560
}.thenBy {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import baritone.api.pathing.goals.GoalInverted
2222
import com.lambda.config.groups.InventoryConfig
2323
import com.lambda.context.SafeContext
2424
import com.lambda.interaction.construction.context.BreakContext
25-
import com.lambda.interaction.material.StackSelection.Companion.select
2625
import com.lambda.interaction.material.StackSelection.Companion.selectStack
27-
import com.lambda.interaction.material.container.ContainerManager.findBestAvailableTool
2826
import com.lambda.interaction.material.container.ContainerManager.transfer
2927
import com.lambda.interaction.material.container.MaterialContainer
3028
import com.lambda.interaction.material.container.containers.MainHandContainer
@@ -99,12 +97,9 @@ sealed class BreakResult : BuildResult() {
9997
override val pausesParent get() = true
10098

10199
override fun resolve() =
102-
findBestAvailableTool(blockState, inventory = inventory)
103-
?.select()
104-
?.transfer(MainHandContainer, inventory)
105-
?: selectStack {
106-
isItem(badItem).not()
107-
}.transfer(MainHandContainer, inventory)
100+
selectStack {
101+
isItem(badItem).not()
102+
}.transfer(MainHandContainer, inventory)
108103
?: MaterialContainer.FailureTask("Couldn't find a tool for ${blockState.block.name.string} with $badItem in main hand.")
109104

110105
override fun SafeContext.buildRenderer() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
195195
data class WrongItem(
196196
override val blockPos: BlockPos,
197197
val context: BuildContext,
198+
//TODO: probably need to make this a list of items
198199
val neededItem: Item,
199200
val currentItem: ItemStack,
200201
val inventory: InventoryConfig

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import com.lambda.interaction.construction.result.BreakResult
2929
import com.lambda.interaction.construction.result.BuildResult
3030
import com.lambda.interaction.construction.result.PlaceResult
3131
import com.lambda.interaction.construction.verify.TargetState
32-
import com.lambda.interaction.material.container.ContainerManager.findBestAvailableTool
3332
import com.lambda.interaction.request.rotation.Rotation.Companion.rotation
3433
import com.lambda.interaction.request.rotation.Rotation.Companion.rotationTo
3534
import com.lambda.interaction.request.rotation.RotationConfig
@@ -43,10 +42,12 @@ import com.lambda.module.modules.client.TaskFlowModule
4342
import com.lambda.threading.runSafe
4443
import com.lambda.util.BlockUtils
4544
import com.lambda.util.BlockUtils.blockState
45+
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
4646
import com.lambda.util.BlockUtils.instantBreakable
4747
import com.lambda.util.BlockUtils.vecOf
4848
import com.lambda.util.Communication.warn
4949
import com.lambda.util.item.ItemStackUtils.equal
50+
import com.lambda.util.item.ItemUtils.findBestAvailableTool
5051
import com.lambda.util.math.distSq
5152
import com.lambda.util.player.copyPlayer
5253
import com.lambda.util.world.raycast.RayCastUtils.blockResult
@@ -291,7 +292,8 @@ object BuildSimulator {
291292
eye.distanceTo(blockHit.pos),
292293
resultState,
293294
blockState(blockHit.blockPos),
294-
Hand.MAIN_HAND,
295+
//TODO: idk if this is the right input here
296+
player.inventory.selectedSlot,
295297
context.blockPos,
296298
target,
297299
shouldSneak,
@@ -405,7 +407,13 @@ object BuildSimulator {
405407
lookAtBlock(pos, config = interact), rotation
406408
)
407409
val breakContext = BreakContext(
408-
eye, blockHit, rotationRequest, state, targetState, player.activeHand, instantBreakable(state, pos)
410+
eye,
411+
blockHit,
412+
rotationRequest,
413+
state,
414+
targetState,
415+
player.inventory.selectedSlot, instantBreakable(state, pos),
416+
build
409417
)
410418
acc.add(BreakResult.Break(pos, breakContext))
411419
return acc
@@ -447,29 +455,35 @@ object BuildSimulator {
447455

448456
interact.pointSelection.select(validHits)?.let { checkedHit ->
449457
val blockHit = checkedHit.hit.blockResult ?: return@let
458+
val bestTools = findBestAvailableTool(state)
450459

451460
val breakContext = BreakContext(
452461
eye,
453462
blockHit,
454463
RotationRequest(lookAt(checkedHit.targetRotation, 0.001), rotation),
455464
state,
456465
targetState,
457-
player.activeHand,
458-
instantBreakable(state, pos)
466+
player.inventory.selectedSlot,
467+
instantBreakable(state, pos),
468+
build
459469
)
460470

461471
/* player has a better tool for the job available */
462-
if (!player.isCreative) findBestAvailableTool(state)?.let { bestTool ->
463-
Hand.entries.firstOrNull {
464-
val stack = player.getStackInHand(it)
465-
stack.item == bestTool
466-
}?.let { hand ->
467-
breakContext.hand = hand
472+
if (!player.isCreative) findBestAvailableTool(state).let { bestTools ->
473+
Hand.entries.map {
474+
player.getStackInHand(it)
475+
}.filter { stack ->
476+
bestTools.any { tool -> tool == stack.item }
477+
}.sortedByDescending {
478+
state.calcItemBlockBreakingDelta(player, world, pos, it)
479+
}.let { stackList ->
480+
if (stackList.isEmpty()) {
481+
acc.add(BuildResult.WrongItem(pos, breakContext, bestTools.first(), player.activeItem, inventory))
482+
return acc
483+
}
484+
breakContext.slotIndex = player.inventory.getSlotWithStack(stackList.first())
468485
acc.add(BreakResult.Break(pos, breakContext))
469486
return acc
470-
} ?: run {
471-
acc.add(BuildResult.WrongItem(pos, breakContext, bestTool, player.activeItem, inventory))
472-
return acc
473487
}
474488
}
475489

0 commit comments

Comments
 (0)