Skip to content

Commit c843833

Browse files
committed
InventoryResync module
1 parent b74674a commit c843833

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ package com.lambda.interaction.managers.inventory
2020
import com.lambda.context.Automated
2121
import com.lambda.context.SafeContext
2222
import com.lambda.interaction.managers.Request
23+
import com.lambda.util.PacketUtils.sendPacket
2324
import com.lambda.util.player.SlotUtils.clickSlot
25+
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
2426
import net.minecraft.item.ItemStack
27+
import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket
2528
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
2629
import net.minecraft.screen.slot.SlotActionType
30+
import net.minecraft.screen.sync.ItemStackHash
2731
import net.minecraft.util.Hand
2832
import net.minecraft.util.math.BlockPos
2933
import net.minecraft.util.math.Direction
@@ -63,6 +67,22 @@ class InventoryRequest private constructor(
6367
InventoryAction.Inventory { clickSlot(slotId, button, actionType) }.addToActions()
6468
}
6569

70+
@InvRequestDsl
71+
fun resyncInventory() {
72+
InventoryAction.Inventory {
73+
connection.sendPacket {
74+
val sh = player.currentScreenHandler
75+
ClickSlotC2SPacket(
76+
sh.syncId,
77+
-1, -1, 0,
78+
SlotActionType.CLONE,
79+
Int2ObjectOpenHashMap<ItemStackHash>(),
80+
ItemStackHash.fromItemStack(sh.cursorStack, connection.componentHasher)
81+
)
82+
}
83+
}.addToActions()
84+
}
85+
6686
@InvRequestDsl
6787
fun pickFromInventory(slotId: Int) {
6888
InventoryAction.Inventory {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2026 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.module.modules.player
19+
20+
import com.lambda.event.events.TickEvent
21+
import com.lambda.event.listener.SafeListener.Companion.listen
22+
import com.lambda.interaction.managers.inventory.InventoryRequest.Companion.inventoryRequest
23+
import com.lambda.module.Module
24+
import com.lambda.module.tag.ModuleTag
25+
import com.lambda.util.TickTimer
26+
27+
@Suppress("unused")
28+
object InventoryResync : Module(
29+
name = "InventoryResync",
30+
description = "Resyncs your inventory, with a delay between resyncs",
31+
tag = ModuleTag.PLAYER
32+
) {
33+
private val delay by setting("Delay", 100, 0..1000, 5, unit = " ticks")
34+
35+
private val timer = TickTimer()
36+
37+
init {
38+
setModulePriority(10)
39+
listen<TickEvent.Pre> {
40+
timer.tick()
41+
if (!timer.hasSurpassed(delay)) return@listen
42+
inventoryRequest {
43+
resyncInventory()
44+
}.submit()
45+
timer.reset()
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)