Skip to content

Commit 78c5250

Browse files
committed
Merge branch '1.21.5' into improvement/place-interact-merge
2 parents 340bb77 + 5b9e76e commit 78c5250

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/main/kotlin/com/lambda/interaction/managers/inventory/InventoryManager.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ object InventoryManager : Manager<InventoryRequest>(
5858
private var actions = mutableListOf<InventoryAction>()
5959

6060
private var slots = listOf<ItemStack>()
61-
private var alteredSlots = LimitedDecayQueue<InventoryChange>(
62-
Int.MAX_VALUE, DEFAULT.desyncTimeout * 50L
63-
)
61+
private var alteredSlots = LimitedDecayQueue<InventoryChange>(Int.MAX_VALUE, DEFAULT.desyncTimeout * 50L)
62+
private var alteredPlayerSlots = LimitedDecayQueue<InventoryChange>(Int.MAX_VALUE, DEFAULT.desyncTimeout * 50L)
6463

6564
private var screenHandler: ScreenHandler? = null
6665
set(value) {
@@ -92,10 +91,8 @@ object InventoryManager : Manager<InventoryRequest>(
9291
actions = mutableListOf()
9392
}
9493

95-
listen<PacketEvent.Send.Pre> { event ->
96-
if (event.packet is CloseHandledScreenC2SPacket &&
97-
event.packet.syncId != player.currentScreenHandler.syncId
98-
) {
94+
listen<PacketEvent.Send.Post> { event ->
95+
if (event.packet is CloseHandledScreenC2SPacket) {
9996
screenHandler = player.playerScreenHandler
10097
}
10198
}
@@ -133,6 +130,7 @@ object InventoryManager : Manager<InventoryRequest>(
133130
actions = request.actions.toMutableList()
134131
maxActionsThisSecond = request.inventoryConfig.actionsPerSecond
135132
alteredSlots.setDecayTime(DEFAULT.desyncTimeout * 50L)
133+
alteredPlayerSlots.setDecayTime(DEFAULT.desyncTimeout * 50L)
136134
}
137135

138136
/**
@@ -178,7 +176,8 @@ object InventoryManager : Manager<InventoryRequest>(
178176
?.filter { !it.stack.equal(slots[it.id]) }
179177
?.map { InventoryChange(it.id, slots[it.id], it.stack.copy()) }
180178
?: emptyList()
181-
alteredSlots.addAll(changes)
179+
if (player.currentScreenHandler.syncId == 0) alteredPlayerSlots.addAll(changes)
180+
else alteredSlots.addAll(changes)
182181
slots = getStacks(player.currentScreenHandler.slots)
183182
}
184183

@@ -203,6 +202,7 @@ object InventoryManager : Manager<InventoryRequest>(
203202
else -> return@runSafe
204203
}
205204
val alteredContents = mutableListOf<ItemStack>()
205+
val alteredSlots = if (packet.syncId == 0) alteredPlayerSlots else alteredSlots
206206
packet.contents.forEachIndexed { index, incomingStack ->
207207
val matches = alteredSlots.removeIf { cached ->
208208
incomingStack.equal(cached.after)
@@ -235,6 +235,7 @@ object InventoryManager : Manager<InventoryRequest>(
235235
!it.isInventoryTabSelected
236236
} ?: false
237237

238+
val alteredSlots = if (packet.syncId == 0) alteredPlayerSlots else alteredSlots
238239
val matches = alteredSlots.removeIf {
239240
it.syncId == packet.slot && it.after.equal(itemStack)
240241
}

src/main/kotlin/com/lambda/module/modules/combat/AutoTotem.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ import com.lambda.event.events.TickEvent
2323
import com.lambda.event.listener.SafeListener.Companion.listen
2424
import com.lambda.friend.FriendManager
2525
import com.lambda.interaction.material.StackSelection.Companion.select
26-
import com.lambda.interaction.material.container.ContainerManager.transfer
27-
import com.lambda.interaction.material.container.containers.OffHandContainer
26+
import com.lambda.interaction.request.inventory.InventoryRequest.Companion.inventoryRequest
2827
import com.lambda.module.Module
2928
import com.lambda.module.tag.ModuleTag
30-
import com.lambda.task.RootTask.run
31-
import com.lambda.util.Communication.info
3229
import com.lambda.util.NamedEnum
3330
import com.lambda.util.combat.CombatUtils.hasDeadlyCrystal
3431
import com.lambda.util.combat.DamageUtils.isFallDeadly
@@ -64,9 +61,13 @@ object AutoTotem : Module(
6461

6562
if ((!ignoreWhenHolding || !player.isHolding(Items.TOTEM_OF_UNDYING)) && player.offHandStack.item != Items.TOTEM_OF_UNDYING) {
6663
Items.TOTEM_OF_UNDYING.select()
67-
.transfer(OffHandContainer)
68-
?.finally { if (log) info("Swapped the off-hand item with a totem") }
69-
?.run()
64+
.filterSlots(player.currentScreenHandler.slots)
65+
.takeIf { it.isNotEmpty() }
66+
?.let { totems ->
67+
inventoryRequest {
68+
swap(totems.first().id, 40)
69+
}.submit()
70+
}
7071
}
7172
}
7273
}

0 commit comments

Comments
 (0)