Skip to content

Commit 3e15fd5

Browse files
committed
semi working break handler
1 parent f1fb9b1 commit 3e15fd5

File tree

11 files changed

+595
-266
lines changed

11 files changed

+595
-266
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.config.groups
19+
20+
import com.lambda.config.Configurable
21+
import com.lambda.interaction.request.Priority
22+
import com.lambda.interaction.request.breaking.BreakConfig
23+
import com.lambda.util.BlockUtils.allSigns
24+
25+
class BreakSettings(
26+
c: Configurable,
27+
priority: Priority = 0,
28+
vis: () -> Boolean = { true }
29+
) : BreakConfig(priority) {
30+
override val breakMode by c.setting("Break Mode", BreakMode.Vanilla) { vis() }
31+
override val breakThreshold by c.setting("Break Threshold", 1.0f, 0.1f..1.0f, 0.02f, "The break amount at which the block is considered broken") { vis() }
32+
override val doubleBreak by c.setting("Double Break", false, "Allows breaking two blocks at once") { vis() }
33+
override val breakDelay by c.setting("Break Delay", 5, 0..5, 1, "The delay between breaking blocks", " ticks") { vis() }
34+
override val sounds by c.setting("Sounds", true, "Plays the breaking sounds") { vis() }
35+
override val particles by c.setting("Particles", true, "Renders the breaking particles") { vis() }
36+
override val breakingTexture by c.setting("Breaking Overlay", true, "Overlays the breaking texture at its different stages") { vis() }
37+
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() }
38+
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, "Blocks that wont be broken") { vis() }
39+
override val breakConfirmation by c.setting("Break Confirmation", BreakConfirmationMode.BreakThenAwait, "The style of confirmation used when breaking") { vis() }
40+
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() }
41+
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() }
42+
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() }
43+
override val forceFortunePickaxe by c.setting("Force Fortune Pickaxe", false, "Force fortune pickaxe when breaking blocks") { vis() }
44+
override val minFortuneLevel by c.setting("Min Fortune Level", 1, 1..3, 1, "The minimum fortune level to use") { vis() && forceFortunePickaxe }
45+
}

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.lambda.config.groups
1919

20-
import net.minecraft.block.Block
21-
2220
interface BuildConfig {
2321
// General
2422
val pathing: Boolean
@@ -28,35 +26,10 @@ interface BuildConfig {
2826
val interactionTimeout: Int
2927

3028
// 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
38-
val rotateForBreak: Boolean
39-
val breakConfirmation: BreakConfirmationMode
40-
val breaksPerTick: Int
41-
val forceSilkTouch: Boolean
42-
val forceFortunePickaxe: Boolean
43-
val minFortuneLevel: Int
44-
val ignoredBlocks: Set<Block>
45-
46-
val breakWeakBlocks: Boolean
29+
val breakSettings: BreakSettings
4730

4831
// Placing
4932
val rotateForPlace: Boolean
5033
val placeConfirmation: Boolean
5134
val placementsPerTick: Int
52-
53-
enum class BreakMode {
54-
Vanilla, Packet
55-
}
56-
57-
enum class BreakConfirmationMode {
58-
None,
59-
AwaitThenBreak,
60-
BreakThenAwait
61-
}
6235
}

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
21-
import com.lambda.util.BlockUtils.allSigns
21+
import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
2222

2323
class BuildSettings(
2424
c: Configurable,
@@ -37,26 +37,12 @@ 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) { vis() && page == Page.Break }
41-
override val breakThreshold by c.setting("Break Threshold", 1.0f, 0.1f..1.0f, 0.02f, "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 }
47-
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() && page == Page.Break }
48-
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, "Blocks that wont be broken") { vis() && page == Page.Break }
49-
override val breakConfirmation by c.setting("Break Confirmation", BuildConfig.BreakConfirmationMode.BreakThenAwait, "The style of confirmation used when breaking") { vis() && page == Page.Break }
50-
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.Break }
51-
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.Break }
52-
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() && page == Page.Break }
53-
override val forceFortunePickaxe by c.setting("Force Fortune Pickaxe", false, "Force fortune pickaxe when breaking blocks") { vis() && page == Page.Break }
54-
override val minFortuneLevel by c.setting("Min Fortune Level", 1, 1..3, 1, "The minimum fortune level to use") { vis() && page == Page.Break && forceFortunePickaxe }
40+
override val breakSettings = BreakSettings(c) { page == Page.Break && vis() }
5541

5642
// Placing
5743
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() && page == Page.Place }
5844
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation") { vis() && page == Page.Place }
5945
override val placementsPerTick by c.setting("Instant Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick") { vis() && page == Page.Place }
6046

61-
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) }
47+
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 && breakSettings.breakConfirmation != BreakConfirmationMode.None) }
6248
}

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,22 @@
1818
package com.lambda.interaction.construction.context
1919

2020
import com.lambda.config.groups.BuildConfig
21+
import com.lambda.config.groups.BuildSettings
2122
import com.lambda.config.groups.InventoryConfig
2223
import com.lambda.context.SafeContext
2324
import com.lambda.graphics.renderer.esp.DirectionMask
2425
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2526
import com.lambda.interaction.construction.verify.TargetState
26-
import com.lambda.interaction.request.hotbar.HotbarManager
2727
import com.lambda.interaction.request.rotation.RotationRequest
28-
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
2928
import com.lambda.util.world.raycast.RayCastUtils.distanceTo
3029
import net.minecraft.block.BlockState
3130
import net.minecraft.client.network.ClientPlayNetworkHandler
32-
import net.minecraft.entity.player.PlayerEntity
3331
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
3432
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action
3533
import net.minecraft.util.hit.BlockHitResult
3634
import net.minecraft.util.math.BlockPos
3735
import net.minecraft.util.math.Direction
3836
import net.minecraft.util.math.Vec3d
39-
import net.minecraft.world.BlockView
4037
import java.awt.Color
4138

