diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-08-22 04:04:49 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-08-22 04:04:49 +0200 |
commit | 5f10fc9d3938e47baf3fe40fa50e49c564031c36 (patch) | |
tree | 8a6aabf08938ff4722e7b3f4d9ab65fa756afde5 /src/main/java/at/hannibal2 | |
parent | 1021280302d684071a9bde3cf274a16913eb48ec (diff) | |
download | skyhanni-5f10fc9d3938e47baf3fe40fa50e49c564031c36.tar.gz skyhanni-5f10fc9d3938e47baf3fe40fa50e49c564031c36.tar.bz2 skyhanni-5f10fc9d3938e47baf3fe40fa50e49c564031c36.zip |
show crimson armor as stack size and in item name
Diffstat (limited to 'src/main/java/at/hannibal2')
5 files changed, 129 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 74a8a54a1..a1423db65 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -24,6 +24,7 @@ import at.hannibal2.skyhanni.features.dungeon.*; import at.hannibal2.skyhanni.features.fishing.SeaCreatureManager; import at.hannibal2.skyhanni.features.fishing.SeaCreatureMessageShortener; import at.hannibal2.skyhanni.features.fishing.TrophyFishMessages; +import at.hannibal2.skyhanni.features.items.CrimsonArmorTier; import at.hannibal2.skyhanni.features.items.HideNotClickableItems; import at.hannibal2.skyhanni.features.items.ItemDisplayOverlayFeatures; import at.hannibal2.skyhanni.features.items.abilitycooldown.ItemAbilityCooldown; @@ -96,6 +97,7 @@ public class SkyHanniMod { registerEvent(new AshfangNextResetCooldown()); registerEvent(new SummoningSoulsName()); registerEvent(new AshfangGravityOrbs()); + registerEvent(new CrimsonArmorTier()); Commands.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java index a85172d46..a756d1725 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java @@ -27,7 +27,8 @@ public class Inventory { "\u00a7bDungeon Head Floor Number", "\u00a7bNew Year Cake", "\u00a7bPet Level", - "\u00a7bMinion Tier" + "\u00a7bMinion Tier", + "\u00a7bCrimson Armor", } ) public List<Integer> itemNumberAsStackSize = new ArrayList<>(); @@ -41,4 +42,10 @@ public class Inventory { @ConfigOption(name = "Anvil Combine Helper", desc = "Suggests the same item in the inventory when trying to combine two items in the anvil.") @ConfigEditorBoolean public boolean anvilCombineHelper = false; + + @Expose + @ConfigOption(name = "Crimson Armor Stars", + desc = "Show a compact star count in the item name for the Aurora, Crimson, Terror and Fervor armor") + @ConfigEditorBoolean + public boolean crimsonArmorStars = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt index c61b8dd8a..8e558e23f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt @@ -31,23 +31,6 @@ class SeaCreatureManager { } LorenzUtils.debug("loaded $counter sea creatures from repo") -// seaCreatures.asJsonArray.map { it.asJsonObject }.forEach { -// val displayName = it["display_name"].asString -// val chatMessage = it["chat_message"].asString -// val fishingExperience = it["fishing_experience"].asInt -// val variantName = it["variant"].asString -// val special = it["special"].asBoolean -// -// val variant = try { -// FishingVariant.fromString(variantName) -// } catch (e: FishingVariantNotFoundException) { -// LorenzUtils.error("Error loading Sea Creature '$displayName': " + e.message) -// return -// } -// -// seaCreatureMap[chatMessage] = SeaCreature(displayName, fishingExperience, variant, special) -// } - } catch (e: Exception) { e.printStackTrace() LorenzUtils.error("error in RepositoryReloadEvent") @@ -55,7 +38,7 @@ class SeaCreatureManager { } companion object { - val seaCreatureMap = mutableMapOf<String, SeaCreature>() + private val seaCreatureMap = mutableMapOf<String, SeaCreature>() fun getSeaCreature(message: String): SeaCreature? { return seaCreatureMap.getOrDefault(message, null) diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/CrimsonArmorTier.kt b/src/main/java/at/hannibal2/skyhanni/features/items/CrimsonArmorTier.kt new file mode 100644 index 000000000..b18a2ca8b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/items/CrimsonArmorTier.kt @@ -0,0 +1,115 @@ +package at.hannibal2.skyhanni.features.items + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderItemEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class CrimsonArmorTier { + + private val armors = mutableListOf<String>() + private val tiers = mutableMapOf<String, Int>() + private val STAR_FIND_PATCHER = Pattern.compile("(.*)§.✪(.*)") + private val armorParts = listOf("Helmet", "Chestplate", "Leggings", "Boots") + + @SubscribeEvent(priority = EventPriority.LOWEST) + fun onTooltip(event: ItemTooltipEvent) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.inventory.crimsonArmorStars) return + + val stack = event.itemStack ?: return + if (stack.stackSize != 1) return + val number = getCrimsonNumber(stack.name ?: return) + + if (number > 0) { + var name = stack.name!! + while (STAR_FIND_PATCHER.matcher(name).matches()) { + name = name.replaceFirst("§.✪".toRegex(), "") + } + name = name.trim() + event.toolTip[0] = "$name §c$number✪" + } + } + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + try { + val items = event.getConstant("Items")!! + if (items.has("crimson_armors")) { + armors.clear() + armors.addAll(items.getAsJsonArray("crimson_armors").map { it.asString }) + } + + tiers.clear() + if (items.has("crimson_tiers")) { + items.getAsJsonObject("crimson_tiers").entrySet().forEach { + tiers[it.key] = it.value.asInt + } + } + + } catch (e: Exception) { + e.printStackTrace() + LorenzUtils.error("error in RepositoryReloadEvent") + } + } + + @SubscribeEvent + fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(6)) return + + val stack = event.stack ?: return + if (stack.stackSize != 1) return + val number = getCrimsonNumber(stack.name ?: return) + val stackTip = if (number == -1) "" else number.toString() + + if (stackTip.isNotEmpty()) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + event.fontRenderer.drawStringWithShadow( + stackTip, + (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), + (event.y + 9).toFloat(), + 16777215 + ) + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + } + + private fun getCrimsonNumber(fullName: String): Int { + var name = fullName + if (armors.any { name.contains(it) } && armorParts.any { name.contains(it) }) { + var gold = 0 + var pink = 0 + var aqua = 0 + while (name.contains("§6✪")) { + name = name.replaceFirst("§6✪", "") + gold++ + } + while (name.contains("§d✪")) { + name = name.replaceFirst("§d✪", "") + pink++ + } + while (name.contains("§b✪")) { + name = name.replaceFirst("§b✪", "") + aqua++ + } + return (tiers.entries.find { name.contains(it.key) }?.value ?: 0) + if (aqua > 0) { + 10 + aqua + } else if (pink > 0) { + 5 + pink + } else { + gold + } + } + return -1 + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt index 1ad9aa39b..bc4caf181 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt @@ -17,11 +17,11 @@ class ItemDisplayOverlayFeatures { @SubscribeEvent fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - val item = event.stack ?: return + val stack = event.stack ?: return - if (!LorenzUtils.inSkyblock || item.stackSize != 1) return + if (!LorenzUtils.inSkyblock || stack.stackSize != 1) return - val stackTip = getStackTip(item) + val stackTip = getStackTip(stack) if (stackTip.isNotEmpty()) { GlStateManager.disableLighting() @@ -36,7 +36,6 @@ class ItemDisplayOverlayFeatures { GlStateManager.enableLighting() GlStateManager.enableDepth() } - } private fun getStackTip(item: ItemStack): String { |