ItemTags module

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

1 implementationRENDER

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)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleItemTags.ktKotlin · 247 lines · 9.2 KB

Display icons and quantities labels for dropped items.

SettingsFilterItemsBackgroundColorRenderOffsetRowLengthPreventOverlapMergeModeMergeStacksShowTitle
ModuleItemTags.ktKotlin · Minecraft 26.2 · 247 lines · 9.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.render
20
21
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
22
import it.unimi.dsi.fastutil.objects.ObjectArrayList
23
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
24
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
25
import net.ccbluex.fastutil.fastIterator
26
import net.ccbluex.fastutil.mapToArray
27
import net.ccbluex.liquidbounce.config.types.CurveValue.Axis.Companion.axis
28
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
29
import net.ccbluex.liquidbounce.config.types.list.Tagged
30
import net.ccbluex.liquidbounce.event.computedOn
31
import net.ccbluex.liquidbounce.event.events.GameTickEvent
32
import net.ccbluex.liquidbounce.event.events.OverlayRenderEvent
33
import net.ccbluex.liquidbounce.event.events.WorldChangeEvent
34
import net.ccbluex.liquidbounce.event.handler
35
import net.ccbluex.liquidbounce.features.module.ClientModule
36
import net.ccbluex.liquidbounce.features.module.ModuleCategories
37
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemAndComponents
38
import net.ccbluex.liquidbounce.render.gui.ItemStackListRenderer.drawItemStackList
39
import net.ccbluex.liquidbounce.render.engine.type.Color4b
40
import net.ccbluex.liquidbounce.utils.collection.Filter
41
import net.ccbluex.liquidbounce.utils.collection.itemSortedSetOf
42
import net.ccbluex.liquidbounce.utils.entity.cameraDistance
43
import net.ccbluex.liquidbounce.utils.entity.interpolateCurrentPosition
44
import net.ccbluex.liquidbounce.utils.item.COMPARING_DESCRIPTION_ID
45
import net.ccbluex.liquidbounce.utils.item.PreferStackSize
46
import net.ccbluex.liquidbounce.utils.kotlin.toTypedArray
47
import net.ccbluex.liquidbounce.utils.math.average
48
import net.ccbluex.liquidbounce.utils.math.sq
49
import net.ccbluex.liquidbounce.utils.render.WorldToScreen
50
import net.ccbluex.liquidbounce.utils.world.entityGetter
51
import net.ccbluex.liquidbounce.utils.world.filter
52
import net.minecraft.core.component.DataComponents
53
import net.minecraft.world.entity.Entity
54
import net.minecraft.world.entity.EntityTypes
55
import net.minecraft.world.entity.item.ItemEntity
56
import net.minecraft.world.item.Item
57
import net.minecraft.world.item.ItemStack
58
import net.minecraft.world.phys.Vec3
59
import org.joml.Vector2f
60
61
/**
62
 * ItemTags module
63
 *
64
 * Show the names and quantities of items in several boxes.
65
 */
