InventoryTracker module

InventoryTracker: Minecraft 26.3 cheat module, full source for every implementation (1 client: LiquidBounce (Kotlin)).

1 implementationWORLD

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

LiquidBounce (Kotlin)WORLDsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleInventoryTracker.ktKotlin · 162 lines · 6.2 KB

Tracks the inventories of other players.

SettingsSavePlayers
ModuleInventoryTracker.ktKotlin · Minecraft 26.2 · 162 lines · 6.2 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.misc
20
21
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap
22
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
23
import net.ccbluex.liquidbounce.event.events.EntityEquipmentChangeEvent
24
import net.ccbluex.liquidbounce.event.events.ItemLoreQueryEvent
25
import net.ccbluex.liquidbounce.event.events.WorldChangeEvent
26
import net.ccbluex.liquidbounce.event.handler
27
import net.ccbluex.liquidbounce.features.command.commands.module.CommandInvsee
28
import net.ccbluex.liquidbounce.features.module.ClientModule
29
import net.ccbluex.liquidbounce.features.module.ModuleCategories
30
import net.ccbluex.liquidbounce.features.module.modules.misc.antibot.ModuleAntiBot
31
import net.ccbluex.liquidbounce.utils.inventory.ViewedInventoryScreen
32
import net.ccbluex.liquidbounce.utils.text.asPlainText
33
import net.minecraft.ChatFormatting
34
import net.minecraft.client.player.RemotePlayer
35
import net.minecraft.world.entity.EquipmentSlot
36
import net.minecraft.world.entity.EquipmentSlot.MAINHAND
37
import net.minecraft.world.entity.EquipmentSlot.OFFHAND
38
import net.minecraft.world.entity.EquipmentSlot.Type.ANIMAL_ARMOR
39
import net.minecraft.world.entity.EquipmentSlot.Type.HAND
40
import net.minecraft.world.entity.EquipmentSlot.Type.HUMANOID_ARMOR
41
import net.minecraft.world.entity.player.Player
42
import net.minecraft.world.item.ItemStack
43
import java.util.Locale
44
import java.util.UUID
45
46
/**
47
 * Module InventoryTracker
48
 *
49
 * Tracks the inventories of other players.
50
 *
51
 * Command: [CommandInvsee]
52
 */
53
object ModuleInventoryTracker : ClientModule("InventoryTracker", ModuleCategories.WORLD) {
54
55
    /** Saves the non-persistent player object associated with the uuid.
56
     * This makes it possible to look up inventories of players which aren't in
57
     * the render distance. */
58
    private val savePlayers by boolean("SavePlayers", false).onChanged { playerMap.clear() }
59
60
    private val inventoryMap = Object2ObjectOpenHashMap<UUID, TrackedInventory>()
61
    val playerMap = Object2ObjectOpenHashMap<UUID, Player>()
62
63
    @Suppress("unused")
64
    val playerEquipmentChangeHandler = handler<EntityEquipmentChangeEvent> { event ->
65
        val player = event.entity
66
        if (player !is RemotePlayer || ModuleAntiBot.isBot(player)) return@handler
67
68
        val updatedSlot = event.equipmentSlot
69
        if (updatedSlot.type === ANIMAL_ARMOR) return@handler
70
71
        val newItemStack = event.itemStack
72
73
        val mainHandStack = if (updatedSlot === MAINHAND) newItemStack else player.mainHandItem
74
        val offHandStack = if (updatedSlot === OFFHAND) newItemStack else player.offhandItem
75
76
        val trackedInventory = inventoryMap.getOrPut(player.uuid) { TrackedInventory() }
77
        if (savePlayers) {
78
            playerMap[player.uuid] = player
79
        }
80
81
        when (updatedSlot.type) {
82
            HAND -> {
83
                trackedInventory.update(offHandStack, OFFHAND)
84
                trackedInventory.update(mainHandStack, MAINHAND)
85
            }
86
            HUMANOID_ARMOR -> trackedInventory.update(newItemStack, updatedSlot)
87
            else -> {}
88
        }
89
90
        val inventory = player.inventory
91
        val items = trackedInventory.items
92
93
        val mainHandEmpty = mainHandStack.isEmpty
94
        val range = if (mainHandEmpty) 0..34 else 1..35
95
        val offset = if (mainHandEmpty) 1 else 0
96
97
        for (i in range) {
98
            inventory.nonEquipmentItems[i + offset] = items.getOrNull(i) ?: ItemStack.EMPTY
99
        }
100
    }
101
102
    override fun onDisabled() = reset()
103
104
    @Suppress("unused")
105
    private val worldChangeHandler = handler<WorldChangeEvent> { reset() }
106
107
    private fun reset() {
108
        val players = world.players().associateBy { it.uuid }
109
        inventoryMap.keys.forEach { uuid ->
110
            val player = players[uuid] ?: return@forEach
111
            for (i in 1 until player.inventory.nonEquipmentItems.size) {
112
                player.inventory.nonEquipmentItems[i] = ItemStack.EMPTY
113
            }
114
        }
115
        inventoryMap.clear()
116
        playerMap.clear()
117
    }
118
119
    @Suppress("unused")
120
    private val itemLoreQueryHandler = handler<ItemLoreQueryEvent> { event ->
121
        if (mc.gui.screen() !is ViewedInventoryScreen) return@handler
122
        val player = CommandInvsee.viewedPlayer
123
        val timeStamp = inventoryMap[player]?.timeMap?.getLong(event.itemStack)?.takeIf { it != 0L } ?: return@handler
124
        val lastSeen = System.currentTimeMillis() - timeStamp
125
        event.lore.add(
126
            "Last Seen: ${toMinutesSeconds(lastSeen)}".asPlainText(ChatFormatting.GRAY)
127
        )
128
    }
129
130
    private fun toMinutesSeconds(ms: Long): String {
131
        val totalSeconds = ms / 1000
132
        val minutes = (totalSeconds % 3600) / 60
133
        val seconds = totalSeconds % 60
134
        return "%02d:%02d".format(Locale.US, minutes, seconds)
135
    }
136
}
137
138
private class TrackedInventory {
139
140
    val items = ArrayDeque<ItemStack>()
141
    val timeMap = Object2LongOpenHashMap<ItemStack>()
142
143
    /**
144
     * if slot type is armor then we check if the item is already in the tracked items
145
     * and if yes we remove it because it has been equipped
146
     */
147
    fun update(newItemStack: ItemStack, updatedSlot: EquipmentSlot) {
148
        items.removeIf { it.count == 0 }
149
        if (newItemStack.isEmpty) return
150
151
        items.removeIf { newItemStack.item == it.item && newItemStack.enchantments == it.enchantments }
152
        if (updatedSlot.type === HAND) {
153
            items.addFirst(newItemStack)
154
            timeMap.put(newItemStack, System.currentTimeMillis())
155
156
            if (items.size > 36) {
157
                items.removeLast()
158
            }
159
        }
160
    }
161
}
162