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() private val itemNameCache = mutableMapOf() // 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() } }