CombineMobs module

CombineMobs: 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/ModuleCombineMobs.ktKotlin · 118 lines · 4.2 KB

Combines cramped entities.

SettingsCombineArmorStandsCombineMinecarts
ModuleCombineMobs.ktKotlin · Minecraft 26.2 · 118 lines · 4.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.longs.Long2IntOpenHashMap
22
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
23
import net.ccbluex.fastutil.Pool
24
import net.ccbluex.liquidbounce.event.events.GameRenderEvent
25
import net.ccbluex.liquidbounce.event.handler
26
import net.ccbluex.liquidbounce.features.module.ClientModule
27
import net.ccbluex.liquidbounce.features.module.ModuleCategories
28
import net.ccbluex.liquidbounce.utils.entity.RenderedEntities
29
import net.minecraft.world.entity.Entity
30
import net.minecraft.world.entity.EntityType
31
import net.minecraft.world.entity.LivingEntity
32
import net.minecraft.world.entity.Mob
33
import net.minecraft.world.entity.decoration.ArmorStand
34
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart
35
36
/**
37
 * Combine Mobs
38
 *
39
 * This module will disable rendering of entities of the same type that are crammed together
40
 * and show a single entity instead with a count of how many entities are crammed together.
41
 *
42
 * This is useful for example in 2b2t where there are a lot of entities in spawn.
43
 * The idea behind this module originates from the video
44
 * "2b2t's WAR Against Chicken Lag" https://www.youtube.com/watch?v=Qqmz76Z5az0
45
 */
46
object ModuleCombineMobs : ClientModule("CombineMobs", ModuleCategories.RENDER) {
47
48
    @JvmRecord
49
    private data class CombineKey(val type: EntityType<*>, val babyGroup: Boolean)
50
51
    private val renderTracker = Object2ObjectOpenHashMap<CombineKey, Long2IntOpenHashMap>()
52
    private val nametagTracker = Object2ObjectOpenHashMap<CombineKey, Long2IntOpenHashMap>()
53
54
    private val mapPool = Pool(::Long2IntOpenHashMap, Long2IntOpenHashMap::clear)
55
56
    private val combineArmorStands by boolean("CombineArmorStands", false)
57
    private val combineMinecarts by boolean("CombineMinecarts", false)
58
59
    private fun clearRenderTracker() {
60
        mapPool.recycleAll(renderTracker.values)
61
        renderTracker.clear()
62
    }
63
64
    private fun clearNametagTracker() {
65
        mapPool.recycleAll(nametagTracker.values)
66
        nametagTracker.clear()
67
    }
68
69
    override fun onEnabled() {
70
        RenderedEntities.subscribe(this)
71
        RenderedEntities.onUpdated(::clearNametagTracker)
72
        super.onEnabled()
73
    }
74
75
    override fun onDisabled() {
76
        RenderedEntities.unsubscribe(this)
77
        clearRenderTracker()
78
        clearNametagTracker()
79
    }
80
81
    @Suppress("unused")
82
    private val renderGameHandler = handler<GameRenderEvent> {
83
        clearRenderTracker()
84
    }
85
86
    private fun keyFor(mob: Entity): CombineKey {
87
        if (mob !is LivingEntity) {
88
            return CombineKey(mob.type, false)
89
        }
90
        val babyGroup = mob.isBaby
91
        return CombineKey(mob.type, babyGroup)
92
    }
93
94
    @JvmOverloads
95
    fun trackEntity(entity: Entity, forNametag: Boolean = false): Boolean {
96
        val canCombine = entity is Mob ||
97
            (entity is ArmorStand && combineArmorStands) ||
98
            (entity is AbstractMinecart && combineMinecarts)
99
        if (!canCombine) return false
100
101
        return (if (forNametag) nametagTracker else renderTracker)
102
            .getOrPut(keyFor(entity), mapPool::borrow)
103
            .addTo(entity.blockPosition().asLong(), 1) > 0
104
    }
105
106
    fun getCombinedCount(entity: Entity): Int {
107
        if (!running) return 1
108
109
        val key = keyFor(entity)
110
        val pos = entity.blockPosition().asLong()
111
112
        val count = renderTracker[key]?.getOrDefault(pos, 0) ?: 0
113
        if (count > 0) return count
114
115
        return nametagTracker[key]?.getOrDefault(pos, 1) ?: 1
116
    }
117
}
118