aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderLivingEntityHelper.kt
blob: 4d54aa90bd737ed7c4d73cbf9f37560d4277cb4e (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.events.RenderMobColoredEvent
import at.hannibal2.skyhanni.events.ResetEntityHurtEvent
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()

        entityNoHurTime.clear()
        entityNoHurTimeCondition.clear()
    }

    companion object {

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

        private val entityNoHurTime = mutableListOf<EntityLivingBase>()
        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) {
            entityNoHurTime.add(entity)
            entityNoHurTimeCondition[entity] = condition
        }

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

            // TODO remove event
            if (!SkyHanniDebugsAndTests.globalRender) return 0
            val event = RenderMobColoredEvent(entity, 0)
            event.postAndCatch()
            return event.color
        }

        fun <T : EntityLivingBase> changeHurtTime(entity: T): Int {
            if (!SkyHanniDebugsAndTests.globalRender) return 0
            if (entityNoHurTime.contains(entity)) {
                val condition = entityNoHurTimeCondition[entity]!!
                if (condition.invoke()) {
                    return 0
                }
            }

            // TODO remove event
            val event = ResetEntityHurtEvent(entity, false)
            event.postAndCatch()
            return if (event.shouldReset) 0 else entity.hurtTime
        }
    }
}