Skip to content

Commit 09693ed

Browse files
committed
Add compatibility with Operation.kt
1 parent bccc544 commit 09693ed

File tree

4 files changed

+83
-114
lines changed

4 files changed

+83
-114
lines changed

src/main/kotlin/com/lambda/client/manager/managers/PlayerInventoryManager.kt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import net.minecraft.network.play.server.SPacketConfirmTransaction
2525
import java.util.*
2626
import java.util.concurrent.ConcurrentSkipListSet
2727

28+
/**
29+
* @see NoGhostItems
30+
*/
2831
object PlayerInventoryManager : Manager {
2932
val timer = TickTimer()
3033
private val transactionQueue = ConcurrentSkipListSet<InventoryTask>(Comparator.reverseOrder())
@@ -76,8 +79,6 @@ object PlayerInventoryManager : Manager {
7679
return@safeListener
7780
}
7881

79-
if (NoGhostItems.baritoneSync) NoGhostItems.pauseBaritone()
80-
8182
transactionQueue.firstOrNull()?.let { currentTask ->
8283
currentTask.currentInfo()?.let { currentInfo ->
8384
if (currentInfo.transactionId < 0 || timer.tick(NoGhostItems.timeout, false)) {
@@ -103,7 +104,7 @@ object PlayerInventoryManager : Manager {
103104
if (transactionId > -1) {
104105
currentInfo.transactionId = transactionId
105106
currentInfo.tries++
106-
LambdaMod.LOG.info("Transaction successfully initiated. $currentInfo")
107+
LambdaMod.LOG.info("Transaction successfully initiated. ${transactionQueue.size} left. $currentInfo")
107108
} else {
108109
LambdaMod.LOG.error("Container outdated. Skipping task. $currentInfo")
109110
next()
@@ -123,10 +124,7 @@ object PlayerInventoryManager : Manager {
123124
transactionID = activeContainer.getNextTransactionID(inventory)
124125

125126
val itemStack = if (currentInfo.type == ClickType.PICKUP && currentInfo.slot != -999) {
126-
getContainerOrNull(currentInfo.windowId)
127-
?.inventorySlots
128-
?.getOrNull(currentInfo.slot)
129-
?.stack ?: ItemStack.EMPTY
127+
activeContainer.inventorySlots?.getOrNull(currentInfo.slot)?.stack ?: ItemStack.EMPTY
130128
} else {
131129
ItemStack.EMPTY
132130
}
@@ -144,22 +142,19 @@ object PlayerInventoryManager : Manager {
144142
onMainThreadSafe { playerController.updateController() }
145143
}
146144
}
145+
} ?: run {
146+
LambdaMod.LOG.error("Container outdated. Skipping task. $currentInfo")
147+
next()
147148
}
148149

149150
return transactionID
150151
}
151152

152153
private fun SafeClientEvent.getContainerOrNull(windowId: Int): Container? =
153-
when (windowId) {
154-
player.inventoryContainer.windowId -> {
155-
player.inventoryContainer
156-
}
157-
player.openContainer.windowId -> {
158-
player.openContainer
159-
}
160-
else -> {
161-
null
162-
}
154+
if (windowId == player.openContainer.windowId) {
155+
player.openContainer
156+
} else {
157+
null
163158
}
164159

165160
fun next() {
@@ -179,8 +174,16 @@ object PlayerInventoryManager : Manager {
179174
*
180175
* @return [TaskState] representing the state of this task
181176
*/
182-
fun AbstractModule.addInventoryTask(vararg clickInfo: ClickInfo) =
183-
InventoryTask(currentId++, modulePriority, clickInfo).let {
177+
fun AbstractModule.addInventoryTask(vararg clickInfo: ClickInfo): TaskState {
178+
if (NoGhostItems.baritoneSync) NoGhostItems.pauseBaritone()
179+
return InventoryTask(currentId++, modulePriority, clickInfo).let {
180+
transactionQueue.add(it)
181+
it.taskState
182+
}
183+
}
184+
185+
fun addInventoryTask(vararg clickInfo: ClickInfo) =
186+
InventoryTask(currentId++, 0, clickInfo).let {
184187
transactionQueue.add(it)
185188
it.taskState
186189
}

src/main/kotlin/com/lambda/client/module/modules/combat/AutoOffhand.kt

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ object AutoOffhand : Module(
7171
// General
7272
private val priority by setting("Priority", Priority.HOTBAR)
7373
private val switchMessage by setting("Switch Message", true)
74-
private val delay by setting("Delay", 2, 1..20, 1,
75-
description = "Ticks to wait between each move")
76-
private val confirmTimeout by setting("Confirm Timeout", 5, 1..20, 1,
77-
description = "Maximum ticks to wait for confirm packets from server")
7874

7975
private enum class Type(val filter: (ItemStack) -> Boolean) {
8076
TOTEM({ it.item.id == 449 }),
@@ -88,9 +84,6 @@ object AutoOffhand : Module(
8884
HOTBAR, INVENTORY
8985
}
9086

91-
private val transactionLog = HashMap<Short, Boolean>()
92-
private val confirmTimer = TickTimer(TimeUnit.TICKS)
93-
private val movingTimer = TickTimer(TimeUnit.TICKS)
9487
private var maxDamage = 0f
9588

9689
init {
@@ -104,32 +97,11 @@ object AutoOffhand : Module(
10497
}
10598
}
10699

107-
safeListener<PacketEvent.Receive> {
108-
if (it.packet !is SPacketConfirmTransaction || it.packet.windowId != 0 || !transactionLog.containsKey(it.packet.actionNumber)) return@safeListener
109-
110-
transactionLog[it.packet.actionNumber] = true
111-
if (!transactionLog.containsValue(false)) {
112-
confirmTimer.reset(confirmTimeout * -50L) // If all the click packets were accepted then we reset the timer for next moving
113-
}
114-
}
115-
116100
safeListener<TickEvent.ClientTickEvent>(1100) {
117101
if (player.isDead || player.health <= 0.0f) return@safeListener
118102

119-
if (!confirmTimer.tick(confirmTimeout.toLong(), false)) return@safeListener
120-
if (!movingTimer.tick(delay.toLong(), false)) return@safeListener // Delays `delay` ticks
121-
122103
updateDamage()
123104

124-
if (!player.inventory.itemStack.isEmpty) { // If player is holding an in inventory
125-
if (mc.currentScreen is GuiContainer) { // If inventory is open (playing moving item)
126-
movingTimer.reset() // reset movingTimer as the user is currently interacting with the inventory.
127-
} else { // If inventory is not open (ex. inventory desync)
128-
removeHoldingItem()
129-
}
130-
return@safeListener
131-
}
132-
133105
switchToType(getType(), true)
134106
}
135107
}
@@ -169,15 +141,7 @@ object AutoOffhand : Module(
169141
getItemSlot(typeOriginal, attempts)?.let { (slot, typeAlt) ->
170142
if (slot == player.offhandSlot) return
171143

172-
transactionLog.clear()
173-
moveToSlot(slot, player.offhandSlot).forEach {
174-
transactionLog[it] = false
175-
}
176-
177-
playerController.updateController()
178-
179-
confirmTimer.reset()
180-
movingTimer.reset()
144+
moveToSlot(slot, player.offhandSlot)
181145

182146
if (switchMessage) MessageSendHelper.sendChatMessage("$chatName Offhand now has a ${typeAlt.toString().lowercase()}")
183147
}

src/main/kotlin/com/lambda/client/module/modules/player/NoGhostItems.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ object NoGhostItems : Module(
1717
description = "Syncs inventory transactions for strict environments",
1818
category = Category.PLAYER
1919
) {
20-
private val syncMode by setting("Scope", SyncMode.ALL)
20+
val syncMode by setting("Scope", SyncMode.ALL)
2121
val baritoneSync by setting("Baritone pause", true, description = "Pauses Baritone until transaction is complete.")
22-
val timeout by setting("Timeout in ms", 250, 1..2500, 25)
23-
val maxRetries by setting("Max retries", 3, 0..20, 1)
22+
val timeout by setting("Timeout in ms", 800, 1..2500, 25)
23+
val maxRetries by setting("Max retries", 8, 0..20, 1)
2424
private val clearQueue = setting("Clear Transaction Queue", false)
2525

2626
enum class SyncMode {

0 commit comments

Comments
 (0)