MobOwners module

MobOwners: 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/ModuleMobOwners.ktKotlin · 102 lines · 3.7 KB

Allows you to see which player a tamed entity or projectile belongs to.

SettingsProjectiles
ModuleMobOwners.ktKotlin · Minecraft 26.2 · 102 lines · 3.7 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 kotlinx.coroutines.CancellationException
22
import net.ccbluex.liquidbounce.api.core.HttpClient
23
import net.ccbluex.liquidbounce.api.core.withScope
24
import net.ccbluex.liquidbounce.features.module.ClientModule
25
import net.ccbluex.liquidbounce.features.module.ModuleCategories
26
import net.ccbluex.liquidbounce.utils.kotlin.toUndashedString
27
import net.minecraft.ChatFormatting
28
import net.minecraft.network.chat.Style
29
import net.minecraft.util.FormattedCharSequence
30
import net.minecraft.world.entity.Entity
31
import net.minecraft.world.entity.TamableAnimal
32
import net.minecraft.world.entity.animal.equine.AbstractHorse
33
import net.minecraft.world.entity.projectile.Projectile
34
import java.util.UUID
35
import java.util.concurrent.ConcurrentHashMap
36
37
/**
38
 * MobOwners module
39
 *
40
 * Shows you from which player a tamable entity or projectile belongs to.
41
 */
42
43
object ModuleMobOwners : ClientModule("MobOwners", ModuleCategories.RENDER) {
44
45
    private val projectiles by boolean("Projectiles", false)
46
47
    private val uuidNameCache = ConcurrentHashMap<UUID, FormattedCharSequence>()
48
49
    fun getOwnerInfoText(entity: Entity?): FormattedCharSequence? {
50
        if (entity == null || !this.running) {
51
            return null
52
        }
53
54
        val ownerId = when (entity) {
55
            is TamableAnimal -> entity.ownerReference?.uuid
56
            is AbstractHorse -> entity.ownerReference?.uuid
57
            is Projectile if projectiles -> entity.owner?.uuid
58
            else -> null
59
        } ?: return null
60
61
        return world.getPlayerByUUID(ownerId)
62
            ?.let { FormattedCharSequence.forward(it.scoreboardName, Style.EMPTY) }
63
            ?: getFromMojangApi(ownerId)
64
    }
65
66
    private val LOADING_TEXT = FormattedCharSequence.forward(
67
        "Loading...",
68
        Style.EMPTY.withItalic(true)
69
    )
70
71
    private val FAILED_TEXT = FormattedCharSequence.forward(
72
        "Failed to query Mojang API",
73
        Style.EMPTY.withItalic(true).withColor(ChatFormatting.RED)
74
    )
75
76
    private val CANCELED_TEXT = FormattedCharSequence.forward(
77
        "Query is canceled",
78
        Style.EMPTY.withItalic(true).withColor(ChatFormatting.YELLOW)
79
    )
80
81
    @Suppress("SwallowedException")
82
    private fun getFromMojangApi(ownerId: UUID): FormattedCharSequence {
83
        return uuidNameCache.putIfAbsent(ownerId, LOADING_TEXT) ?: run {
84
            // The job will still run even if the module is disabled
85
            withScope {
86
                uuidNameCache[ownerId] = try {
87
                    val profile = HttpClient.mojangApiClient.mcServicesApi
88
                        .lookupNameByUuid(ownerId.toUndashedString())
89
                    FormattedCharSequence.forward(profile.name, Style.EMPTY)
90
                } catch (e: CancellationException) {
91
                    CANCELED_TEXT
92
                } catch (e: Exception) {
93
                    FAILED_TEXT
94
                }
95
            }
96
97
            LOADING_TEXT
98
        }
99
    }
100
101
}
102