aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt70
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt29
3 files changed, 65 insertions, 38 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index bb2d3fd3e..4b334d027 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -42,6 +42,7 @@ 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.Item
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -54,35 +55,39 @@ object NEUItems {
private val multiplierCache = mutableMapOf<NEUInternalName, PrimitiveItemStack>()
private val recipesCache = mutableMapOf<NEUInternalName, Set<NeuRecipe>>()
private val ingredientsCache = mutableMapOf<NeuRecipe, Set<Ingredient>>()
+ private val itemIdCache = mutableMapOf<Item, List<NEUInternalName>>()
private val hypixelApiGson by lazy {
BaseGsonBuilder.gson()
- .registerTypeAdapter(HypixelApiTrophyFish::class.java, object : TypeAdapter<HypixelApiTrophyFish>() {
- override fun write(out: JsonWriter, value: HypixelApiTrophyFish) {}
-
- override fun read(reader: JsonReader): HypixelApiTrophyFish {
- val trophyFish = mutableMapOf<String, Int>()
- var totalCaught = 0
- reader.beginObject()
- while (reader.hasNext()) {
- val key = reader.nextName()
- if (key == "total_caught") {
- totalCaught = reader.nextInt()
- continue
- }
- if (reader.peek() == JsonToken.NUMBER) {
- val valueAsString = reader.nextString()
- if (valueAsString.isInt()) {
- trophyFish[key] = valueAsString.toInt()
+ .registerTypeAdapter(
+ HypixelApiTrophyFish::class.java,
+ object : TypeAdapter<HypixelApiTrophyFish>() {
+ override fun write(out: JsonWriter, value: HypixelApiTrophyFish) {}
+
+ override fun read(reader: JsonReader): HypixelApiTrophyFish {
+ val trophyFish = mutableMapOf<String, Int>()
+ var totalCaught = 0
+ reader.beginObject()
+ while (reader.hasNext()) {
+ val key = reader.nextName()
+ if (key == "total_caught") {
+ totalCaught = reader.nextInt()
continue
}
+ if (reader.peek() == JsonToken.NUMBER) {
+ val valueAsString = reader.nextString()
+ if (valueAsString.isInt()) {
+ trophyFish[key] = valueAsString.toInt()
+ continue
+ }
+ }
+ reader.skipValue()
}
- reader.skipValue()
+ reader.endObject()
+ return HypixelApiTrophyFish(totalCaught, trophyFish)
}
- reader.endObject()
- return HypixelApiTrophyFish(totalCaught, trophyFish)
- }
- }.nullSafe())
+ }.nullSafe(),
+ )
.create()
}
@@ -94,7 +99,7 @@ object NEUItems {
Utils.createItemStack(
ItemStack(Blocks.barrier).item,
"§cMissing Repo Item",
- "§cYour NEU repo seems to be out of date"
+ "§cYour NEU repo seems to be out of date",
)
}
@@ -119,7 +124,7 @@ object NEUItems {
} catch (e: Exception) {
ErrorManager.logErrorWithData(
e, "Error reading hypixel player api data",
- "data" to apiData
+ "data" to apiData,
)
}
}
@@ -210,7 +215,7 @@ object NEUItems {
"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
+ "repo commit" to manager.latestRepoCommit,
)
fallbackItem
}
@@ -225,7 +230,7 @@ object NEUItems {
x: Float,
y: Float,
scaleMultiplier: Double = itemFontSize,
- rescaleSkulls: Boolean = true
+ rescaleSkulls: Boolean = true,
) {
val item = checkBlinkItem()
val isSkull = rescaleSkulls && item.item === Items.skull
@@ -281,13 +286,24 @@ object NEUItems {
fun allNeuRepoItems(): Map<String, JsonObject> = NotEnoughUpdates.INSTANCE.manager.itemInformation
+ fun getInternalNamesForItemId(item: Item): List<NEUInternalName> {
+ itemIdCache[item]?.let {
+ return it
+ }
+ val result = allNeuRepoItems()
+ .filter { Item.getByNameOrId(it.value.get("itemid").asString) == item }
+ .keys.map { it.asInternalName() }
+ itemIdCache[item] = result
+ return result
+ }
+
fun getPrimitiveMultiplier(internalName: NEUInternalName, tryCount: Int = 0): PrimitiveItemStack {
multiplierCache[internalName]?.let { return it }
if (tryCount == 10) {
ErrorManager.logErrorStateWithData(
"Could not load recipe data.",
"Failed to find item multiplier",
- "internalName" to internalName
+ "internalName" to internalName,
)
return internalName.makePrimitiveStack()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 1ee34699c..b97298ce4 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -33,7 +33,7 @@ object NumberUtil {
5 to "V",
4 to "IV",
1 to "I",
- )
+ ),
)
@Deprecated("outdated", ReplaceWith("value.shortFormat(preciseBillions)"))
@@ -170,6 +170,8 @@ object NumberUtil {
} else romanSymbols[l] + (this - l).toRoman()
}
+ fun Number.toStringWithPlus() = (if (this.toDouble() >= 0.0) "+" else "") + this.toString()
+
private fun processDecimal(decimal: Int, lastNumber: Int, lastDecimal: Int) = if (lastNumber > decimal) {
lastDecimal - decimal
} else {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt b/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt
index dc50eef74..7859853ca 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils.json
import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.data.model.SkyblockStat
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.pests.PestType
@@ -24,22 +25,22 @@ object SkyHanniTypeAdapters {
val UUID: TypeAdapter<UUID> = SimpleStringTypeAdapter(
{ this.toString() },
- { java.util.UUID.fromString(this) }
+ { java.util.UUID.fromString(this) },
)
val INTERNAL_NAME: TypeAdapter<NEUInternalName> = SimpleStringTypeAdapter(
{ this.asString() },
- { this.asInternalName() }
+ { this.asInternalName() },
)
val VEC_STRING: TypeAdapter<LorenzVec> = SimpleStringTypeAdapter(
{ "$x:$y:$z" },
- { LorenzVec.decodeFromString(this) }
+ { LorenzVec.decodeFromString(this) },
)
val TROPHY_RARITY: TypeAdapter<TrophyRarity> = SimpleStringTypeAdapter(
{ name },
- { TrophyRarity.getByName(this) ?: error("Could not parse TrophyRarity from '$this'") }
+ { TrophyRarity.getByName(this) ?: error("Could not parse TrophyRarity from '$this'") },
)
val TIME_MARK: TypeAdapter<SimpleTimeMark> = object : TypeAdapter<SimpleTimeMark>() {
@@ -54,12 +55,17 @@ object SkyHanniTypeAdapters {
val CROP_TYPE: TypeAdapter<CropType> = SimpleStringTypeAdapter(
{ name },
- { CropType.getByName(this) }
+ { CropType.getByName(this) },
)
val PEST_TYPE: TypeAdapter<PestType> = SimpleStringTypeAdapter(
{ name },
- { PestType.getByName(this) }
+ { PestType.getByName(this) },
+ )
+
+ val SKYBLOCK_STAT: TypeAdapter<SkyblockStat> = SimpleStringTypeAdapter(
+ { name.lowercase() },
+ { SkyblockStat.valueOf(this.uppercase()) },
)
val TRACKER_DISPLAY_MODE = SimpleStringTypeAdapter.forEnum<SkyHanniTracker.DefaultDisplayMode>()
@@ -70,10 +76,13 @@ object SkyHanniTypeAdapters {
crossinline write: (JsonWriter, T) -> Unit,
crossinline read: (JsonReader) -> T,
): GsonBuilder {
- this.registerTypeAdapter(T::class.java, object : TypeAdapter<T>() {
- override fun write(out: JsonWriter, value: T) = write(out, value)
- override fun read(reader: JsonReader) = read(reader)
- }.nullSafe())
+ this.registerTypeAdapter(
+ T::class.java,
+ object : TypeAdapter<T>() {
+ override fun write(out: JsonWriter, value: T) = write(out, value)
+ override fun read(reader: JsonReader) = read(reader)
+ }.nullSafe(),
+ )
return this
}
}