aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderLivingEntityHelper.kt
blob: eb7456b4c19277bf4effab79f2db42a41aea2846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package at.hannibal2.skyhanni.mixins.hooks

import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import net.minecraft.entity.EntityLivingBase
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class RenderLivingEntityHelper {

    @SubscribeEvent
    fun onWorldChange(event: LorenzWorldChangeEvent) {
        entityColorMap.clear()
        entityColorCondition.clear()

        entityNoHurTimeCondition.clear()
    }

    companion object {

        private val entityColorMap = mutableMapOf<EntityLivingBase, Int>()
        private val entityColorCondition = mutableMapOf<EntityLivingBase, () -> Boolean>()

        private val entityNoHurTimeCondition = mutableMapOf<EntityLivingBase, () -> Boolean>()

        fun <T : EntityLivingBase> removeEntityColor(entity: T) {
            entityColorMap.remove(entity)
            entityColorCondition.remove(entity)
        }

        fun <T : EntityLivingBase> setEntityColor(entity: T, color: Int, condition: () -> Boolean) {
            entityColorMap[entity] = color
            entityColorCondition[entity] = condition
        }

        fun <T : EntityLivingBase> setNoHurtTime(entity: T, condition: () -> Boolean) {
            entityNoHurTimeCondition[entity] = condition
        }

        fun <T : EntityLivingBase> setEntityColorWithNoHurtTime(entity: T, color: Int, condition: () -> Boolean) {
            setEntityColor(entity, color, condition)
            setNoHurtTime(entity, condition)
        }

        fun <T : EntityLivingBase> removeNoHurtTime(entity: T) {
            entityNoHurTimeCondition.remove(entity)
        }

        fun <T : EntityLivingBase> removeCustomRender(entity: T) {
            removeEntityColor(entity)
            removeNoHurtTime(entity)
        }

        fun <T : EntityLivingBase> internalSetColorMultiplier(entity: T): Int {
            if (!SkyHanniDebugsAndTests.globalRender) return 0
            if (entityColorMap.containsKey(entity)) {
                val condition = entityColorCondition[entity]!!
                if (condition.invoke()) {
                    return entityColorMap[entity]!!
                }
            }
            return 0
        }

        fun <T : EntityLivingBase> internalChangeHurtTime(entity: T): Int {
            if (!SkyHanniDebugsAndTests.globalRender) return entity.hurtTime
            run {
                val condition = entityNoHurTimeCondition[entity] ?: return@run
                if (condition.invoke()) {
                    return 0
                }
            }
            return entity.hurtTime
        }
    }
}