Skip to content

Commit 2550fd1

Browse files
authored
Inventory Manager!!!!!! (161)
1 parent f47349b commit 2550fd1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+516
-664
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/java/com/lambda/mixin/network/ClientPlayNetworkHandlerMixin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import com.lambda.event.EventFlow;
2121
import com.lambda.event.events.InventoryEvent;
2222
import com.lambda.event.events.WorldEvent;
23+
import com.lambda.interaction.request.inventory.InventoryManager;
2324
import com.lambda.module.modules.movement.Velocity;
2425
import com.lambda.module.modules.render.NoRender;
26+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
27+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2528
import net.minecraft.client.network.ClientPlayNetworkHandler;
2629
import net.minecraft.client.network.PlayerListEntry;
2730
import net.minecraft.network.packet.s2c.play.*;
@@ -103,4 +106,14 @@ public boolean onServerMetadata(ClientPlayNetworkHandler clientPlayNetworkHandle
103106
void injectVelocity(ExplosionS2CPacket packet, CallbackInfo ci) {
104107
if (Velocity.getExplosion() && Velocity.INSTANCE.isEnabled()) ci.cancel();
105108
}
109+
110+
@WrapMethod(method = "onScreenHandlerSlotUpdate")
111+
private void wrapOnScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet, Operation<Void> original) {
112+
InventoryManager.onSlotUpdate(packet, original);
113+
}
114+
115+
@WrapMethod(method = "onInventory")
116+
private void wrapOnInventory(InventoryS2CPacket packet, Operation<Void> original) {
117+
InventoryManager.onInventoryUpdate(packet, original);
118+
}
106119
}

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 Second", 100, 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, TickEvent.Input.Pre, TickEvent.Input.Post, TickEvent.Player.Post), 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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ object AutomationConfig : Configurable(LambdaConfig), Automated {
5959
override val hotbarConfig = HotbarSettings(this, Group.Hotbar)
6060
override val eatConfig = EatSettings(this, Group.Eat)
6161

62+
val avoidDesync by setting("Avoid Desync", true, "Cancels incoming inventory update packets if they match previous actions").group(Group.Debug)
63+
val maxDesyncCache by setting("Max Desync Cache", 30, 1..30, 1, "Maximum cached previous inventory actions") { avoidDesync }.group(Group.Debug)
64+
val desyncTimeout by setting("Desync Timeout", 30, 1..30, 1, unit = " ticks", description = "Time to store previous inventory actions before dropping the cache") { avoidDesync }.group(Group.Debug)
6265
val showAllEntries by setting("Show All Entries", false, "Show all entries in the task tree").group(Group.Debug)
6366
val shrinkFactor by setting("Shrink Factor", 0.001, 0.0..1.0, 0.001).group(Group.Debug)
6467
val ignoreItemDropWarnings by setting("Ignore Drop Warnings", false, "Hides the item drop warnings from the break manager").group(Group.Debug)

src/main/kotlin/com/lambda/interaction/material/transfer/TransferSelection.kt renamed to src/main/kotlin/com/lambda/context/IAutomatedSafeContext.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.interaction.material.transfer
18+
package com.lambda.context
1919

20-
class TransferSelection
20+
interface IAutomatedSafeContext : SafeContext, Automated

src/main/kotlin/com/lambda/interaction/material/container/containers/CreativeContainer.kt

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ package com.lambda.interaction.material.container.containers
1919

