Skip to content

Commit a0ad9b0

Browse files
committed
initial inventory manager implementation. Nothing has been swapped to using it yet
1 parent 622e69e commit a0ad9b0

22 files changed

+246
-47
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ tasks {
215215

216216
kotlin {
217217
compilerOptions {
218-
freeCompilerArgs.add("-Xcontext-parameters")
218+
freeCompilerArgs.addAll("-Xcontext-parameters", "-Xconsistent-data-class-copy-visibility")
219219
}
220220

221221
jvmToolchain(21)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BreakSettings(
5656
override val breakDelay by c.setting("Break Delay", 0, 0..6, 1, "The delay between breaking blocks", " tick(s)", visibility = vis).group(baseGroup, Group.General)
5757

5858
// Timing
59-
override val breakStageMask by c.setting("Break Stage Mask", setOf(TickEvent.Input.Post), description = "The sub-tick timing at which break actions can be performed", visibility = vis).group(baseGroup, Group.General)
59+
override val tickStageMask by c.setting("Break Stage Mask", setOf<TickEvent>(TickEvent.Input.Post), description = "The sub-tick timing at which break actions can be performed", visibility = vis).group(baseGroup, Group.General)
6060

6161
// Swap
6262
override val swapMode by c.setting("Swap Mode", BreakConfig.SwapMode.End, "Decides when to swap to the best suited tool when breaking a block", visibility = vis).group(baseGroup, Group.General)

src/main/kotlin/com/lambda/config/groups/InteractSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class InteractSettings(
2929
) : InteractConfig, SettingGroup(c) {
3030
override val rotate by c.setting("Rotate For Interact", true, "Rotates the player to look at the block when interacting", visibility = vis).group(baseGroup)
3131
override val swingHand by c.setting("Swing On Interact", true, "Swings the players hand after interacting", visibility = vis).group(baseGroup)
32-
override val interactStageMask by c.setting("Interact Stage Mask", setOf(TickEvent.Input.Post), description = "The sub-tick timing at which interact actions are performed", visibility = vis).group(baseGroup)
32+
override val tickStageMask by c.setting("Interact Stage Mask", setOf<TickEvent>(TickEvent.Input.Post), description = "The sub-tick timing at which interact actions are performed", visibility = vis).group(baseGroup)
3333
override val interactSwingType by c.setting("Interact Swing Type", BuildConfig.SwingType.Vanilla, "The style of swing") { vis() && swingHand }.group(baseGroup)
3434
override val interactConfirmationMode by c.setting("Interact Confirmation Mode", InteractConfig.InteractConfirmationMode.InteractThenAwait, "The style of confirmation for interactions", visibility = vis).group(baseGroup)
3535
}

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

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

2020
import com.lambda.config.Configurable
21+
import com.lambda.event.events.TickEvent
2122
import com.lambda.interaction.request.inventory.InventoryConfig
2223
import com.lambda.util.NamedEnum
2324
import com.lambda.util.item.ItemUtils
@@ -28,10 +29,13 @@ class InventorySettings(
2829
vis: () -> Boolean = { true }
2930
) : InventoryConfig, SettingGroup(c) {
3031
enum class Group(override val displayName: String) : NamedEnum {
32+
General("General"),
3133
Container("Container"),
3234
Access("Access")
3335
}
3436

37+
override val actionsPerSecond by c.setting("Actions Per Tick", 20, 0..100, 1, "How many inventory actions can be performed per tick", visibility = vis).group(baseGroup, Group.General)
38+
override val tickStageMask by c.setting("Inventory Stage Mask", setOf<TickEvent>(TickEvent.Pre), description = "The sub-tick timing at which inventory actions are performed", visibility = vis).group(baseGroup, Group.General)
3539
override val disposables by c.setting("Disposables", ItemUtils.defaultDisposables, ItemUtils.defaultDisposables, "Items that will be ignored when checking for a free slot", vis).group(baseGroup, Group.Container)
3640
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones", vis).group(baseGroup, Group.Container)
3741
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from", vis).group(baseGroup, Group.Container)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PlaceSettings(
3232
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing", visibility = vis).group(baseGroup)
3333
override val airPlace by c.setting("Air Place", AirPlaceMode.None, "Allows for placing blocks without adjacent faces", visibility = vis).group(baseGroup)
3434
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 }.group(baseGroup)
35-
override val placeStageMask by c.setting("Place Stage mask", setOf(TickEvent.Input.Post), description = "The sub-tick timing at which place actions are performed", visibility = vis).group(baseGroup)
35+
override val tickStageMask by c.setting("Place Stage mask", setOf<TickEvent>(TickEvent.Input.Post), description = "The sub-tick timing at which place actions are performed", visibility = vis).group(baseGroup)
3636
override val placeConfirmationMode by c.setting("Place Confirmation", PlaceConfirmationMode.PlaceThenAwait, "Wait for block placement confirmation", visibility = vis).group(baseGroup)
3737
override val maxPendingPlacements by c.setting("Max Pending Placements", 5, 0..30, 1, "The maximum amount of pending placements", visibility = vis).group(baseGroup)
3838
override val placementsPerTick by c.setting("Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick", visibility = vis).group(baseGroup)

src/main/kotlin/com/lambda/context/AutomatedSafeContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ package com.lambda.context
2020
class AutomatedSafeContext(
2121
safeContext: SafeContext,
2222
automated: Automated
23-
) : SafeContext by safeContext, Automated by automated
23+
) : IAutomatedSafeContext, SafeContext by safeContext, Automated by automated
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.context
19+
20+
interface IAutomatedSafeContext : SafeContext, Automated

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface BreakConfig : RequestConfig {
4040
// abstract val desyncFix: Boolean
4141
val breakDelay: Int
4242

43-
val breakStageMask: Set<Event>
43+
val tickStageMask: Set<Event>
4444

4545
val swapMode: SwapMode
4646

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ object BreakManager : RequestHandler<BreakRequest>(
497497

498498
val breakInfo = BreakInfo(requestCtx, Primary, request)
499499
primaryBreak?.let { primaryInfo ->
500-
if (tickStage !in primaryInfo.breakConfig.breakStageMask) return null
500+
if (tickStage !in primaryInfo.breakConfig.tickStageMask) return null
501501

502502
if (!primaryInfo.breakConfig.doubleBreak || secondaryBreak != null) {
503503
if (!primaryInfo.updatedThisTick) {
@@ -543,7 +543,7 @@ object BreakManager : RequestHandler<BreakRequest>(
543543
breakInfos
544544
.filterNotNull()
545545
.asSequence()
546-
.filter { !it.updatedThisTick && tickStage in it.breakConfig.breakStageMask }
546+
.filter { !it.updatedThisTick && tickStage in it.breakConfig.tickStageMask }
547547
.forEach { info ->
548548
if (info.type == RedundantSecondary && !info.progressedThisTick) {
549549
val cachedState = info.context.cachedState
@@ -604,7 +604,7 @@ object BreakManager : RequestHandler<BreakRequest>(
604604
logger.debug("Updating pre-processing", this@updatePreProcessing)
605605

606606
shouldProgress = !progressedThisTick
607-
&& tickStage in breakConfig.breakStageMask
607+
&& tickStage in breakConfig.tickStageMask
608608
&& (rotated || type != Primary)
609609

610610
if (updatedPreProcessingThisTick) return

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import com.lambda.util.BlockUtils.isEmpty
2929
import net.minecraft.entity.ItemEntity
3030
import net.minecraft.util.math.BlockPos
3131

32-
data class BreakRequest(
32+
data class BreakRequest private constructor(
3333
val contexts: Collection<BreakContext>,
3434
val pendingInteractions: MutableCollection<BuildContext>,
3535
private val automated: Automated
@@ -67,63 +67,63 @@ data class BreakRequest(
6767
}
6868

6969
@DslMarker
70-
annotation class BreakRequestBuilder
70+
annotation class BreakRequestDsl
7171

72-
@BreakRequestBuilder
73-
class RequestBuilder(
72+
@BreakRequestDsl
73+
class BreakRequestBuilder(
7474
contexts: Collection<BreakContext>,
7575
pendingInteractions: MutableCollection<BuildContext>,
7676
automated: Automated
7777
) {
7878
val request = BreakRequest(contexts, pendingInteractions, automated)
7979

80-
@BreakRequestBuilder
80+
@BreakRequestDsl
8181
fun onStart(callback: (BlockPos) -> Unit) {
8282
request.onStart = callback
8383
}
8484

85-
@BreakRequestBuilder
85+
@BreakRequestDsl
8686
fun onUpdate(callback: (BlockPos) -> Unit) {
8787
request.onUpdate = callback
8888
}
8989

90-
@BreakRequestBuilder
90+
@BreakRequestDsl
9191
fun onStop(callback: (BlockPos) -> Unit) {
9292
request.onStop = callback
9393
}
9494

95-
@BreakRequestBuilder
95+
@BreakRequestDsl
9696
fun onCancel(callback: (BlockPos) -> Unit) {
9797
request.onCancel = callback
9898
}
9999

100-
@BreakRequestBuilder
100+
@BreakRequestDsl
101101
fun onItemDrop(callback: (ItemEntity) -> Unit) {
102102
request.onItemDrop = callback
103103
}
104104

105-
@BreakRequestBuilder
105+
@BreakRequestDsl
106106
fun onReBreakStart(callback: (BlockPos) -> Unit) {
107107
request.onReBreakStart = callback
108108
}
109109

110-
@BreakRequestBuilder
110+
@BreakRequestDsl
111111
fun onReBreak(callback: (BlockPos) -> Unit) {
112112
request.onReBreak = callback
113113
}
114-
115-
@BreakRequestBuilder
116-
fun build(): BreakRequest = request
117114
}
118115

119116
companion object {
120117
var requestCount = 0
121118

122-
@BreakRequestBuilder
119+
@BreakRequestDsl
123120
fun Automated.breakRequest(
124121
contexts: Collection<BreakContext>,
125122
pendingInteractions: MutableCollection<BuildContext>,
126-
builder: RequestBuilder.() -> Unit
127-
) = RequestBuilder(contexts, pendingInteractions, this).apply(builder).build()
123+
builder: (BreakRequestBuilder.() -> Unit)? = null
124+
) = BreakRequestBuilder(contexts, pendingInteractions, this).apply { builder?.invoke(this) }.build()
125+
126+
@BreakRequestDsl
127+
private fun BreakRequestBuilder.build(): BreakRequest = request
128128
}
129129
}

0 commit comments

Comments
 (0)