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 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() private val entityColorCondition = mutableMapOf Boolean>() private val entityNoHurTime = mutableListOf() private val entityNoHurTimeCondition = mutableMapOf Boolean>() fun removeEntityColor(entity: T) { entityColorMap.remove(entity) entityColorCondition.remove(entity) } fun setEntityColor(entity: T, color: Int, condition: () -> Boolean) { entityColorMap[entity] = color entityColorCondition[entity] = condition } fun setNoHurtTime(entity: T, condition: () -> Boolean) { entityNoHurTime.add(entity) entityNoHurTimeCondition[entity] = condition } fun setColorMultiplier(entity: T): Int { if (entityColorMap.containsKey(entity)) { val condition = entityColorCondition[entity]!! if (condition.invoke()) { return entityColorMap[entity]!! } } //TODO remove event val event = RenderMobColoredEvent(entity, 0) event.postAndCatch() return event.color } fun changeHurtTime(entity: T): Int { 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 } } }