DamageParticles module

DamageParticles: 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/ModuleDamageParticles.ktKotlin · 188 lines · 6.5 KB

Show health changes of entities.

SettingsTimeToLiveScaleScaleTransitionDisplacementDisplacementTransitionTrackModeDamageDeathHealMaxHealth
ModuleDamageParticles.ktKotlin · Minecraft 26.2 · 188 lines · 6.5 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.Reference2FloatOpenHashMap
22
import net.ccbluex.liquidbounce.config.types.group.ValueGroup
23
import net.ccbluex.liquidbounce.config.types.list.Tagged
24
import net.ccbluex.liquidbounce.event.events.EntityHealthUpdateEvent
25
import net.ccbluex.liquidbounce.event.events.GameTickEvent
26
import net.ccbluex.liquidbounce.event.events.OverlayRenderEvent
27
import net.ccbluex.liquidbounce.event.events.WorldChangeEvent
28
import net.ccbluex.liquidbounce.event.handler
29
import net.ccbluex.liquidbounce.features.module.ClientModule
30
import net.ccbluex.liquidbounce.features.module.ModuleCategories
31
import net.ccbluex.liquidbounce.render.engine.type.Color4b
32
import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention.FIRST_PRIORITY
33
import net.ccbluex.liquidbounce.utils.math.Easing
34
import net.ccbluex.liquidbounce.utils.math.fma
35
import net.ccbluex.liquidbounce.utils.render.WorldToScreen
36
import net.minecraft.world.entity.LivingEntity
37
import net.minecraft.world.phys.Vec3
38
import java.text.DecimalFormat
39
import kotlin.math.abs
40
41
/**
42
 * DamageParticles module
43
 *
44
 * Show health changes of entities
45
 */
46
object ModuleDamageParticles : ClientModule("DamageParticles", ModuleCategories.RENDER) {
47
48
    private val ttl by float("TimeToLive", 3F, 0.5F..5.0F, "s")
49
    private val scale by float("Scale", 2F, 0.25F..4F)
50
    private val scaleTransition by easing("ScaleTransition", Easing.QUAD_OUT)
51
    private val displacement by vec3d("Displacement", Vec3.Y_AXIS.scale(1.5))
52
    private val displacementTransition by easing("DisplacementTransition", Easing.QUAD_OUT)
53
    private val trackMode by enumChoice("TrackMode", TrackMode.ON_TICK)
54
55
    init {
56
        tree(Colors)
57
    }
58
59
    private object Colors : ValueGroup("Colors") {
60
        val damage by color("Damage", Color4b.RED)
61
        val death by color("Death", Color4b.RED)
62
        val heal by color("Heal", Color4b.GREEN)
63
        val maxHealth by color("MaxHealth", Color4b.GREEN)
64
    }
65
66
    private enum class TrackMode(override val tag: String) : Tagged {
67
        ON_TICK("OnTick"),
68
        ON_UPDATE("OnUpdate"),
69
    }
70
71
    /**
72
     * Ordered by [Particle.startTime]
73
     */
74
    private val particles = ArrayDeque<Particle>()
75
76
    private val entityHealthMap = Reference2FloatOpenHashMap<LivingEntity>()
77
78
    private const val EPSILON = 0.05F
79
    private val FORMATTER = DecimalFormat("0.#")
80
81
    private fun trackEntityHealth(entity: LivingEntity, oldHealth: Float, newHealth: Float, maxHealth: Float) {
82
        val delta = abs(oldHealth - newHealth)
83
        if (delta > EPSILON) {
84
            val color = when {
85
                newHealth <= 0F -> Colors.death
86
                oldHealth > newHealth -> Colors.damage
87
                newHealth < maxHealth -> Colors.heal
88
                else -> Colors.maxHealth
89
            }
90
91
            particles += Particle(
92
                System.currentTimeMillis(),
93
                FORMATTER.format(delta),
94
                color,
95
                entity.boundingBox.center.add(entity.knownMovement),
96
            )
97
        }
98
    }
99
100
    private fun shouldNotTrack(entity: LivingEntity) = entity.tickCount == 0 || entity === player
101
102
    override fun onDisabled() {
103
        particles.clear()
104
        entityHealthMap.clear()
105
    }
106
107
    @Suppress("unused")
108
    private val worldChangeHandler = handler<WorldChangeEvent> {
109
        particles.clear()
110
        entityHealthMap.clear()
111
    }
112
113
    @Suppress("unused")
114
    private val entityHealthUpdateHandler = handler<EntityHealthUpdateEvent> {
115
        if (trackMode !== TrackMode.ON_UPDATE) {
116
            return@handler
117
        }
118
119
        val entity = it.entity
120
        if (shouldNotTrack(entity)) {
121
            return@handler
122
        }
123
124
        trackEntityHealth(entity, it.old, it.new, it.max)
125
    }
126
127
    @Suppress("unused")
128
    private val tickHandler = handler<GameTickEvent>(priority = FIRST_PRIORITY) {
129
        val earliest = System.currentTimeMillis() - (ttl * 1000).toLong()
130
        while (particles.isNotEmpty() && particles.first().startTime < earliest) {
131
            particles.removeFirst()
132
        }
133
134
        if (trackMode !== TrackMode.ON_TICK) {
135
            return@handler
136
        }
137
138
        val entities = world.entitiesForRendering()
139
        for (entity in entities) {
140
            if (entity !is LivingEntity || shouldNotTrack(entity)) {
141
                continue
142
            }
143
144
            val newHealth = entity.health
145
            val maxHealth = entity.maxHealth
146
            val oldHealth = entityHealthMap.put(entity, newHealth)
147
            if (oldHealth != 0F) {
148
                trackEntityHealth(entity, oldHealth, newHealth, maxHealth)
149
            }
150
        }
151
152
        entityHealthMap.keys.removeIf { it !in entities || it.isDeadOrDying }
153
    }
154
155
    @Suppress("unused")
156
    private val renderHandler = handler<OverlayRenderEvent> { event ->
157
        val now = System.currentTimeMillis()
158
        particles.forEachIndexed { i, particle ->
159
            val progress = (now - particle.startTime).toFloat() / (ttl * 1000.0F)
160
161
            val currentPos = particle.pos.fma(displacementTransition.transform(progress).toDouble(), displacement)
162
            val screenPos = WorldToScreen.calculateScreenPos(currentPos) ?: return@forEachIndexed
163
164
            val currentScale = scale * scaleTransition.transform(progress)
165
166
            with(event.context) {
167
                pose().pushMatrix()
168
                pose().translate(screenPos.x, screenPos.y)
169
                pose().scale(currentScale, currentScale)
170
171
                centeredText(
172
                    mc.font,
173
                    particle.text,
174
                    0,
175
                    0,
176
                    particle.color.argb,
177
                )
178
                pose().popMatrix()
179
            }
180
        }
181
182
    }
183
184
    @JvmRecord
185
    private data class Particle(val startTime: Long, val text: String, val color: Color4b, val pos: Vec3)
186
187
}
188