aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
blob: 46c9c6fea853de190c530e1cbd205c2dbfc991a5 (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
package at.hannibal2.skyhanni.utils

import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.init.Items
import net.minecraft.item.ItemStack

object NEUItems {

    private val itemCache = mutableMapOf<String, ItemStack>()

    fun readItemFromRepo(internalName: String): ItemStack {
        if (itemCache.contains(internalName)) {
            return itemCache[internalName]!!
        }
        val itemStack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(
            NotEnoughUpdates.INSTANCE.manager.itemInformation[internalName]
        )
        if (itemStack != null) {
            itemCache[internalName] = itemStack
        }
        return itemStack
    }

    fun ItemStack.renderOnScreen(x: Float, y: Float) {
        GlStateManager.pushMatrix()
        GlStateManager.translate(x, y, 0f)

        val scale = if (item === Items.skull) 0.8f else 0.6f
        GlStateManager.scale(scale, scale, 1f)
        Utils.drawItemStack(this, 0, 0)
        GlStateManager.popMatrix()
    }
}