diff options
author | HiZe_ <superhize@hotmail.com> | 2023-05-18 04:22:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 04:22:53 +0200 |
commit | 66877204cf85689b57eb57d5d808949d40b0e09e (patch) | |
tree | 597908f833f9625ab8772a6039b51d31b9e483f1 /src/main | |
parent | e6544987a070beaa4d1169d3a52181716ea109c5 (diff) | |
download | skyhanni-66877204cf85689b57eb57d5d808949d40b0e09e.tar.gz skyhanni-66877204cf85689b57eb57d5d808949d40b0e09e.tar.bz2 skyhanni-66877204cf85689b57eb57d5d808949d40b0e09e.zip |
Added Sacks Items Display (#110)
Diffstat (limited to 'src/main')
3 files changed, 202 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 976e99e2c..00f3cd8e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -273,6 +273,7 @@ class SkyHanniMod { loadModule(TrevorSolver) loadModule(BingoCardTips()) loadModule(GardenVisitorDropStatistics) + loadModule(SackDisplay()) 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 aa5992c57..c6641afe9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.config.features; +import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.*; @@ -112,6 +113,40 @@ public class Inventory { public boolean jacobFarmingContestRealTime = true; @Expose + @ConfigOption(name = "Sack Items Display", desc = "") + @Accordion + public SackDisplay sackDisplay = new SackDisplay(); + + public static class SackDisplay { + + @Expose + @ConfigOption(name = "Enabled", desc = "Show contained items inside a sack inventory.") + @ConfigEditorBoolean + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Number Format", desc = "Either show Default, Formatted or Unformatted numbers." + + "§eDefault: §72,240/2.2k\n" + + "§eFormatted: §72.2k/2.2k\n" + + "§eUnformatted: §72,240/2,200") + @ConfigEditorDropdown(values = {"Default", "Formatted", "Unformatted"}) + public int numberFormat = 1; + + @Expose + @ConfigOption(name = "Sorting Type", desc = "Sorting type of items in sacks.") + @ConfigEditorDropdown(values = {"Descending", "Ascending"}) + public int sortingType = 0; + + @Expose + @ConfigOption(name = "Show in Runes Sack", desc = "Show contained items inside a runes sack.") + @ConfigEditorBoolean + public boolean showRunes = false; + + @Expose + public Position position = new Position(155, -57, false, true); + } + + @Expose @ConfigOption( name = "Item number", desc = "Showing the item number as a stack size for these items." @@ -167,4 +202,6 @@ public class Inventory { desc = "Highlight own items that are sold in green and that are expired in red.") @ConfigEditorBoolean public boolean highlightAuctions = true; + + } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt new file mode 100644 index 000000000..e3e4d3ac8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt @@ -0,0 +1,164 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class SackDisplay { + + companion object { + var inInventory = false + var isRuneSack = false + } + + private val config get() = SkyHanniMod.feature.inventory.sackDisplay + private var display = listOf<List<Any>>() + private val sackItem = mutableMapOf<Pair<String, String>, Pair<String, String>>() + private val runeItem = mutableMapOf<Pair<String, String>, String>() + private val sackPattern = "^(.* Sack|Enchanted .* Sack)$".toPattern() + + private val numPattern = + "(?:(?:§[0-9a-f](?<level>I{1,3})§7:)?|(?:§7Stored:)?) (?<color>§[0-9a-f])(?<stored>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)§7/(?<total>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)".toPattern() + + + @SubscribeEvent + fun onBackgroundDraw(event: GuiRenderEvent.ChestBackgroundRenderEvent) { + if (inInventory) { + config.position.renderStringsAndItems( + display, + extraSpace = 5, + itemScale = 1.3, + posLabel = "Sacks Items" + ) + } + } + + private fun updateDisplay() { + display = drawDisplay() + } + + private fun update() { + updateDisplay() + } + + private fun drawDisplay(): List<List<Any>> { + val newDisplay = mutableListOf<List<Any>>() + + if (sackItem.isNotEmpty()) { + val sortedPairs = when (config.sortingType) { + 0 -> sackItem.entries.sortedByDescending { it.value.first.formatNumber().toInt() } + 1 -> sackItem.entries.sortedBy { it.value.first.formatNumber().toInt() } + else -> { + sackItem.entries.sortedByDescending { it.value.first.formatNumber().toInt() } + } + } + + newDisplay.addAsSingletonList("§7Items in Sacks:") + for ((name, pair) in sortedPairs) { + val list = mutableListOf<Any>() + val (colorCode, itemName) = name + val internalName = NEUItems.getInternalName(itemName) + val itemStack = NEUItems.getItemStack(internalName) + list.add(" §7- ") + list.add(itemStack) + list.add(" $itemName: ") + val item = when (config.numberFormat) { + 0 -> "$colorCode${pair.first}§7/§b${pair.second}" + 1 -> "$colorCode${NumberUtil.format(pair.first.formatNumber())}§7/§b${pair.second}" + 2 -> "$colorCode${pair.first}§7/§b${String.format("%,d", pair.second.formatNumber())}" + else -> "$colorCode${pair.first}§7/§b${pair.second}" + } + list.add(item) + if (colorCode == "§a") // §a = Full, §e = Not full, §7 = Empty + list.add(" §c§l(Full!)") + newDisplay.add(list) + } + } + + if (runeItem.isNotEmpty()) { + newDisplay.addAsSingletonList("§7Items in Sacks:") + for ((name, runeLine) in runeItem) { + val list = mutableListOf<Any>() + val colorCode = name.first + val itemName = name.second + list.add(" §7- ") + list.add(" $itemName $runeLine") + if (colorCode == "§a") + list.add(" §c§l(Full!)") + newDisplay.add(list) + } + } + + return newDisplay + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + inInventory = false + isRuneSack = false + sackItem.clear() + runeItem.clear() + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!isEnabled()) return + val inventoryName = event.inventoryName + if (!isRuneDisplayEnabled() && inventoryName == "Runes Sack") return + val match = sackPattern.matcher(inventoryName).matches() + if (!match) return + val stacks = event.inventoryItems + isRuneSack = inventoryName == "Runes sacks" + inInventory = true + var runeLine = "" + for ((_, stack) in stacks) { + val name = stack.name ?: continue + val lore = stack.getLore() + loop@ for (line in lore) { + numPattern.matchMatcher(line) { + val stored = group("stored") + val total = group("total") + val color = group("color") + val colored = Pair(color, name) + val item = Pair(stored, total) + if (group("level") != null) { + val level = group("level") + if (level == "I") { + runeLine = "§cI $color$stored§7/§b$total" + continue@loop + } + if (level == "II") { + runeLine += "§7, §cII $color$stored§7/§b$total" + continue@loop + } + if (level == "III") { + runeLine += "§7, §cIII $color$stored§7/§b$total" + } + + runeItem.put(colored, runeLine) + } else { + sackItem.put(colored, item) + } + + } + } + + } + + update() + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled + private fun isRuneDisplayEnabled() = config.showRunes +}
\ No newline at end of file |