blob: 8c127fac827838ba3092515c4e671b2bc7f2a051 (
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
|
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
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>()
private val itemNameCache = mutableMapOf<String, String>() // display name -> internal name
fun getInternalNameByName(rawName: String): String? {
val itemName = rawName.removeColor()
if (itemNameCache.containsKey(itemName)) {
return itemNameCache[itemName]
}
val manager = NotEnoughUpdates.INSTANCE.manager
for ((internalId, b) in manager.itemInformation) {
if (b.has("displayname")) {
val name = b.get("displayname").asString
if (name.contains(itemName)) {
itemNameCache[itemName] = internalId
return internalId
}
}
}
return null
}
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()
}
}
|