Skip to content

Commit

Permalink
fix all repo errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Aug 12, 2024
1 parent 5410157 commit 547fe83
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,19 @@ object ComposterOverlay {
return
}
if (organicMatterFactors.isEmpty()) {
organicMatterDisplay =
Collections.singletonList(
listOf(
"§cSkyHanni composter error:", "§cRepo data not loaded!",
"§7(organicMatterFactors is empty)",
),
)
organicMatterDisplay = listOf(
Collections.singletonList("§cSkyHanni composter error:"),
Collections.singletonList("§cRepo data not loaded!"),
Collections.singletonList("§7(organicMatterFactors is empty)"),
)
return
}
if (fuelFactors.isEmpty()) {
organicMatterDisplay =
Collections.singletonList(
listOf(
"§cSkyHanni composter error:", "§cRepo data not loaded!",
"§7(fuelFactors is empty)",
),
)
organicMatterDisplay = listOf(
Collections.singletonList("§cSkyHanni composter error:"),
Collections.singletonList("§cRepo data not loaded!"),
Collections.singletonList("§7(fuelFactors is empty)"),
)
return
}
if (currentOrganicMatterItem.let { it !in organicMatterFactors.keys && it != NONE }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,7 @@ object GardenComposterInventoryFeatures {
)
continue
}
val internalName = NEUInternalName.fromItemNameOrNull(itemName) ?: run {
ErrorManager.logErrorStateWithData(
"Error reading internal name for item: $itemName",
"could not find internal name for",
"itemName" to itemName
)
continue
}
val internalName = NEUInternalName.fromItemName(itemName)
val lowestBin = internalName.getPrice()
val price = lowestBin * amount
fullPrice += price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.events.item.ItemHoverEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
Expand All @@ -25,7 +24,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
Expand Down Expand Up @@ -203,12 +201,6 @@ object EstimatedItemValue {
if (internalName.contains("UNIQUE_RUNE")) return listOf()
if (internalName.contains("WISP_POTION")) return listOf()


if (internalName.getItemStackOrNull() == null) {
ChatUtils.debug("Estimated Item Value is null for: '$internalName'")
return listOf()
}

val list = mutableListOf<String>()
list.add("§aEstimated Item Value:")
val pair = EstimatedItemValueCalculator.calculate(stack, list)
Expand Down
49 changes: 48 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.data.PetAPI
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
Expand All @@ -14,22 +16,28 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.removeResets
import com.google.common.collect.Lists
import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
import io.github.moulberry.notenoughupdates.util.NotificationHandler
import net.minecraft.client.Minecraft
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.nbt.NBTTagList
import net.minecraft.nbt.NBTTagString
import net.minecraftforge.common.util.Constants
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.LinkedList
import java.util.regex.Matcher
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
object ItemUtils {

private val itemNameCache = mutableMapOf<NEUInternalName, String>() // internal name -> item name

private val missingRepoItems = mutableSetOf<String>()

fun ItemStack.cleanName() = this.displayName.removeColor()

fun isSack(stack: ItemStack) = stack.getInternalName().endsWith("_SACK") && stack.cleanName().endsWith(" Sack")
Expand Down Expand Up @@ -360,7 +368,11 @@ object ItemUtils {
}

val itemStack = getItemStackOrNull()
val name = itemStack?.name ?: error("Could not find item name for $this")
val name = itemStack?.name ?: run {
val name = toString()
addMissingRepoItem(name, "Could not find item name for $name")
return "§c$name"
}

// show enchanted book name
if (itemStack.getItemCategoryOrNull() == ItemCategory.ENCHANTED_BOOK) {
Expand Down Expand Up @@ -411,4 +423,39 @@ object ItemUtils {
it.key.getPrice(pastRecipes = pastRecipes) * it.value
}.sum()

@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
event.title("Missing Repo Items")

if (missingRepoItems.isNotEmpty()) {
event.addData {
add("Detected ${missingRepoItems.size} missing items:")
for (itemName in missingRepoItems) {
add(" - $itemName")
}
}
} else {
event.addIrrelevant("No Repo Item fails detected.")
}
}

fun addMissingRepoItem(name: String, message: String) {
if (!missingRepoItems.add(name)) return
ChatUtils.debug(message)
// showRepoWarning()
}

// Running NEU's function `Utils.showOutdatedRepoNotification()` caused a NoSuchMethodError in dev env.
// Therefore we run NotificationHandler.displayNotification directly
private fun showRepoWarning() {
NotificationHandler.displayNotification(
Lists.newArrayList(
"§c§lMissing repo data",
"§cData used for some SkyHanni features is not up to date, this should normally not be the case.",
"§cYou can try §l/neuresetrepo§r§c and restart your game to see if that fixes the issue.",
"§cIf the problem persists please join the SkyHanni Discord and message in §l#support§r§c to get support.",

This comment has been minimized.

Copy link
@CalMWolfs

CalMWolfs Aug 12, 2024

Collaborator

maybe put the link here, or a /shdiscord command

),
true, true,
)
}
}
12 changes: 5 additions & 7 deletions src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.test.command.ErrorManager

class NEUInternalName private constructor(private val internalName: String) {

companion object {
Expand All @@ -24,11 +22,11 @@ class NEUInternalName private constructor(private val internalName: String) {
fun fromItemNameOrNull(itemName: String): NEUInternalName? =
ItemNameResolver.getInternalNameOrNull(itemName.removeSuffix(" Pet"))

fun fromItemName(itemName: String): NEUInternalName =
fromItemNameOrNull(itemName) ?: ErrorManager.skyHanniError(
"NEUInternalName is null for item name: '$itemName'",
"inventoryName" to InventoryUtils.openInventoryName()
)
fun fromItemName(itemName: String): NEUInternalName = fromItemNameOrNull(itemName) ?: run {
val name = "itemName:$itemName"
ItemUtils.addMissingRepoItem(name, "Could not find internal name for $name")
return NEUInternalName.MISSING_ITEM
}
}

fun asString() = internalName
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,9 @@ object NEUItems {
getItemStackOrNull() ?: run {
getPriceOrNullNew() ?: return@run fallbackItem
if (ignoreItemsFilter.match(this.asString())) return@run fallbackItem
ErrorManager.logErrorWithData(
IllegalStateException("Something went wrong!"),
"Encountered an error getting the item for §7$this§c. " +
"This may be because your NEU repo is outdated. Please ask in the SkyHanni " +
"Discord if this is the case.",
"Item name" to this.asString(),
"repo commit" to manager.latestRepoCommit,
)

val name = this.toString()
ItemUtils.addMissingRepoItem(name, "Could not create item stack for $name")
fallbackItem
}

Expand Down

0 comments on commit 547fe83

Please sign in to comment.