Skip to content

Commit

Permalink
Dont use recombed name in base item
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArthurCole committed Dec 14, 2024
1 parent 7429a26 commit a5002dd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/default_user.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameRarityAware
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameFullyRarityAware
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addButton
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
Expand Down Expand Up @@ -121,12 +121,12 @@ object ChestValue {
if (total < config.hideBelow) continue
val textAmount = " §7x${amount.addSeparators()}:"
val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textAmount)
val name = "${stack.itemNameRarityAware.reduceStringLength((config.nameLength - width), ' ')} $textAmount"
val name = "${stack.itemNameFullyRarityAware.reduceStringLength((config.nameLength - width), ' ')} $textAmount"
val price = "§6${(total).formatPrice()}"
val text = if (config.alignedDisplay)
"$name $price"
else
"${stack.itemNameRarityAware} §7x$amount: §6${total.formatPrice()}"
"${stack.itemNameFullyRarityAware} §7x$amount: §6${total.formatPrice()}"
newDisplay.add(
buildList {
val renderable = Renderable.hoverTips(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.getReadableNBTDump
import at.hannibal2.skyhanni.utils.ItemUtils.isRune
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameRarityAware
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameBaseRarityAware
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzRarity
Expand Down Expand Up @@ -700,7 +700,7 @@ object EstimatedItemValueCalculator {
}
}

val name = stack.itemNameRarityAware
val name = stack.itemNameBaseRarityAware
if (internalName.startsWith("ENCHANTED_BOOK_BUNDLE_")) {
list.add("§7Base item: $name")
return 0.0
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.ItemPriceUtils.getPrice
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
Expand Down Expand Up @@ -344,6 +345,11 @@ object ItemUtils {
return data.itemCategory
}

fun ItemStack.getItemBaseRarityOrNull(): LorenzRarity? {
val rarity = getItemRarityOrNull() ?: return null
return if (isRecombobulated(this)) LorenzRarity.entries.firstOrNull { it.id == rarity.id - 1 } else rarity
}

fun ItemStack.getItemRarityOrNull(): LorenzRarity? {
val data = cachedData
if (itemRarityLastCheck(data)) {
Expand Down Expand Up @@ -460,15 +466,28 @@ object ItemUtils {
return getInternalNameOrNull()?.itemName ?: "<null>"
}

val ItemStack.itemNameRarityAware: String
/**
* Returns the item name with its base color, i.e. before recombobulation
*/
val ItemStack.itemNameBaseRarityAware: String
get() {
return getRarityName(getItemBaseRarityOrNull())
}

/**
* Returns the item name with its full color, i.e. after recombobulation
*/
val ItemStack.itemNameFullyRarityAware: String
get() {
val rarity = getItemRarityOrNull()
return if (rarity == null) itemName
else if (itemName.startsWith("§")) {
itemName.replaceFirst(Regex("§[0-9a-f]"), rarity.chatColorCode)
} else itemName
return getRarityName(getItemRarityOrNull())
}

private fun ItemStack.getRarityName(rarity: LorenzRarity?): String =
if (rarity == null) itemName
else if (itemName.startsWith("§")) {
itemName.replaceFirst(Regex("§[0-9a-f]"), rarity.color.getChatColor())
} else itemName

fun ItemStack.getAttributeFromShard(): Pair<String, Int>? {
if (getInternalName().asString() != "ATTRIBUTE_SHARD") return null
val attributes = getAttributes() ?: return null
Expand Down

0 comments on commit a5002dd

Please sign in to comment.