4239
data class BreakContext(
@@ -77,23 +74,13 @@ data class BreakContext(
7774
}
7875
}
7976

80-
override fun shouldRotate(config: BuildConfig) = config.rotateForBreak
77+
override fun shouldRotate(config: BuildConfig) = config.breakSettings.rotateForBreak
8178

8279
override fun SafeContext.buildRenderer() {
8380
withState(checkedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side))
8481
withState(checkedState, expectedPos, sideColor, result.side)
8582
}
8683

87-
fun getBlockBreakingProgress(breakingTicks: Int, player: PlayerEntity, world: BlockView): Int {
88-
val currentItemStack = player.mainHandStack ?: return -1
89-
val breakDelta = checkedState.calcItemBlockBreakingDelta(player, world, expectedPos, currentItemStack)
90-
val progress = breakDelta * breakingTicks
91-
return if (progress > 0.0f)
92-
((progress / buildConfig.breakThreshold) * 10.0f).toInt()
93-
else
94-
-1
95-
}
96-
9784
fun startBreakPacket(sequence: Int, connection: ClientPlayNetworkHandler) =
9885
breakPacket(Action.START_DESTROY_BLOCK, sequence, connection)
9986

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ object BuildSimulator {
118118
}
119119

120120
/* block should be ignored */
121-
if (state.block in build.ignoredBlocks && target.type == TargetState.Type.AIR) {
121+
if (state.block in build.breakSettings.ignoredBlocks && target.type == TargetState.Type.AIR) {
122122
return BuildResult.Ignored(pos)
123123
}
124124

@@ -339,7 +339,7 @@ object BuildSimulator {
339339
val state = blockState(pos)
340340

341341
/* is a block that will be destroyed by breaking adjacent blocks */
342-
if (build.breakWeakBlocks && state.block.hardness == 0f && !state.isAir) {
342+
if (build.breakSettings.breakWeakBlocks && state.block.hardness == 0f && !state.isAir) {
343343
acc.add(BuildResult.Ignored(pos))
344344
return acc
345345
}
@@ -414,7 +414,7 @@ object BuildSimulator {
414414
player.inventory.selectedSlot,
415415
instantBreakable(state, pos),
416416
build,
417-
inventory
417+
inventory
418418
)
419419
acc.add(BreakResult.Break(pos, breakContext))
420420
return acc
@@ -487,10 +487,10 @@ object BuildSimulator {
487487
return acc
488488
}
489489

490-
val toolSelection = if (build.forceSilkTouch) {
490+
val toolSelection = if (build.breakSettings.forceSilkTouch) {
491491
selectStack { isOneOfItems(bestTools) and hasEnchantment(Enchantments.SILK_TOUCH) }
492-
} else if (build.forceFortunePickaxe) {
493-
selectStack { isOneOfItems(bestTools) and hasEnchantment(Enchantments.FORTUNE, build.minFortuneLevel) }
492+
} else if (build.breakSettings.forceFortunePickaxe) {
493+
selectStack { isOneOfItems(bestTools) and hasEnchantment(Enchantments.FORTUNE, build.breakSettings.minFortuneLevel) }
494494
} else {
495495
bestTools.select()
496496
}

common/src/main/kotlin/com/lambda/interaction/request/RequestHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract class RequestHandler<R : Request> {
5151
*
5252
* @return True, if the request was updated.
5353
*/
54-
protected fun updateRequest(
54+
protected open fun updateRequest(
5555
keepIfNull: Boolean = false,
5656
filter: (Map.Entry<RequestConfig<R>, R>) -> Boolean = { true }
5757
): Boolean {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.request.breaking
19+
20+
import com.lambda.config.Configurable
21+
import com.lambda.config.groups.BuildSettings.Page
22+
import com.lambda.interaction.request.Priority
23+
import com.lambda.interaction.request.RequestConfig
24+
import com.lambda.interaction.request.hotbar.HotbarManager
25+
import com.lambda.interaction.request.hotbar.HotbarRequest
26+
import com.lambda.util.BlockUtils.allSigns
27+
import net.minecraft.block.Block
28+
29+
abstract class BreakConfig(
30+
priority: Priority = 0
31+
) : RequestConfig<BreakRequest>(priority) {
32+
abstract val breakMode: BreakMode
33+
abstract val breakThreshold: Float
34+
abstract val doubleBreak: Boolean
35+
abstract val breakDelay: Int
36+
abstract val sounds: Boolean
37+
abstract val particles: Boolean
38+
abstract val breakingTexture: Boolean
39+
abstract val rotateForBreak: Boolean
40+
abstract val breakConfirmation: BreakConfirmationMode
41+
abstract val breaksPerTick: Int
42+
abstract val breakWeakBlocks: Boolean
43+
abstract val forceSilkTouch: Boolean
44+
abstract val forceFortunePickaxe: Boolean
45+
abstract val minFortuneLevel: Int
46+
abstract val ignoredBlocks: Set<Block>
47+
48+
override fun requestInternal(request: BreakRequest) {
49+
BreakManager.registerRequest(this, request)
50+
}
51+
52+
enum class BreakMode {
53+
Vanilla,
54+
Packet
55+
}
56+
57+
enum class BreakConfirmationMode {
58+
None,
59+
BreakThenAwait,
60+
AwaitThenBreak
61+
}
62+
}

0 commit comments

Comments
 (0)