Skip to content

Commit 0797e8a

Browse files
committed
properly cancels vanilla breaking interactions, and makes rotation nullable for if the user wants them disabled. ik its probably not the best solution but it works for now
1 parent e721653 commit 0797e8a

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ object PacketMineTaskRewrite : Module(
9999
private val blockQueue = ArrayDeque<BlockPos>()
100100

101101
init {
102-
listen<PlayerEvent.Attack.Block>(1) { event ->
102+
listen<PlayerEvent.Breaking.Update> { event ->
103103
event.cancel()
104104

105105
val pos = event.pos
106+
if (breakTasks.any { it?.pos == event.pos }) return@listen
107+
106108
val blockState = pos.blockState(world)
107109
val bestTool = findBestAvailableTool(blockState)
108110

@@ -122,10 +124,19 @@ object PacketMineTaskRewrite : Module(
122124
blockState,
123125
pos,
124126
bestTool?.select()?.itemStack ?: player.mainHandStack
125-
)
127+
),
128+
BreakType.Primary
126129
).run()
127130
}
128131

132+
listen<PlayerEvent.Attack.Block> { event ->
133+
event.cancel()
134+
}
135+
136+
listen<PlayerEvent.Breaking.Cancel> { event ->
137+
if (breakTasks.any { it != null }) event.cancel()
138+
}
139+
129140
onDisable {
130141
breakTasks.forEach {
131142
it?.cancelBreak()
@@ -135,13 +146,14 @@ object PacketMineTaskRewrite : Module(
135146
}
136147
}
137148

138-
class PacketBreakInfo(
149+
private class PacketBreakInfo(
139150
val pos: BlockPos,
140151
val blockState: BlockState,
141152
val hand: Hand,
142153
val side: Direction,
143154
bestTool: Item?,
144-
instantBreak: Boolean
155+
instantBreak: Boolean,
156+
breakType: BreakType
145157
) {
146158
private val breakContext: BreakContext
147159
private val packetBreakTask: PacketBreakBlock
@@ -166,8 +178,11 @@ object PacketMineTaskRewrite : Module(
166178
breakingTexture = true,
167179
breakingSound = true,
168180
breakingParticles = true,
169-
collectDrop = false
170-
)
181+
collectDrop = false,
182+
rotation = null
183+
).finally {
184+
breakTasks[breakType.index] = null
185+
} as PacketBreakBlock
171186
}
172187

173188
fun run(): PacketBreakInfo {
@@ -180,6 +195,11 @@ object PacketMineTaskRewrite : Module(
180195
}
181196
}
182197

198+
private enum class BreakType(val index: Int) {
199+
Primary(0),
200+
Secondary(1)
201+
}
202+
183203
private enum class Page {
184204
General,
185205
Rebreak,

common/src/main/kotlin/com/lambda/task/tasks/PacketBreakBlock.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
6060
private val breakingSound: Boolean = true,
6161
private val breakingParticles: Boolean = true,
6262
private val collectDrop: Boolean = false,
63-
private val rotation: RotationConfig = TaskFlowModule.rotation,
63+
private val rotation: RotationConfig? = TaskFlowModule.rotation,
6464
private val interact: InteractionConfig = TaskFlowModule.interact,
6565
private val sides: Set<Direction> = Direction.entries.toSet(),
6666
private val rotate: Boolean = TaskFlowModule.build.rotateForBreak,
@@ -103,16 +103,20 @@ class PacketBreakBlock @Ta5kBuilder constructor(
103103
}
104104

105105
init {
106-
rotate {
107-
onUpdate {
108-
if (state != State.BREAKING) return@onUpdate null
109-
if (!rotate || ctx.instantBreak) return@onUpdate null
106+
rotation?.let { rotation ->
107+
rotate {
108+
onUpdate {
109+
if (state != State.BREAKING) return@onUpdate null
110+
if (!rotate || ctx.instantBreak) return@onUpdate null
110111

111-
lookAtBlock(blockPos, rotation, interact, sides)
112-
}
113-
onReceive { context ->
114-
isValid = context.isValid
112+
lookAtBlock(blockPos, rotation, interact, sides)
113+
}
114+
onReceive { context ->
115+
isValid = context.isValid
116+
}
115117
}
118+
} ?: run {
119+
isValid = true
116120
}
117121

118122
listen<TickEvent.Pre> {
@@ -231,6 +235,10 @@ class PacketBreakBlock @Ta5kBuilder constructor(
231235
)
232236
}
233237

238+
if (breakingParticles) {
239+
mc.particleManager.addBlockBreakingParticles(blockPos, side)
240+
}
241+
234242
interaction.blockBreakingSoundCooldown++
235243
if (interaction.currentBreakingProgress >= 1.0f) {
236244
interaction.breakingBlock = false

0 commit comments

Comments
 (0)