Skip to content

Commit d1e0c66

Browse files
committed
Stack selection container transfer fixes
1 parent c813e30 commit d1e0c66

File tree

14 files changed

+96
-77
lines changed

14 files changed

+96
-77
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lambda.command.commands
2+
3+
import com.lambda.brigadier.execute
4+
import com.lambda.command.LambdaCommand
5+
import com.lambda.interaction.material.ContainerManager.transfer
6+
import com.lambda.interaction.material.StackSelection.Companion.select
7+
import com.lambda.interaction.material.container.MainHandContainer
8+
import com.lambda.util.primitives.extension.CommandBuilder
9+
import net.minecraft.item.Items
10+
11+
object TransferCommand : LambdaCommand(
12+
name = "transfer",
13+
usage = "transfer <item> <amount> <to>",
14+
description = "Transfer items to a container"
15+
) {
16+
override fun CommandBuilder.create() {
17+
execute {
18+
Items.OBSIDIAN.select().transfer(MainHandContainer).solve.start(null)
19+
}
20+
}
21+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data class BreakContext(
1414
val result: BlockHitResult,
1515
val rotation: RotationContext,
1616
val checkedState: BlockState,
17-
val hand: Hand,
17+
var hand: Hand,
1818
val instantBreak: Boolean,
1919
) : BuildContext, ComparableContext {
2020
override val distance: Double by lazy {

common/src/main/kotlin/com/lambda/interaction/construction/result/BreakResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package com.lambda.interaction.construction.result
22

33
import com.lambda.interaction.construction.context.BreakContext
44
import com.lambda.interaction.material.ContainerManager.findBestAvailableTool
5+
import com.lambda.interaction.material.ContainerManager.transfer
56
import com.lambda.interaction.material.StackSelection.Companion.select
67
import com.lambda.interaction.material.StackSelection.Companion.selectStack
7-
import com.lambda.interaction.material.container.CreativeContainer.transfer
88
import com.lambda.interaction.material.container.MainHandContainer
99
import com.lambda.task.Task
1010
import com.lambda.task.Task.Companion.emptyTask

common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ object ContainerManager : Loadable {
7070
}
7171
}
7272

73+
fun StackSelection.transfer(destination: MaterialContainer) =
74+
findContainerWithSelection(this)?.transfer(this, destination)
75+
?: throw NoContainerFound(this)
76+
7377
fun findContainer(
7478
block: (MaterialContainer) -> Boolean
7579
): MaterialContainer? = container.find(block)

common/src/main/kotlin/com/lambda/interaction/material/MaterialContainer.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@ abstract class MaterialContainer(
5252
open fun spaceLeft(selection: StackSelection) =
5353
filter(selection).spaceLeft + stacks.empty * selection.stackSize
5454

55-
fun StackSelection.transfer(destination: MaterialContainer): TransferResult {
56-
val amount = available(this)
57-
if (amount < count) {
58-
return TransferResult.MissingItems(amount - count)
55+
fun transfer(selection: StackSelection, destination: MaterialContainer): TransferResult {
56+
val amount = available(selection)
57+
if (amount < selection.count) {
58+
return TransferResult.MissingItems(amount - selection.count)
5959
}
6060

61-
val space = destination.spaceLeft(this)
62-
if (space == 0) {
63-
return TransferResult.NoSpace
64-
}
61+
// val space = destination.spaceLeft(selection)
62+
// if (space == 0) {
63+
// return TransferResult.NoSpace
64+
// }
6565

66-
val transferAmount = minOf(amount, space)
67-
selector = { true }
68-
count = transferAmount
66+
// val transferAmount = minOf(amount, space)
67+
// selection.selector = { true }
68+
// selection.count = transferAmount
6969

7070
return TransferResult.Success(
7171
prepare().onSuccess { prep, _ ->
72-
withdraw(this@transfer).onSuccess { with, _ ->
72+
withdraw(selection).onSuccess { with, _ ->
7373
destination.prepare().onSuccess { dest, _ ->
74-
destination.deposit(this@transfer).start(dest)
74+
destination.deposit(selection).start(dest)
7575
}.start(with)
7676
}.start(prep)
7777
}

common/src/main/kotlin/com/lambda/interaction/material/container/ChestContainer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ data class ChestContainer(
3030

3131
override fun withdraw(selection: StackSelection) =
3232
openContainer<GenericContainerScreenHandler>(blockPos)
33-
.withMaxAttempts(3)
34-
.withTimeout(20)
33+
// .withMaxAttempts(3)
34+
// .withTimeout(20)
3535
.onSuccess { open, screen ->
3636
info("Withdrawing $selection from ${screen.type}")
3737
withdraw(screen, selection).start(open)
3838
}
3939

4040
override fun deposit(selection: StackSelection) =
4141
openContainer<GenericContainerScreenHandler>(blockPos)
42-
.withMaxAttempts(3)
43-
.withTimeout(20)
42+
// .withMaxAttempts(3)
43+
// .withTimeout(20)
4444
.onSuccess { open, screen ->
4545
info("Depositing $selection to ${screen.type}")
4646
deposit(screen, selection).start(open)

common/src/main/kotlin/com/lambda/interaction/material/container/HotbarContainer.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import com.lambda.Lambda.mc
44
import com.lambda.interaction.material.MaterialContainer
55
import com.lambda.interaction.material.StackSelection
66
import com.lambda.task.Task
7+
import com.lambda.task.Task.Companion.emptyTask
8+
import com.lambda.task.tasks.InventoryTask.Companion.deposit
79
import com.lambda.util.player.SlotUtils.hotbar
10+
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider
811
import net.minecraft.item.ItemStack
912

1013
object HotbarContainer : MaterialContainer(Rank.HOTBAR) {
1114
override var stacks: List<ItemStack>
1215
get() = mc.player?.hotbar ?: emptyList()
1316
set(_) {}
1417

15-
override fun withdraw(selection: StackSelection): Task<*> {
16-
TODO("Not yet implemented")
17-
}
18+
override fun withdraw(selection: StackSelection) = emptyTask("HotbarWithdraw")
1819

1920
override fun deposit(selection: StackSelection): Task<*> {
20-
TODO("Not yet implemented")
21+
val handledScreen = mc.currentScreen as? ScreenHandlerProvider<*> ?: return emptyTask()
22+
return deposit(handledScreen.screenHandler, selection)
2123
}
2224
}

common/src/main/kotlin/com/lambda/interaction/material/container/InventoryContainer.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ object InventoryContainer : MaterialContainer(Rank.INVENTORY) {
1212
get() = mc.player?.combined ?: emptyList()
1313
set(_) {}
1414

15-
override fun withdraw(selection: StackSelection): Task<*> {
16-
TODO("Not yet implemented")
17-
}
15+
override fun withdraw(selection: StackSelection) = Task.emptyTask()
1816

19-
override fun deposit(selection: StackSelection): Task<*> {
20-
TODO("Not yet implemented")
21-
}
17+
override fun deposit(selection: StackSelection) = Task.emptyTask()
2218
}

common/src/main/kotlin/com/lambda/interaction/material/container/MainHandContainer.kt

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.lambda.interaction.material.MaterialContainer
55
import com.lambda.interaction.material.StackSelection
66
import com.lambda.module.modules.client.TaskFlow
77
import com.lambda.task.Task
8+
import com.lambda.task.Task.Companion.buildTask
9+
import com.lambda.task.Task.Companion.emptyTask
810
import com.lambda.util.player.SlotUtils.combined
911
import com.lambda.util.player.SlotUtils.hotbar
1012
import kotlinx.coroutines.delay
@@ -18,38 +20,31 @@ object MainHandContainer : MaterialContainer(Rank.MAIN_HAND) {
1820
get() = mc.player?.mainHandStack?.let { listOf(it) } ?: emptyList()
1921
set(_) {}
2022

21-
override fun withdraw(selection: StackSelection): Task<*> {
22-
TODO("Not yet implemented")
23-
}
24-
// InventoryContainer.stacks.filter(selection.selector).take(selection.count).forEach { stack ->
25-
// if (ItemStack.areEqual(stack, player.mainHandStack)) {
26-
// return@forEach
27-
// }
28-
//
29-
// if (ItemStack.areEqual(stack, player.offHandStack)) {
30-
// connection.sendPacket(
31-
// PlayerActionC2SPacket(
32-
// PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND,
33-
// BlockPos.ORIGIN,
34-
// Direction.DOWN,
35-
// ),
36-
// )
37-
// delay(TaskFlow.itemMoveDelay)
38-
// return@forEach
39-
// }
40-
//
41-
// if (stack in player.hotbar) {
42-
// player.inventory.selectedSlot = player.hotbar.indexOf(stack)
43-
// delay(TaskFlow.itemMoveDelay)
44-
// return@forEach
45-
// }
46-
//
47-
// interaction.pickFromInventory(player.combined.indexOf(stack))
48-
// delay(TaskFlow.itemMoveDelay)
49-
// }
50-
// }
23+
override fun withdraw(selection: StackSelection) = emptyTask("WithdrawFromMainHand")
24+
25+
override fun deposit(selection: StackSelection) = buildTask("DepositToMainHand") {
26+
InventoryContainer.filter(selection).firstOrNull()?.let { stack ->
27+
if (ItemStack.areEqual(stack, player.mainHandStack)) {
28+
return@buildTask
29+
}
30+
31+
if (ItemStack.areEqual(stack, player.offHandStack)) {
32+
connection.sendPacket(
33+
PlayerActionC2SPacket(
34+
PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND,
35+
BlockPos.ORIGIN,
36+
Direction.DOWN,
37+
),
38+
)
39+
return@buildTask
40+
}
41+
42+
if (stack in player.hotbar) {
43+
player.inventory.selectedSlot = player.hotbar.indexOf(stack)
44+
return@buildTask
45+
}
5146

52-
override fun deposit(selection: StackSelection): Task<*> {
53-
TODO("Not yet implemented")
47+
interaction.pickFromInventory(player.combined.indexOf(stack))
48+
}
5449
}
5550
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import com.lambda.task.Task
88
import com.lambda.task.Task.Companion.emptyTask
99
import com.lambda.task.tasks.BuildStructure.Companion.buildStructure
1010
import com.lambda.util.BlockUtils.blockPos
11-
import com.lambda.util.BlockUtils.instantBreakable
12-
import com.lambda.util.BlockUtils.safeLiquid
1311
import com.lambda.util.BlockUtils.blockState
12+
import com.lambda.util.BlockUtils.instantBreakable
1413
import com.lambda.util.KeyCode
1514
import net.minecraft.util.math.BlockPos
1615
import net.minecraft.util.math.Vec3i
@@ -23,7 +22,6 @@ object Nuker : Module(
2322
) {
2423
private val flatten by setting("Flatten", true)
2524
private val onlyBreakInstant by setting("Only Break Instant", true)
26-
private val doNotExposeLiquids by setting("Do Not Expose Liquids", true)
2725
private val fillFloor by setting("Fill Floor", false)
2826

2927
private val range = Vec3i(4, 4, 4) // TODO: Customizable
@@ -42,7 +40,6 @@ object Nuker : Module(
4240
.filter { !world.isAir(it) }
4341
.filter { !flatten || it.y >= player.blockPos.y }
4442
.filter { !onlyBreakInstant || instantBreakable(it.blockState(world), it) }
45-
.filter { !doNotExposeLiquids || safeLiquid(it) }
4643
.associateWith { TargetState.Air }
4744

4845
// if (fillFloor) {

0 commit comments

Comments
 (0)