Skip to content

Commit 25707c5

Browse files
committed
init request handler structure rewrite
1 parent 960ede6 commit 25707c5

File tree

28 files changed

+700
-617
lines changed

28 files changed

+700
-617
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BreakSettings(
3232
override val breakThreshold by c.setting("Break Threshold", 0.7f, 0.1f..1.0f, 0.02f, "The break amount at which the block is considered broken") { vis() }
3333
override val doubleBreak by c.setting("Double Break", true, "Allows breaking two blocks at once") { vis() }
3434
override val breakDelay by c.setting("Break Delay", 0, 0..5, 1, "The delay between breaking blocks", " ticks") { vis() }
35-
override val sequenceMode by c.setting("Break Sequence Mode", BuildConfig.InteractSequenceMode.PostMovement, "The sub-tick timing at which break actions are performed", vis)
35+
override val breakStageMask by c.setting("Break Stage Mask", setOf(*TickStage.entries.toTypedArray()), "The sub-tick timing at which break actions can be performed", vis)
3636
override val swing by c.setting("Swing Mode", SwingMode.Constant, "The times at which to swing the players hand") { vis() }
3737
override val swingType by c.setting("Break Swing Type", BuildConfig.SwingType.Vanilla, "The style of swing") { vis() && swing != SwingMode.None }
3838
override val sounds by c.setting("Break Sounds", true, "Plays the breaking sounds") { vis() }
@@ -42,7 +42,7 @@ class BreakSettings(
4242
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, "Blocks that wont be broken") { vis() }
4343
override val breakConfirmation by c.setting("Break Confirmation", BreakConfirmationMode.BreakThenAwait, "The style of confirmation used when breaking") { vis() }
4444
override val maxPendingBreaks by c.setting("Max Pending Breaks", 15, 1..30, 1, "The maximum amount of pending breaks") { vis() }
45-
override val instantBreaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() }
45+
override val breaksPerTick by c.setting("Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() }
4646
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() }
4747
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() }
4848
override val forceFortunePickaxe by c.setting("Force Fortune Pickaxe", false, "Force fortune pickaxe when breaking blocks") { vis() }

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,14 @@ interface BuildConfig {
2626
val interactionTimeout: Int
2727

2828
// Breaking
29-
val breakSettings: BreakSettings
29+
val breaking: BreakSettings
3030

3131
// Placing
32-
val placeSettings: PlaceSettings
32+
val placing: PlaceSettings
3333

3434
enum class SwingType {
3535
Vanilla,
3636
Server,
3737
Client
3838
}
39-
40-
enum class InteractSequenceMode {
41-
TickStart,
42-
Vanilla,
43-
PostMovement,
44-
}
4539
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class BuildSettings(
3838
override val maxPendingInteractions by c.setting("Max Pending Interactions", 20, 1..30, 1, "Dont wait for this many interactions for the server response") { vis() && page == Page.General }
3939

4040
// Breaking
41-
override val breakSettings = BreakSettings(c) { page == Page.Break && vis() }
41+
override val breaking = BreakSettings(c) { page == Page.Break && vis() }
4242

4343
// Placing
44-
override val placeSettings = PlaceSettings(c) { page == Page.Place && vis() }
44+
override val placing = PlaceSettings(c) { page == Page.Place && vis() }
4545

46-
override val interactionTimeout by c.setting("Interaction Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks") { vis() && ((page == Page.Place && placeSettings.placeConfirmationMode != PlaceConfig.PlaceConfirmationMode.None) || (page == Page.Break && breakSettings.breakConfirmation != BreakConfirmationMode.None)) }
46+
override val interactionTimeout by c.setting("Interaction Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks") { vis() && ((page == Page.Place && placing.placeConfirmationMode != PlaceConfig.PlaceConfirmationMode.None) || (page == Page.Break && breaking.breakConfirmation != BreakConfirmationMode.None)) }
4747
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ class HotbarSettings(
2929
override val keepTicks by c.setting("Keep Ticks", 3, 0..20, 1, "The number of ticks to keep the current hotbar selection active", " ticks", vis)
3030
override val swapDelay by c.setting("Swap Delay", 0, 0..3, 1, "The number of ticks delay before allowing another hotbar selection swap", " ticks", vis)
3131
override val swapsPerTick by c.setting("Swaps Per Tick", 3, 1..10, 1, "The number of hotbar selection swaps that can take place each tick") { swapDelay <= 0 && vis() }
32-
override var swapPause by c.setting("Swap Pause", 0, 0..20, 1, "The delay in ticks to pause actions after switching to the slot", " ticks", vis)
32+
override val swapPause by c.setting("Swap Pause", 0, 0..20, 1, "The delay in ticks to pause actions after switching to the slot", " ticks", vis)
33+
override val sequenceStageMask by c.setting("Hotbar Stage Mask", setOf(*TickStage.entries.toTypedArray()), "The sub-tick timing at which hotbar actions are performed", vis)
3334
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PlaceSettings(
2929
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() }
3030
override val airPlace by c.setting("Air Place", AirPlaceMode.None, "Allows for placing blocks without adjacent faces") { vis() }
3131
override val axisRotateSetting by c.setting("Axis Rotate", true, "Overrides the Rotate For Place setting and rotates the player on each axis to air place rotational blocks") { vis() && airPlace.isEnabled() }
32-
override val sequenceMode by c.setting("Place Sequence Mode", BuildConfig.InteractSequenceMode.PostMovement, "The sub-tick timing at which break actions are performed") { vis() }
32+
override val placeStageMask by c.setting("Place Sequence Mode", setOf(*TickStage.entries.toTypedArray()), "The sub-tick timing at which break actions are performed") { vis() }
3333
override val placeConfirmationMode by c.setting("Place Confirmation", PlaceConfirmationMode.PlaceThenAwait, "Wait for block placement confirmation") { vis() }
3434
override val maxPendingPlacements by c.setting("Max Pending Placements", 5, 0..30, 1, "The maximum amount of pending placements") { vis() }
3535
override val placementsPerTick by c.setting("Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick") { vis() }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
enum class TickStage {
21+
TickStart,
22+
PostHotbar,
23+
PostInteract,
24+
PreMovement,
25+
PostMovement,
26+
}

common/src/main/kotlin/com/lambda/event/events/UpdateManagerEvent.kt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,8 @@ package com.lambda.event.events
2020
import com.lambda.event.Event
2121

2222
sealed class UpdateManagerEvent {
23-
sealed class Rotation {
24-
class Pre : Event
25-
class Post : Event
26-
}
27-
28-
sealed class Hotbar {
29-
class Pre : Event
30-
class Post : Event
31-
}
32-
33-
sealed class Break {
34-
class Pre : Event
35-
class Post : Event
36-
}
37-
38-
sealed class Place {
39-
class Pre : Event
40-
class Post : Event
41-
}
23+
class Rotation : Event
24+
class Hotbar : Event
25+
class Break : Event
26+
class Place : Event
4227
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ 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.breaking.BreakRequest
26+
import com.lambda.interaction.request.hotbar.HotbarRequest
2527
import com.lambda.interaction.request.rotation.RotationRequest
2628
import com.lambda.util.world.raycast.RayCastUtils.distanceTo
2729
import net.minecraft.block.BlockState
@@ -70,10 +72,15 @@ data class BreakContext(
7072
}
7173
}
7274

73-
override fun shouldRotate(config: BuildConfig) = config.breakSettings.rotateForBreak
75+
override fun shouldRotate(config: BuildConfig) = config.breaking.rotateForBreak
7476

7577
override fun SafeContext.buildRenderer() {
7678
withState(checkedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side))
7779
withState(checkedState, expectedPos, sideColor, result.side)
7880
}
81+
82+
fun requestDependencies(request: BreakRequest): Boolean {
83+
val hotbarRequest = request.hotbar.request(HotbarRequest(hotbarIndex, request.hotbar))
84+
return hotbarRequest.done
85+
}
7986
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ 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.HotbarRequest
26+
import com.lambda.interaction.request.placing.PlaceRequest
2527
import com.lambda.interaction.request.rotation.RotationRequest
2628
import com.lambda.util.BlockUtils
2729
import com.lambda.util.BlockUtils.blockState
@@ -73,5 +75,11 @@ data class PlaceContext(
7375
withState(blockState(result.blockPos), result.blockPos, sideColor, result.side)
7476
}
7577

76-
override fun shouldRotate(config: BuildConfig) = config.placeSettings.rotateForPlace
78+
override fun shouldRotate(config: BuildConfig) = config.placing.rotate
79+
80+
fun requestDependencies(request: PlaceRequest): Boolean {
81+
val hotbarRequest = request.hotbar.request(HotbarRequest(hotbarIndex, request.hotbar))
82+
val validRotation = if (request.build.placing.rotate) request.rotation.request(rotation).done else true
83+
return hotbarRequest.done && validRotation
84+
}
7785
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ object BuildSimulator {
9292
checkRequirements(pos, target, build)?.let {
9393
return@flatMap setOf(it)
9494
}
95-
checkPlaceResults(pos, target, eye, build.placeSettings, interact, rotation, inventory).let {
95+
checkPlaceResults(pos, target, eye, build.placing, interact, rotation, inventory).let {
9696
if (it.isEmpty()) return@let
9797
return@flatMap it
9898
}
99-
checkBreakResults(pos, eye, build.placeSettings, interact, rotation, inventory, build).let {
99+
checkBreakResults(pos, eye, build.placing, interact, rotation, inventory, build).let {
100100
if (it.isEmpty()) return@let
101101
return@flatMap it
102102
}
@@ -122,7 +122,7 @@ object BuildSimulator {
122122
}
123123

124124
/* block should be ignored */
125-
if (state.block in build.breakSettings.ignoredBlocks && target.type == TargetState.Type.AIR) {
125+
if (state.block in build.breaking.ignoredBlocks && target.type == TargetState.Type.AIR) {
126126
return BuildResult.Ignored(pos)
127127
}
128128

@@ -392,7 +392,7 @@ object BuildSimulator {
392392
val state = blockState(pos)
393393

394394
/* is a block that will be destroyed by breaking adjacent blocks */
395-
if (build.breakSettings.breakWeakBlocks && state.block.hardness == 0f && !state.isAir) {
395+
if (build.breaking.breakWeakBlocks && state.block.hardness == 0f && !state.isAir) {
396396
acc.add(BuildResult.Ignored(pos))
397397
return acc
398398
}
@@ -465,7 +465,7 @@ object BuildSimulator {
465465
state,
466466
targetState,
467467
player.inventory.selectedSlot,
468-
instantBreakable(state, pos, build.breakSettings.breakThreshold)
468+
instantBreakable(state, pos, build.breaking.breakThreshold)
469469
)
470470
acc.add(BreakResult.Break(pos, breakContext))
471471
return acc
@@ -510,7 +510,7 @@ object BuildSimulator {
510510
val blockHit = bestHit.hit.blockResult ?: return acc
511511
val target = lookAt(bestHit.targetRotation, 0.001)
512512
val request = RotationRequest(target, rotation)
513-
val instant = instantBreakable(state, pos, build.breakSettings.breakThreshold)
513+
val instant = instantBreakable(state, pos, build.breaking.breakThreshold)
514514

515515
val breakContext = BreakContext(
516516
eye, blockHit, request, state, targetState, player.inventory.selectedSlot, instant
@@ -538,10 +538,10 @@ object BuildSimulator {
538538
return acc
539539
}
540540

541-
val toolSelection = if (build.breakSettings.forceSilkTouch) {
541+
val toolSelection = if (build.breaking.forceSilkTouch) {
542542
selectStack { isOneOfItems(bestTools) and hasEnchantment(Enchantments.SILK_TOUCH) }
543-
} else if (build.breakSettings.forceFortunePickaxe) {
544-
selectStack { isOneOfItems(bestTools) and hasEnchantment(Enchantments.FORTUNE, build.breakSettings.minFortuneLevel) }
543+
} else if (build.breaking.forceFortunePickaxe) {
544+
selectStack { isOneOfItems(bestTools) and hasEnchantment(Enchantments.FORTUNE, build.breaking.minFortuneLevel) }
545545
} else {
546546
bestTools.select()
547547
}
@@ -568,7 +568,7 @@ object BuildSimulator {
568568
if (toolPair == null) return acc
569569

570570
breakContext.hotbarIndex = player.hotbar.indexOf(toolPair.first)
571-
breakContext.instantBreak = instantBreakable(state, pos, toolPair.first, build.breakSettings.breakThreshold)
571+
breakContext.instantBreak = instantBreakable(state, pos, toolPair.first, build.breaking.breakThreshold)
572572
acc.add(BreakResult.Break(pos, breakContext))
573573
return acc
574574
}

0 commit comments

Comments
 (0)