2020
import com.lambda.Lambda.mc
2121
import com.lambda.context.Automated
22-
import com.lambda.context.SafeContext
22+
import com.lambda.event.events.TickEvent
23+
import com.lambda.event.listener.SafeListener.Companion.listen
2324
import com.lambda.interaction.material.StackSelection
2425
import com.lambda.interaction.material.container.MaterialContainer
25-
import com.lambda.interaction.material.transfer.TransactionExecutor
26+
import com.lambda.interaction.request.inventory.InventoryRequest.Companion.inventoryRequest
2627
import com.lambda.task.Task
2728
import com.lambda.util.item.ItemStackUtils.equal
2829
import com.lambda.util.player.gamemode
@@ -41,57 +42,63 @@ data object CreativeContainer : MaterialContainer(Rank.Creative) {
4142
override fun spaceAvailable(selection: StackSelection): Int =
4243
if (mc.player?.isCreative == true && selection.optimalStack != null) Int.MAX_VALUE else 0
4344

44-
class CreativeDeposit @Ta5kBuilder constructor(val selection: StackSelection) : Task<Unit>() {
45+
class CreativeDeposit @Ta5kBuilder constructor(val selection: StackSelection, automated: Automated) : Task<Unit>(), Automated by automated {
4546
override val name: String get() = "Removing $selection from creative inventory"
4647

47-
override fun SafeContext.onStart() {
48-
if (!gamemode.isCreative) {
49-
// ToDo: Maybe switch gamemode?
50-
throw NotInCreativeModeException()
51-
}
48+
init {
49+
listen<TickEvent.Pre> {
50+
if (!gamemode.isCreative) {
51+
// ToDo: Maybe switch gamemode?
52+
throw NotInCreativeModeException()
53+
}
5254

53-
TransactionExecutor.transfer(player.currentScreenHandler) {
54-
player.currentScreenHandler?.slots?.let { slots ->
55-
selection.filterSlots(slots).forEach {
56-
clickCreativeStack(ItemStack.EMPTY, it.id)
55+
inventoryRequest {
56+
player.currentScreenHandler?.slots?.let { slots ->
57+
selection.filterSlots(slots).forEach {
58+
clickCreativeStack(ItemStack.EMPTY, it.id)
59+
}
5760
}
58-
}
59-
}.finally {
60-
success()
61-
}.execute(this@CreativeDeposit)
61+
onComplete { success() }
62+
}.submit(queueIfClosed = false)
63+
}
6264
}
6365
}
6466

6567
context(automated: Automated)
66-
override fun deposit(selection: StackSelection) = CreativeDeposit(selection)
68+
override fun deposit(selection: StackSelection) = CreativeDeposit(selection, automated)
6769

68-
class CreativeWithdrawal @Ta5kBuilder constructor(val selection: StackSelection) : Task<Unit>() {
70+
class CreativeWithdrawal @Ta5kBuilder constructor(val selection: StackSelection, automated: Automated) : Task<Unit>(), Automated by automated {
6971
override val name: String get() = "Withdrawing $selection from creative inventory"
7072

71-
override fun SafeContext.onStart() {
72-
selection.optimalStack?.let { optimalStack ->
73-
if (player.mainHandStack.equal(optimalStack)) return
73+
init {
74+
listen<TickEvent.Pre> {
75+
selection.optimalStack?.let { optimalStack ->
76+
if (player.mainHandStack.equal(optimalStack)) {
77+
success()
78+
return@listen
79+
}
7480

75-
if (!gamemode.isCreative) {
76-
// ToDo: Maybe switch gamemode?
77-
throw NotInCreativeModeException()
81+
if (!gamemode.isCreative) {
82+
// ToDo: Maybe switch gamemode?
83+
throw NotInCreativeModeException()
84+
}
85+
86+
inventoryRequest {
87+
clickCreativeStack(optimalStack, 36 + player.inventory.selectedSlot)
88+
action { player.inventory.selectedStack = optimalStack }
89+
onComplete { success() }
90+
}.submit(queueIfClosed = false)
91+
return@listen
7892
}
7993

80-
TransactionExecutor.transfer(player.currentScreenHandler) {
81-
clickCreativeStack(optimalStack, 36 + player.inventory.selectedSlot)
82-
}.finally {
83-
success()
84-
}.execute(this@CreativeWithdrawal)
85-
return
94+
throw NoOptimalStackException()
8695
}
87-
88-
throw NoOptimalStackException()
8996
}
9097
}
9198

9299
// Withdraws items from the creative menu to the player's main hand
93100
context(automated: Automated)
94-
override fun withdraw(selection: StackSelection) = CreativeWithdrawal(selection)
101+
override fun withdraw(selection: StackSelection) = CreativeWithdrawal(selection, automated)
95102

96103
class NotInCreativeModeException : IllegalStateException("Insufficient permission: not in creative mode")
97104
class NoOptimalStackException : IllegalStateException("Cannot move item: no optimal stack")

0 commit comments

Comments
 (0)