Skip to content

Commit a0cca20

Browse files
committed
use break manager for fast break
1 parent 41f69ef commit a0cca20

File tree

7 files changed

+52
-120
lines changed

7 files changed

+52
-120
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class BreakSettings(
3636
override val breakMode by c.setting("Break Mode", BreakMode.Packet) { vis() && page == Page.General }
3737
override val sorter by c.setting("Sorter", SortMode.Closest, "The order in which breaks are performed") { vis() && page == Page.General }
3838
override val reBreak by c.setting("ReBreak", true, "Re-breaks blocks after they've been broken once") { vis() && page == Page.General }
39-
override val unsafeCancels by c.setting("Unsafe Cancels", true, "Allows cancelling block breaking even if the server might continue breaking sever side, potentially causing unexpected state changes") { vis() && page == Page.General }
4039
override val breakThreshold by c.setting("Break Threshold", 0.70f, 0.1f..1.0f, 0.01f, "The break amount at which the block is considered broken") { vis() && page == Page.General }
4140
override val doubleBreak by c.setting("Double Break", true, "Allows breaking two blocks at once") { vis() && page == Page.General }
41+
override val unsafeCancels by c.setting("Unsafe Cancels", true, "Allows cancelling block breaking even if the server might continue breaking sever side, potentially causing unexpected state changes") { vis() && page == Page.General }
4242
override val fudgeFactor by c.setting("Fudge Factor", 1, 0..5, 1, "The amount of ticks to give double, aka secondary breaks extra for the server to recognise the break") { vis() && page == Page.General }
4343
// override val desyncFix by c.setting("Desync Fix", false, "Predicts if the players breaking will be slowed next tick as block break packets are processed using the players next position") { vis() && page == Page.General }
4444
override val breakDelay by c.setting("Break Delay", 0, 0..6, 1, "The delay between breaking blocks", " ticks") { vis() && page == Page.General }

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import com.lambda.interaction.request.breaking.BreakRequest
2525
import com.lambda.interaction.request.hotbar.HotbarManager
2626
import com.lambda.interaction.request.hotbar.HotbarRequest
2727
import com.lambda.interaction.request.rotating.RotationRequest
28-
import com.lambda.module.modules.client.TaskFlowModule
2928
import com.lambda.util.BlockUtils.emptyState
3029
import net.minecraft.block.BlockState
3130
import net.minecraft.block.FallingBlock
@@ -38,9 +37,9 @@ data class BreakContext(
3837
override val result: BlockHitResult,
3938
override val rotation: RotationRequest,
4039
override var hotbarIndex: Int,
41-
override var cachedState: BlockState,
4240
var instantBreak: Boolean,
43-
val sortMode: BreakConfig.SortMode = TaskFlowModule.build.breaking.sorter
41+
override var cachedState: BlockState,
42+
val sortMode: BreakConfig.SortMode
4443
) : BuildContext() {
4544
private val baseColor = Color(222, 0, 0, 25)
4645
private val sideColor = Color(222, 0, 0, 100)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ object BuildSimulator {
697697
blockHit,
698698
rotationRequest,
699699
player.inventory.selectedSlot,
700-
state,
701700
instantBreakable(state, pos, breaking.breakThreshold),
701+
state,
702702
breaking.sorter
703703
)
704704
acc.add(BreakResult.Break(pos, breakContext))
@@ -746,7 +746,7 @@ object BuildSimulator {
746746
val rotationRequest = RotationRequest(target, rotation)
747747
val instant = instantBreakable(state, pos, breaking.breakThreshold)
748748

749-
val breakContext = BreakContext(blockHit, rotationRequest, player.inventory.selectedSlot, state, instant)
749+
val breakContext = BreakContext(blockHit, rotationRequest, player.inventory.selectedSlot, instant, state, breaking.sorter)
750750

751751
if (gamemode.isCreative) {
752752
acc.add(BreakResult.Break(pos, breakContext))

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ interface BreakConfig : RequestConfig {
2727
val breakMode: BreakMode
2828
val sorter: SortMode
2929
val reBreak: Boolean
30-
val unsafeCancels: Boolean
3130
val breakThreshold: Float
3231
val doubleBreak: Boolean
32+
val unsafeCancels: Boolean
3333
val fudgeFactor: Int
3434
//ToDo: Needs a more advanced player simulation implementation to predict the next ticks onGround / submerged status
3535
// abstract val desyncFix: Boolean

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ object BreakManager : RequestHandler<BreakRequest>(
351351
// Sanitize the new breaks
352352
val newBreaks = request.contexts
353353
.distinctBy { it.blockPos }
354-
.filter { ctx -> canAccept(ctx, request.build.breaking) }
354+
.filter { ctx -> canAccept(ctx, request.config) }
355355
.let { acceptable ->
356356
acceptable.firstOrNull()?.let { first ->
357357
acceptable.filter { it.hotbarIndex == first.hotbarIndex }
@@ -387,7 +387,7 @@ object BreakManager : RequestHandler<BreakRequest>(
387387
.filter { !it.instantBreak }
388388
.toMutableList()
389389

390-
val breakConfig = request.build.breaking
390+
val breakConfig = request.config
391391
val pendingLimit = (breakConfig.maxPendingBreaks - pendingBreakCount).coerceAtLeast(0)
392392
maxBreaksThisTick = breakConfig.breaksPerTick.coerceAtMost(pendingLimit)
393393
}
@@ -425,8 +425,8 @@ object BreakManager : RequestHandler<BreakRequest>(
425425
val ctx = iterator.next()
426426

427427
if (!ctx.requestDependencies(request)) return false
428-
rotationRequest = if (request.build.breaking.rotateForBreak) ctx.rotation.submit(false) else null
429-
if (!rotated || tickStage !in request.build.breaking.breakStageMask) return false
428+
rotationRequest = if (request.config.rotateForBreak) ctx.rotation.submit(false) else null
429+
if (!rotated || tickStage !in request.config.breakStageMask) return false
430430

431431
val breakInfo = initNewBreak(ctx, request) ?: return false
432432
updateBreakProgress(breakInfo)

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.lambda.interaction.request.Request
2525
import com.lambda.interaction.request.hotbar.HotbarConfig
2626
import com.lambda.interaction.request.inventory.InventoryConfig
2727
import com.lambda.interaction.request.rotating.RotationConfig
28+
import com.lambda.module.modules.client.TaskFlowModule
2829
import com.lambda.threading.runSafe
2930
import com.lambda.util.BlockUtils.blockState
3031
import com.lambda.util.BlockUtils.isEmpty
@@ -34,11 +35,11 @@ import net.minecraft.util.math.BlockPos
3435
data class BreakRequest(
3536
val contexts: Collection<BreakContext>,
3637
val pendingInteractions: MutableCollection<BuildContext>,
37-
val build: BuildConfig,
38-
val hotbar: HotbarConfig,
39-
val rotation: RotationConfig,
40-
val inventory: InventoryConfig,
41-
val interact: InteractionConfig
38+
val build: BuildConfig = TaskFlowModule.build,
39+
val hotbar: HotbarConfig = TaskFlowModule.hotbar,
40+
val rotation: RotationConfig = TaskFlowModule.rotation,
41+
val inventory: InventoryConfig = TaskFlowModule.inventory,
42+
val interact: InteractionConfig = TaskFlowModule.interaction
4243
) : Request() {
4344
override val config = build.breaking
4445
var onStart: ((BlockPos) -> Unit)? = null
@@ -114,11 +115,11 @@ data class BreakRequest(
114115
fun breakRequest(
115116
contexts: Collection<BreakContext>,
116117
pendingInteractions: MutableCollection<BuildContext>,
117-
rotation: RotationConfig,
118-
hotbar: HotbarConfig,
119-
interact: InteractionConfig,
120-
inventory: InventoryConfig,
121-
build: BuildConfig,
118+
rotation: RotationConfig = TaskFlowModule.rotation,
119+
hotbar: HotbarConfig = TaskFlowModule.hotbar,
120+
interact: InteractionConfig = TaskFlowModule.interaction,
121+
inventory: InventoryConfig = TaskFlowModule.inventory,
122+
build: BuildConfig = TaskFlowModule.build,
122123
builder: RequestBuilder.() -> Unit
123124
) = RequestBuilder(contexts, pendingInteractions, rotation, hotbar, interact, inventory, build).apply(builder).build()
124125
}

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

Lines changed: 31 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@
1717

1818
package com.lambda.module.modules.player
1919

20-
import com.lambda.event.events.PacketEvent
20+
import com.lambda.config.groups.BuildSettings
2121
import com.lambda.event.events.PlayerEvent
22-
import com.lambda.event.events.RenderEvent
23-
import com.lambda.event.events.TickEvent
2422
import com.lambda.event.listener.SafeListener.Companion.listen
25-
import com.lambda.graphics.renderer.esp.builders.buildFilled
26-
import com.lambda.graphics.renderer.esp.builders.buildOutline
23+
import com.lambda.interaction.construction.context.BreakContext
24+
import com.lambda.interaction.construction.context.BuildContext
25+
import com.lambda.interaction.request.breaking.BreakRequest
26+
import com.lambda.interaction.request.rotating.Rotation.Companion.rotation
27+
import com.lambda.interaction.request.rotating.RotationRequest
28+
import com.lambda.interaction.request.rotating.visibilty.lookAt
2729
import com.lambda.module.Module
30+
import com.lambda.module.modules.client.TaskFlowModule
2831
import com.lambda.module.tag.ModuleTag
29-
import com.lambda.util.math.lerp
30-
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
31-
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action
32-
import net.minecraft.util.math.Box
33-
import java.awt.Color
32+
import com.lambda.util.BlockUtils.blockState
33+
import net.minecraft.util.Hand
34+
import net.minecraft.util.hit.BlockHitResult
35+
import java.util.concurrent.ConcurrentLinkedQueue
3436

3537
object FastBreak : Module(
3638
name = "FastBreak",
@@ -39,100 +41,30 @@ object FastBreak : Module(
3941
ModuleTag.PLAYER, ModuleTag.WORLD
4042
)
4143
) {
42-
private val page by setting("Page", Page.Mining)
44+
private val buildConfig = BuildSettings(this)
4345

44-
private val breakDelay by setting("Break Delay", 5, 0..5, 1, "The tick delay between breaking blocks", unit = " ticks") { page == Page.Mining }
45-
private val breakThreshold by setting("Break Threshold", 0.7f, 0.2f..1.0f, 0.1f, "The progress at which the block will break.") { page == Page.Mining }
46-
47-
private val render by setting("Render", true, "Render block breaking progress")
48-
private val renderMode by setting("Render Mode", RenderMode.Out, "The animation style of the renders") { page == Page.Render }
49-
private val renderSetting by setting("Render Setting", RenderSetting.Both, "The different ways to draw the renders") { page == Page.Render && render }
50-
51-
private val fillColourMode by setting("Fill Mode", ColourMode.Dynamic) { page == Page.Render && renderSetting != RenderSetting.Outline }
52-
private val staticFillColour by setting("Static Fill Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the static fill of the box") { page == Page.Render && render && renderSetting != RenderSetting.Outline && fillColourMode == ColourMode.Static }
53-
private val startFillColour by setting("Start Fill Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the start fill of the box") { page == Page.Render && render && renderSetting != RenderSetting.Outline && fillColourMode == ColourMode.Dynamic }
54-
private val endFillColour by setting("End Fill Colour", Color(0f, 1f, 0f, 0.3f), "The colour used to render the end fill of the box") { page == Page.Render && render && renderSetting != RenderSetting.Outline && fillColourMode == ColourMode.Dynamic }
55-
56-
private val outlineColourMode by setting("Outline Mode", ColourMode.Dynamic) { page == Page.Render && renderSetting != RenderSetting.Fill }
57-
private val staticOutlineColour by setting("Static Outline Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the static outline of the box") { page == Page.Render && render && renderSetting != RenderSetting.Fill && outlineColourMode == ColourMode.Static }
58-
private val startOutlineColour by setting("Start Outline Colour", Color(1f, 0f, 0f, 0.3f), "The colour used to render the start outline of the box") { page == Page.Render && render && renderSetting != RenderSetting.Fill && outlineColourMode == ColourMode.Dynamic }
59-
private val endOutlineColour by setting("End Outline Colour", Color(0f, 1f, 0f, 0.3f), "The colour used to render the end outline of the box") { page == Page.Render && render && renderSetting != RenderSetting.Fill && outlineColourMode == ColourMode.Dynamic }
60-
private val outlineWidth by setting("Outline Width", 1f, 0f..3f, 0.1f, "the thickness of the outline") { page == Page.Render && render && renderSetting != RenderSetting.Fill }
46+
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
6147

6248
init {
63-
listen<PacketEvent.Send.Pre> {
64-
if (it.packet !is PlayerActionC2SPacket
65-
|| it.packet.action != Action.STOP_DESTROY_BLOCK
66-
) return@listen
67-
68-
connection.sendPacket(
69-
PlayerActionC2SPacket(
70-
Action.ABORT_DESTROY_BLOCK,
71-
// For the exploit to work, the position must be outside the player range, so any
72-
// position farther than 6 blocks will work.
73-
// This is only required for grim 2 and potentially grim 3 in the future if they update it
74-
it.packet.pos.up(2024 - 4 - 18),
75-
it.packet.direction
76-
)
49+
listen<PlayerEvent.Attack.Block> { it.cancel() }
50+
listen<PlayerEvent.Breaking.Update> { event ->
51+
event.cancel()
52+
player.swingHand(Hand.MAIN_HAND)
53+
54+
val hitResult = mc.crosshairTarget as? BlockHitResult ?: return@listen
55+
val pos = event.pos
56+
val state = blockState(pos)
57+
58+
val breakContext = BreakContext(
59+
hitResult,
60+
RotationRequest(lookAt(player.rotation), TaskFlowModule.rotation),
61+
player.inventory.selectedSlot,
62+
state.calcBlockBreakingDelta(player, world, pos) >= buildConfig.breaking.breakThreshold,
63+
state,
64+
buildConfig.breaking.sorter
7765
)
78-
}
79-
80-
listen<TickEvent.Pre> {
81-
interaction.blockBreakingCooldown = interaction.blockBreakingCooldown.coerceAtMost(breakDelay)
82-
}
8366

84-
listen<PlayerEvent.Breaking.Update> {
85-
it.progress += world.getBlockState(it.pos)
86-
.calcBlockBreakingDelta(player, world, it.pos) * (1 - breakThreshold)
67+
BreakRequest(setOf(breakContext), pendingInteractions, buildConfig).submit()
8768
}
88-
89-
listen<RenderEvent.StaticESP> { event ->
90-
if (!render || !interaction.isBreakingBlock) return@listen
91-
92-
val pos = interaction.currentBreakingPos
93-
val breakDelta = world.getBlockState(pos).calcBlockBreakingDelta(player, world, pos)
94-
95-
world.getBlockState(pos).getOutlineShape(world, pos).boundingBoxes.forEach {
96-
val previousFactor = interaction.currentBreakingProgress - breakDelta
97-
val nextFactor = interaction.currentBreakingProgress
98-
val factor = lerp(mc.tickDelta, previousFactor, nextFactor).toDouble()
99-
100-
val fillColour = fillColourMode.block(factor, if (fillColourMode == ColourMode.Static) staticFillColour else startFillColour, endFillColour)
101-
val outlineColor = outlineColourMode.block(factor, if (fillColourMode == ColourMode.Static) staticOutlineColour else startOutlineColour, endOutlineColour)
102-
val box = renderMode.block(factor, it)
103-
.offset(pos)
104-
105-
when (renderSetting) {
106-
RenderSetting.Both -> {
107-
event.renderer.buildFilled(box, fillColour)
108-
event.renderer.buildOutline(box, outlineColor)
109-
}
110-
111-
RenderSetting.Fill -> event.renderer.buildFilled(box, fillColour)
112-
RenderSetting.Outline -> event.renderer.buildOutline(box, outlineColor)
113-
}
114-
}
115-
}
116-
}
117-
118-
enum class Page {
119-
Mining, Render
120-
}
121-
122-
enum class RenderSetting {
123-
Both, Fill, Outline
124-
}
125-
126-
enum class ColourMode(val block: (Double, Color, Color) -> Color) {
127-
Static({ _, start, _ -> start }),
128-
Dynamic({ factor, start, end -> lerp(factor, start, end) })
129-
}
130-
131-
val Box.ofCenter: Box get() = Box(center, center)
132-
133-
enum class RenderMode(val block: (Double, Box) -> Box) {
134-
Out({ factor, box -> lerp(factor, box.ofCenter, box)}),
135-
In({ factor, box -> lerp(factor, box, box.ofCenter)}),
136-
Static({ _, box -> box });
13769
}
13870
}

0 commit comments

Comments
 (0)