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
|
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.RenderRealOverlayEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.TimeLimitedCache
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
import kotlin.time.Duration.Companion.milliseconds
class ItemRenderBackground {
companion object {
private val backgroundColour = TimeLimitedCache<ItemStack, Int>(60.milliseconds)
private val borderLineColour = TimeLimitedCache<ItemStack, Int>(60.milliseconds)
var ItemStack.background: Int
get() {
return backgroundColour.getOrNull(this) ?: -1
}
set(value) {
backgroundColour.put(this, value)
}
var ItemStack.borderLine: Int
get() {
return borderLineColour.getOrNull(this) ?: -1
}
set(value) {
borderLineColour.put(this, value)
}
}
@SubscribeEvent
fun onRenderRealOverlay(event: RenderRealOverlayEvent) {
val stack = event.stack ?: return
if (!LorenzUtils.inSkyBlock) return
val backgroundColor = stack.background
if (backgroundColor != -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, backgroundColor)
GlStateManager.popMatrix()
}
val borderLineColor = stack.borderLine
if (borderLineColor != -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 + 1, y + 16, borderLineColor)
Gui.drawRect(x, y, x + 16, y + 1, borderLineColor)
Gui.drawRect(x, y + 15, x + 16, y + 16, borderLineColor)
Gui.drawRect(x + 15, y, x + 16, y + 16, borderLineColor)
GlStateManager.popMatrix()
}
}
}
|