diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-07-01 08:47:24 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-01 00:47:24 +0200 |
commit | db0f40aabed9a29e0055c3c9e6a6b1159b1444bf (patch) | |
tree | 67c682fa39bfa845ac1875d860531c7bddc389df /src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | |
parent | 8667307b1367e3047c854b3a1ed5d1a7c1e879e6 (diff) | |
download | skyhanni-db0f40aabed9a29e0055c3c9e6a6b1159b1444bf.tar.gz skyhanni-db0f40aabed9a29e0055c3c9e6a6b1159b1444bf.tar.bz2 skyhanni-db0f40aabed9a29e0055c3c9e6a6b1159b1444bf.zip |
No more getItemStack() crashes hopefully (#276)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 97f1b7ca3..848acd0ff 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -1,6 +1,9 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.test.command.CopyErrorCommand import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal @@ -16,9 +19,11 @@ import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe import io.github.moulberry.notenoughupdates.recipes.NeuRecipe import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery +import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.RenderHelper +import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound @@ -32,6 +37,15 @@ object NEUItems { private val enchantmentNamePattern = Pattern.compile("^(?<format>(?:§.)+)(?<name>[^§]+) (?<level>[IVXL]+)$") var allItemsCache = mapOf<String, String>() // item name -> internal name var allInternalNames = mutableListOf<String>() + private var warnedAlready = false + + private val fallbackItem by lazy { + Utils.createItemStack( + ItemStack(Blocks.barrier).item, + "§cMissing Repo Item", + "§cYour NEU repo seems to be out of date" + ) + } fun getInternalName(itemName: String): String { return getInternalNameOrNull(itemName) ?: throw Error("getInternalName is null for '$itemName'") @@ -71,6 +85,11 @@ object NEUItems { return itemNameCache[lowercase]!! } + if (itemName == "§cmissing repo item") { + itemNameCache[lowercase] = "MISSING_ITEM" + return "MISSING_ITEM" + } + resolveEnchantmentByName(itemName)?.let { itemNameCache[itemName] = it return it @@ -137,11 +156,18 @@ object NEUItems { .withKnownInternalName(internalName) .resolveToItemStack()?.copy() - fun getItemStack(internalName: String): ItemStack = getItemStackOrNull(internalName) - ?: throw IllegalStateException( - "Could not find the Item '$internalName' in NEU Repo", - Error("ItemResolutionQuery returns null for internalName '$internalName'") - ) + fun getItemStack(internalName: String): ItemStack = getItemStackOrNull(internalName) ?: run { + if (ProfileStorageData.playerSpecific?.lastRepoIssueVersion != SkyHanniMod.version || !warnedAlready) { + Utils.showOutdatedRepoNotification() + CopyErrorCommand.logError( + IllegalStateException("Something went wrong!"), + "Encountered an error getting the item for §7$internalName§c. " + + "This is probably because your NEU repo is outdated" + ) + } + warnedAlready = true + fallbackItem + } fun isVanillaItem(item: ItemStack) = manager.auctionManager.isVanillaItem(item.getInternalName()) |