66
object ModuleItemTags : ClientModule("ItemTags", ModuleCategories.RENDER) {
67
68
    private val filter by enumChoice("Filter", Filter.BLACKLIST)
69
    private val items by items("Items", itemSortedSetOf())
70
71
    private val backgroundColor by color("BackgroundColor", Color4b.DEFAULT_BG_COLOR)
72
    private val scale = curve(
73
        "Scale",
74
        mutableListOf(Vector2f(0f, 1f), Vector2f(200f, 1f)),
75
        xAxis = "Distance" axis 0f..200f,
76
        yAxis = "Scale" axis 0.25f..4f,
77
    )
78
    private val renderOffset by vec3d("RenderOffset", useLocateButton = false)
79
    private val rowLength by int("RowLength", 100, 1..100)
80
    private val preventOverlap by boolean("PreventOverlap", true)
81
    private val clusterEntities = curve(
82
        "ClusterEntities",
83
        mutableListOf(Vector2f(0f, 2f), Vector2f(64f, 16f), Vector2f(128f, 16f), Vector2f(200f, 24f)),
84
        xAxis = "Distance" axis 0f..200f,
85
        yAxis = "Size" axis 0.1F..32F,
86
    )
87
88
    private val mergeMode by enumChoice("MergeMode", MergeMode.BY_COMPONENTS)
89
90
    private object Shulker : ToggleableValueGroup(this, "Shulker", false) {
91
        val mergeStacks by boolean("MergeStacks", true)
92
        val showTitle by boolean("ShowTitle", true)
93
    }
94
95
    init {
96
        tree(Shulker)
97
    }
98
99
    private val itemStackComparator: Comparator<ItemStack> =
100
        PreferStackSize.PREFER_MORE.thenComparing(COMPARING_DESCRIPTION_ID)
101
102
    @Suppress("unused")
103
    private enum class MergeMode(
104
        override val tag: String,
105
        val merge: (stacks: Array<ItemStack>) -> Array<ItemStack>,
106
    ) : Tagged {
107
        /**
108
         * Nothing will be merged.
109
         */
110
        NONE("None", { stacks ->
111
            stacks.sortWith(itemStackComparator)
112
            stacks
113
        }),
114
115
        /**
116
         * [ItemStack]s with same [Item] will be merged.
117
         */
118
        BY_ITEM("ByItem", { stacks ->
119
            val map = Reference2ObjectOpenHashMap<Item, MutableList<ItemStack>>()
120
            for (stack in stacks) {
121
                map.computeIfAbsent(stack.item) { ObjectArrayList() }.add(stack)
122
            }
123
124
            map.values.mapToArray { stacks ->
125
                if (stacks.size == 1) {
126
                    stacks[0]
127
                } else {
128
                    ItemStack(stacks[0].item, stacks.sumOf { it.count })
129
                }
130
            }.apply {
131
                sortWith(itemStackComparator)
132
            }
133
        }),
134
135
        /**
136
         * [ItemStack]s with same [Item] and same [net.minecraft.core.component.DataComponentPatch] will be merged.
137
         */
138
        BY_COMPONENTS("ByComponents", { stacks ->
139
            val map = Object2IntOpenHashMap<ItemAndComponents>()
140
141
            for (stack in stacks) {
142
                map.addTo(ItemAndComponents(stack), stack.count)
143
            }
144
145
            val iter = map.fastIterator()
146
            Array(map.size) {
147
                val entry = iter.next()
148
                entry.key.toItemStack(entry.intValue)
149
            }.apply {
150
                sortWith(itemStackComparator)
151
            }
152
        }),
153
    }
154
155
    private val itemEntities by computedOn<GameTickEvent, ObjectArrayList<ClusteredEntitiesRenderState>>(
156
        initialValue = ObjectArrayList()
157
    ) { _, groups ->
158
        @Suppress("UNCHECKED_CAST")
159
        val entities = world.entityGetter.filter(EntityTypes.ITEM) {
160
            filter(it.item.item, items)
161
        }
162
163
        groups.clear()
164
        val visited = ReferenceOpenHashSet<ItemEntity>()
165
        for (entity in entities) {
166
            if (entity in visited) continue
167
168
            val distance = entity.position().cameraDistance().toFloat()
169
            val scale = scale.transform(distance)
170
            if (scale < 0.01f) continue
171
172
            val radiusSquared = clusterEntities.transform(distance).sq()
173
174
            // `entity` will also be added
175
            val group = entities.filter { other ->
176
                other !in visited && entity.distanceToSqr(other) < radiusSquared
177
            }
178
179
            visited.addAll(group)
180
            groups += ClusteredEntitiesRenderState(
181
                group,
182
                mergeMode.merge(group.mapToArray { it.item }).asList(),
183
                scale,
184
            )
185
        }
186
187
        groups
188
    }
189
190
    override fun onDisabled() {
191
        itemEntities.clear()
192
    }
193
194
    @Suppress("unused")
195
    private val worldHandler = handler<WorldChangeEvent> {
196
        itemEntities.clear()
197
    }
198
199
    @Suppress("unused")
200
    private val renderHandler = handler<OverlayRenderEvent> { event ->
201
        for (result in itemEntities) {
202
            val worldPos = result.interpolateCurrentCenterPosition(event.tickDelta)
203
            val renderPos = WorldToScreen.calculateScreenPos(worldPos.add(renderOffset)) ?: continue
204
205
            event.context.drawItemStackList(result.stacks)
206
                .centerX(renderPos.x)
207
                .centerY(renderPos.y)
208
                .rectBackground(backgroundColor)
209
                .scale(result.scale)
210
                .rowLength(rowLength)
211
                .draw(preventOverlap)
212
213
            if (Shulker.enabled) {
214
                result.stacks.forEach { stack ->
215
                    val containerComponent = stack[DataComponents.CONTAINER] ?: return@forEach
216
                    val stacks = containerComponent.nonEmptyItemCopyStream().toTypedArray()
217
                    if (stacks.isEmpty()) {
218
                        return@forEach
219
                    }
220
221
                    event.context.drawItemStackList(if (Shulker.mergeStacks) mergeMode.merge(stacks) else stacks)
222
                        .title(stack.hoverName.takeIf { Shulker.showTitle })
223
                        .centerX(renderPos.x)
224
                        .centerY(renderPos.y)
225
                        .rectBackground(backgroundColor)
226
                        .scale(result.scale)
227
                        .rowLength(rowLength)
228
                        .draw(preventOverlap)
229
                }
230
            }
231
        }
232
    }
233
234
    private class ClusteredEntitiesRenderState(
235
        @JvmField val entities: List<Entity>,
236
        @JvmField val stacks: List<ItemStack>,
237
        @JvmField val scale: Float,
238
    ) {
239
        fun interpolateCurrentCenterPosition(tickDelta: Float): Vec3 {
240
            return entities.map { entity ->
241
                entity.interpolateCurrentPosition(tickDelta)
242
            }.average()
243
        }
244
    }
245
246
}
247