aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt
blob: 1576ff4ca098ebd95a227f676775bea36afef835 (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
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.events.RenderRealOverlayEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ItemRenderBackground {

    companion object {

        private val mapColor = mutableMapOf<ItemStack, Int>()
        private val mapTime = mutableMapOf<ItemStack, Long>()

        var ItemStack.background: Int
            get() {
                if (System.currentTimeMillis() > mapTime.getOrDefault(this, 0) + 200) return -1
                return mapColor.getOrDefault(this, -1)
            }
            set(value) {
                mapColor[this] = value
                mapTime[this] = System.currentTimeMillis()
            }
    }


    @SubscribeEvent
    fun renderOverlayLol(event: RenderRealOverlayEvent) {
        val stack = event.stack
        if (LorenzUtils.inSkyBlock) {
            if (stack != null) {
                val color = stack.background
                if (color != -1) {
                    GlStateManager.pushMatrix()
                    GlStateManager.translate(0f, 0f, 110 + Minecraft.getMinecraft().renderItem.zLevel)
                    val x = event.x
                    val y = event.y
                    Gui.drawRect(x, y, x + 16, y + 16, color)
                    GlStateManager.popMatrix()
                }
            }
        }
    }
}