Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Fix NeuInternalName.equals #2870

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ object HoppityAPI {
}

HoppityEggsManager.eggBoughtPattern.matchMatcher(event.message) {
if (group("rabbitname").equals(lastName)) {
if (group("rabbitname") == lastName) {
lastMeal = HoppityEggType.BOUGHT
EggFoundEvent(HoppityEggType.BOUGHT).post()
attemptFireRabbitFound()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ object HoppityEggsCompactChat {
}

HoppityEggsManager.eggBoughtPattern.matchMatcher(event.message) {
if (group("rabbitname").equals(lastName)) {
if (group("rabbitname") == lastName) {
lastChatMeal = BOUGHT
compactChat(event)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.roundTo
import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
Expand Down Expand Up @@ -98,6 +99,8 @@ object FarmingFortuneDisplay {
private var lastUniversalFortuneMissingError = SimpleTimeMark.farPast()
private var lastCropFortuneMissingError = SimpleTimeMark.farPast()

private val ZORROS_CAPE by lazy { "ZORROS_CAPE".toInternalName() }

@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
if (!GardenAPI.inGarden()) return
Expand Down Expand Up @@ -273,12 +276,13 @@ object FarmingFortuneDisplay {
fun getToolFortune(tool: ItemStack?): Double = getToolFortune(tool?.getInternalName())
fun getToolFortune(internalName: NEUInternalName?): Double {
if (internalName == null) return 0.0
if (internalName.equals("THEORETICAL_HOE")) {
val string = internalName.asString()
if (string == "THEORETICAL_HOE") {
return 0.0
}
return if (internalName.startsWith("THEORETICAL_HOE")) {
listOf(10.0, 25.0, 50.0)[internalName.asString().last().digitToInt() - 1]
} else when (internalName.asString()) {
return if (string.startsWith("THEORETICAL_HOE")) {
listOf(10.0, 25.0, 50.0)[string.last().digitToInt() - 1]
} else when (string) {
"FUNGI_CUTTER" -> 30.0
"COCO_CHOPPER" -> 20.0
else -> 0.0
Expand Down Expand Up @@ -361,14 +365,14 @@ object FarmingFortuneDisplay {

itemBaseFortune = if (tool.getInternalName().contains("LOTUS")) {
5.0
} else if (tool.getInternalName().equals("ZORROS_CAPE")) {
} else if (tool.getInternalName() == ZORROS_CAPE) {
10.0
} else {
val dummiesFF = (tool.getFarmingForDummiesCount() ?: 0) * 1.0
displayedFortune - reforgeFortune - gemstoneFortune - pesterminatorFortune - enchantmentFortune - dummiesFF
}

greenThumbFortune = if (tool.getInternalName().let { it.contains("LOTUS") || it.equals("ZORROS_CAPE") }) {
greenThumbFortune = if (tool.getInternalName().let { it.contains("LOTUS") || it == ZORROS_CAPE }) {
displayedFortune - reforgeFortune - itemBaseFortune
} else 0.0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.NONE
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
Expand Down Expand Up @@ -105,7 +106,10 @@ object ComposterOverlay {
ChatUtils.chat("Composter test offset set to $testOffset.")
}

private val COMPOST by lazy { "COMPOST".asInternalName() }
private val COMPOST by lazy { "COMPOST".toInternalName() }
private val BIOFUEL by lazy { "BIOFUEL".toInternalName() }
private val VOLTA by lazy { "VOLTA".toInternalName() }
private val OIL_BARREL by lazy { "OIL_BARREL".toInternalName() }

@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
Expand Down Expand Up @@ -481,7 +485,7 @@ object ComposterOverlay {
private fun retrieveMaterials(internalName: NEUInternalName, itemName: String, itemsNeeded: Int) {
if (itemsNeeded == 0) return
if (config.retrieveFrom == ComposterConfig.RetrieveFromEntry.BAZAAR &&
!LorenzUtils.noTradeMode && !internalName.equals("BIOFUEL")
!LorenzUtils.noTradeMode && internalName != BIOFUEL
) {
BazaarApi.searchForBazaarItem(itemName, itemsNeeded)
return
Expand All @@ -496,8 +500,7 @@ object ComposterOverlay {
HypixelCommands.getFromSacks(internalName.asString(), itemsNeeded - havingInInventory)
// TODO Add sack type repo data

val isDwarvenMineable =
internalName.let { it.equals("VOLTA") || it.equals("OIL_BARREL") || it.equals("BIOFUEL") }
val isDwarvenMineable = internalName.let { it == VOLTA || it == OIL_BARREL || it == BIOFUEL }
val sackType = if (isDwarvenMineable) "Mining §eor §9Dwarven" else "Enchanted Agronomy"
ChatUtils.clickableChat(
"Sacks could not be loaded. Click here and open your §9$sackType Sack §eto update the data!",
Expand Down Expand Up @@ -535,7 +538,7 @@ object ComposterOverlay {

private fun getPrice(internalName: NEUInternalName): Double {
val price = internalName.getPrice(config.priceSource)
if (internalName.equals("BIOFUEL") && price > 20_000) return 20_000.0
if (internalName == BIOFUEL && price > 20_000) return 20_000.0

return price
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
Expand Down Expand Up @@ -60,7 +61,9 @@ object CropMoneyDisplay {
private val cropNames = mutableMapOf<NEUInternalName, CropType>()
private val toolHasBountiful get() = GardenAPI.storage?.toolWithBountiful

val BOX_OF_SEEDS by lazy { "BOX_OF_SEEDS".asInternalName().getItemStack() }
private val BOX_OF_SEEDS by lazy { "BOX_OF_SEEDS".toInternalName().getItemStack() }
private val SEEDS by lazy { "SEEDS".toInternalName() }
private val ENCHANTED_SEEDS by lazy { "ENCHANTED_SEEDS".toInternalName() }

@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
Expand Down Expand Up @@ -298,7 +301,7 @@ object CropMoneyDisplay {
(config.useCustomFormat && config.customFormat.singleOrNull() == CustomFormatEntry.NPC_PRICE)

for ((internalName, amount) in multipliers.moveEntryToTop { isSeeds(it.key) }) {
if (internalName.equals("BOX_OF_SEEDS")) continue
if (internalName == BOX_OF_SEEDS.getInternalName()) continue

val crop = cropNames[internalName]!!
// When only the NPC price is shown, display the price only for the base item
Expand Down Expand Up @@ -363,7 +366,7 @@ object CropMoneyDisplay {
debugList.addAsSingletonList(" added seedsPerHour: $seedsPerHour")
}
val factor = NEUItems.getPrimitiveMultiplier(internalName).amount
npcPrice += "SEEDS".asInternalName().getNpcPrice() * seedsPerHour / factor
npcPrice += SEEDS.getNpcPrice() * seedsPerHour / factor
sellOffer += it.sellOfferPrice * seedsPerHour
instantSell += it.instantBuyPrice * seedsPerHour
}
Expand All @@ -381,8 +384,7 @@ object CropMoneyDisplay {
return moneyPerHours
}

private fun isSeeds(internalName: NEUInternalName) =
internalName.equals("ENCHANTED_SEEDS") || internalName.equals("SEEDS")
private fun isSeeds(internalName: NEUInternalName) = internalName == ENCHANTED_SEEDS || internalName == SEEDS

// TODO : Rewrite to not be index-reliant
private fun formatNumbers(sellOffer: Double, instantSell: Double, npcPrice: Double): Array<Double> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.SimpleTimeMark
Expand All @@ -31,6 +32,8 @@ object SprayFeatures {
"§a§lSPRAYONATOR! §r§7Your selected material is now §r§a(?<spray>.*)§r§7!",
)

private val SPRAYONATOR by lazy { "SPRAYONATOR".toInternalName() }

private fun SprayType?.getSprayEffect(): String =
this?.getPests()?.takeIf { it.isNotEmpty() }?.let { pests ->
pests.joinToString("§7, §6") { it.displayName }
Expand Down Expand Up @@ -72,7 +75,7 @@ object SprayFeatures {
fun onWorldRender(event: LorenzRenderWorldEvent) {
if (!GardenAPI.inGarden()) return
if (!config.drawPlotsBorderWhenInHands) return
if (!InventoryUtils.itemInHandId.equals("SPRAYONATOR")) return
if (InventoryUtils.itemInHandId != SPRAYONATOR) return
val plot = GardenPlotAPI.getCurrentPlot() ?: return
event.renderPlot(plot, LorenzColor.YELLOW.toColor(), LorenzColor.DARK_BLUE.toColor())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GuiOptionEditorUpdateCheck(option: ProcessedOption) : GuiOptionEditor(opti

GlStateManager.scale(2F, 2F, 1F)
val currentVersion = SkyHanniMod.version
val sameVersion = currentVersion.equals(nextVersion, true)
val sameVersion = currentVersion.equals(nextVersion, ignoreCase = true)
TextRenderUtils.drawStringCenteredScaledMaxWidth(
"${if (UpdateManager.updateState == UpdateManager.UpdateState.NONE) GREEN else RED}$currentVersion" +
if (nextVersion != null && !sameVersion) "➜ $GREEN$nextVersion" else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
Expand All @@ -40,14 +41,16 @@ object KloonHacking {
private val correctButtons = mutableListOf<String>()
private var nearestTerminal: KloonTerminal? = null

private val RETRO_ENCABULATING_VISOR by lazy { "RETRO_ENCABULATING_VISOR".toInternalName() }

@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!RiftAPI.inRift()) return
checkHelmet()
}

private fun checkHelmet() {
wearingHelmet = InventoryUtils.getHelmet()?.getInternalName()?.equals("RETRO_ENCABULATING_VISOR") ?: false
wearingHelmet = InventoryUtils.getHelmet()?.getInternalName() == RETRO_ENCABULATING_VISOR
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.utils.EntityUtils.getEntities
import at.hannibal2.skyhanni.utils.EntityUtils.hasSkullTexture
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

Expand All @@ -24,6 +25,8 @@ object RiftLarva {
private const val LARVA_SKULL_TEXTURE =
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTgzYjMwZTlkMTM1YjA1MTkwZWVhMmMzYWM2MWUyYWI1NWEyZDgxZTFhNThkYmIyNjk4M2ExNDA4MjY2NCJ9fX0="

private val LARVA_HOOK by lazy { "LARVA_HOOK".toInternalName() }

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!isEnabled()) return
Expand All @@ -37,7 +40,7 @@ object RiftLarva {
}

private fun checkHand() {
hasHookInHand = InventoryUtils.getItemInHand()?.getInternalName()?.equals("LARVA_HOOK") ?: false
hasHookInHand = InventoryUtils.getItemInHand()?.getInternalName() == LARVA_HOOK
}

private fun findLarvas() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import net.minecraft.entity.passive.EntityHorse
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object RiftHorsezookaHider {

private val HORSEZOOKA by lazy { "HORSEZOOKA".toInternalName() }

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (!RiftAPI.inRift()) return
if (!SkyHanniMod.feature.rift.horsezookaHider) return

if (event.entity is EntityHorse && InventoryUtils.itemInHandId.equals("HORSEZOOKA")) {
if (event.entity is EntityHorse && InventoryUtils.itemInHandId == HORSEZOOKA) {
event.cancel()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object SkyBlockIslandTest {
}

private fun find(search: String): IslandType? {
for (type in IslandType.values()) {
for (type in IslandType.entries) {
if (type.name.equals(search, ignoreCase = true)) return type
if (type.displayName.equals(search, ignoreCase = true)) return type
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getRecipePrice
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getRecipes
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators

object ItemPriceUtils {

private val JACK_O_LANTERN by lazy { "JACK_O_LANTERN".toInternalName() }
private val GOLDEN_CARROT by lazy { "GOLDEN_CARROT".toInternalName() }

fun NEUInternalName.getPrice(
priceSource: ItemPriceSource = ItemPriceSource.BAZAAR_INSTANT_BUY,
pastRecipes: List<PrimitiveRecipe> = emptyList(),
Expand All @@ -37,11 +41,11 @@ object ItemPriceUtils {
return it
}

if (equals("JACK_O_LANTERN")) {
if (this == JACK_O_LANTERN) {
return "PUMPKIN".asInternalName().getPrice(priceSource) + 1
}
}
if (equals("GOLDEN_CARROT")) {
if (this == GOLDEN_CARROT) {
// 6.8 for some players
return 7.0 // NPC price
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.PrimitiveIngredient.Companion.toPrimitiveItemStacks
Expand Down Expand Up @@ -45,6 +46,8 @@ object ItemUtils {
private val missingRepoItems = mutableSetOf<String>()
private var lastRepoWarning = SimpleTimeMark.farPast()

private val SKYBLOCK_MENU by lazy { "SKYBLOCK_MENU".toInternalName() }

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

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

fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false
fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName() == SKYBLOCK_MENU

private val itemAmountCache = mutableMapOf<String, Pair<String, Int>>()

Expand Down
Loading