diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-22 23:42:31 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-22 23:42:31 +0200 |
commit | fbc21858d44e5e78c33628b0daa6824bcc45db60 (patch) | |
tree | 95189d7b6aefa26dd782efa483189cbeb28827aa /src/main/java/at | |
parent | 6e095a5c2113b5ee37b5c2acf8d2dfdef81291ee (diff) | |
parent | 908fd8d0d24ca9c57a83dc22c07a7e043af37044 (diff) | |
download | skyhanni-fbc21858d44e5e78c33628b0daa6824bcc45db60.tar.gz skyhanni-fbc21858d44e5e78c33628b0daa6824bcc45db60.tar.bz2 skyhanni-fbc21858d44e5e78c33628b0daa6824bcc45db60.zip |
Merge remote-tracking branch 'origin/beta' into beta
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java | 50 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt | 296 |
2 files changed, 288 insertions, 58 deletions
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 c6641afe9..c6085250f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java @@ -125,7 +125,7 @@ public class Inventory { public boolean enabled = true; @Expose - @ConfigOption(name = "Number Format", desc = "Either show Default, Formatted or Unformatted numbers." + + @ConfigOption(name = "Number Format", desc = "Either show Default, Formatted or Unformatted numbers.\n" + "§eDefault: §72,240/2.2k\n" + "§eFormatted: §72.2k/2.2k\n" + "§eUnformatted: §72,240/2,200") @@ -133,17 +133,57 @@ public class Inventory { public int numberFormat = 1; @Expose - @ConfigOption(name = "Sorting Type", desc = "Sorting type of items in sacks.") - @ConfigEditorDropdown(values = {"Descending", "Ascending"}) + @ConfigOption(name = "Extra space", desc = "Space between each line of text.") + @ConfigEditorSlider( + minValue = 0, + maxValue = 10, + minStep = 1) + public int extraSpace = 1; + + @Expose + @ConfigOption(name = "Sorting Type", desc = "Sorting type of items in sack.") + @ConfigEditorDropdown(values = {"Descending (Stored)", "Ascending (Stored)", "Descending (Price)", "Ascending (Price)"}) public int sortingType = 0; @Expose + @ConfigOption(name = "Item To Show", desc = "Choose how many items are displayed. (Some sacks have too many items to fit\n" + + "in larger gui scale, like the nether sack.)") + @ConfigEditorSlider( + minValue = 0, + maxValue = 45, + minStep = 1 + ) + public int itemToShow = 15; + + @Expose + @ConfigOption(name = "Show Empty Item", desc = "Show empty item quantity in the display.") + @ConfigEditorBoolean + public boolean showEmpty = true; + + @Expose + @ConfigOption(name = "Show Price", desc = "Show price for each item in sack.") + @ConfigEditorBoolean + public boolean showPrice = true; + + @Expose + @ConfigOption(name = "Price Format", desc = "Format of the price displayed.\n" + + "§eFormatted: §7(12k)\n" + + "§eUnformatted: §7(12,421)") + @ConfigEditorDropdown(values = {"Formatted", "Unformatted"}) + public int priceFormat = 0; + + @Expose + @ConfigOption(name = "Show Price From", desc = "Show price from Bazaar or NPC.") + @ConfigEditorDropdown(values = {"Bazaar", "NPC"}) + public int priceFrom = 1; + + @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); + public Position position = new Position(144, 139, false, true); } @Expose @@ -204,4 +244,4 @@ public class Inventory { public boolean highlightAuctions = true; -} +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt index e3e4d3ac8..93ed11873 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt @@ -4,15 +4,21 @@ 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.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName 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.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SackDisplay { @@ -20,16 +26,30 @@ class SackDisplay { companion object { var inInventory = false var isRuneSack = false + var isGemstoneSack = 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 sackItem = mutableMapOf<String, Item>() + private val runeItem = mutableMapOf<String, Rune>() + private val gemstoneItem = mutableMapOf<String, Gemstone>() private val sackPattern = "^(.* Sack|Enchanted .* Sack)$".toPattern() + private val gemstoneMap = mapOf( + "Jade Gemstones" to "ROUGH_JADE_GEM", + "Amber Gemstones" to "ROUGH_AMBER_GEM", + "Topaz Gemstones" to "ROUGH_TOPAZ_GEM", + "Sapphire Gemstones" to "ROUGH_SAPPHIRE_GEM", + "Amethyst Gemstones" to "ROUGH_AMETHYST_GEM", + "Jasper Gemstones" to "ROUGH_JASPER_GEM", + "Ruby Gemstones" to "ROUGH_RUBY_GEM", + "Opal Gemstones" to "ROUGH_OPAL_GEM" + ) 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() + private val gemstonePattern = + " (?:§[0-9a-f])(?<gemrarity>[A-z]*): §[0-9a-f](?<stored>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?) §[0-9a-f]\\((?:\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)\\)".toPattern() @SubscribeEvent @@ -37,7 +57,7 @@ class SackDisplay { if (inInventory) { config.position.renderStringsAndItems( display, - extraSpace = 5, + extraSpace = config.extraSpace, itemScale = 1.3, posLabel = "Sacks Items" ) @@ -54,61 +74,134 @@ class SackDisplay { private fun drawDisplay(): List<List<Any>> { val newDisplay = mutableListOf<List<Any>>() - + var totalPrice = 0 + var rendered = 0 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() } + val sortedPairs: MutableMap<String, Item> = when (config.sortingType) { + 0 -> sackItem.toList().sortedByDescending { it.second.stored.formatNumber() }.toMap().toMutableMap() + 1 -> sackItem.toList().sortedBy { it.second.stored.formatNumber() }.toMap().toMutableMap() + 2 -> sackItem.toList().sortedByDescending { it.second.price }.toMap().toMutableMap() + 3 -> sackItem.toList().sortedBy { it.second.price }.toMap().toMutableMap() + else -> sackItem.toList().sortedByDescending { it.second.stored.formatNumber() }.toMap().toMutableMap() + } + + sortedPairs.toList().forEach { + if (it.second.stored == "0" && !config.showEmpty) { + sortedPairs.remove(it.first) } } - newDisplay.addAsSingletonList("§7Items in Sacks:") - for ((name, pair) in sortedPairs) { + newDisplay.addAsSingletonList("§7Items in Sacks: §o(Rendering ${if (config.itemToShow > sortedPairs.size) sortedPairs.size else config.itemToShow} of ${sortedPairs.size} items)") + for ((itemName, item) in sortedPairs) { + val (internalName, colorCode, stored, total, price) = item + totalPrice += price + if (rendered >= config.itemToShow) continue val list = mutableListOf<Any>() - val (colorCode, itemName) = name - val internalName = NEUItems.getInternalName(itemName) + if (stored == "0" && !config.showEmpty) continue 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(Renderable.optionalLink("$itemName: ", { + if (!NEUItems.neuHasFocus() && !LorenzUtils.noTradeMode) { + LorenzUtils.sendCommandToServer("bz ${itemName.removeColor()}") + } + }) { !NEUItems.neuHasFocus() }) + + val displayItem = when (config.numberFormat) { + 0 -> "$colorCode${stored}§7/§b${total}" + 1 -> "$colorCode${NumberUtil.format(stored.formatNumber())}§7/§b${total}" + 2 -> "$colorCode${stored}§7/§b${total.formatNumber().toInt().addSeparators()}" + else -> "$colorCode${stored}§7/§b${total}" } - list.add(item) + + list.add(displayItem) if (colorCode == "§a") // §a = Full, §e = Not full, §7 = Empty list.add(" §c§l(Full!)") + + if (config.showPrice && price != 0) + list.add(" §7(§6${format(price)}§7)") + + rendered++ newDisplay.add(list) } + + newDisplay.add(buildList { + add("§eSort by: §6Stored ") + add(Renderable.optionalLink("§7[§bDESC§7] ", { + config.sortingType = 0 + update() + }) { !NEUItems.neuHasFocus() }) + add(Renderable.optionalLink("§7[§bASC§7] ", { + config.sortingType = 1 + update() + }) { !NEUItems.neuHasFocus() }) + + if (config.showPrice) { + add("§6Price ") + add(Renderable.optionalLink("§7[§bDESC§7] ", { + config.sortingType = 2 + update() + }) { !NEUItems.neuHasFocus() }) + add(Renderable.optionalLink("§7[§bASC§7]", { + config.sortingType = 3 + update() + }) { !NEUItems.neuHasFocus() }) + } + }) + + if (config.showPrice) + newDisplay.addAsSingletonList("§eTotal price: §6${format(totalPrice)}") } if (runeItem.isNotEmpty()) { - newDisplay.addAsSingletonList("§7Items in Sacks:") - for ((name, runeLine) in runeItem) { + newDisplay.addAsSingletonList("§7Runes:") + for ((name, rune) in runeItem) { val list = mutableListOf<Any>() - val colorCode = name.first - val itemName = name.second + val (stack, lv1, lv2, lv3) = rune list.add(" §7- ") - list.add(" $itemName $runeLine") - if (colorCode == "§a") - list.add(" §c§l(Full!)") + stack?.let { list.add(it) } + list.add(name) + list.add(" §f(§e$lv1§7-§e$lv2§7-§e$lv3§f)") newDisplay.add(list) } } + if (gemstoneItem.isNotEmpty()) { + newDisplay.addAsSingletonList("§7Gemstones:") + for ((name, gem) in gemstoneItem) { + val (internalName, rough, flawed, fine, flawless, roughprice, flawedprice, fineprice, flawlessprice) = gem + newDisplay.add(buildList { + add(" §7- ") + add(NEUItems.getItemStack(internalName)) + add(Renderable.optionalLink("$name: ", { + if (!NEUItems.neuHasFocus() && !LorenzUtils.noTradeMode) { + LorenzUtils.sendCommandToServer("bz ${name.removeColor().dropLast(1)}") + } + }) { !NEUItems.neuHasFocus() }) + add(" ($rough-§a$flawed-§9$fine-§5$flawless)") + val price = (roughprice + flawedprice + fineprice + flawlessprice) + totalPrice += price + if (config.showPrice && price != 0) + add(" §7(§6${format(price)}§7)") + }) + } + if (config.showPrice) + newDisplay.addAsSingletonList("§eTotal price: §6${format(totalPrice)}") + } return newDisplay } + private fun format(price: Int) = if (config.priceFormat == 0) NumberUtil.format(price) else price.addSeparators() + @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { inInventory = false isRuneSack = false - sackItem.clear() + isGemstoneSack = false runeItem.clear() + gemstoneItem.clear() + sackItem.clear() } @SubscribeEvent @@ -119,46 +212,143 @@ class SackDisplay { val match = sackPattern.matcher(inventoryName).matches() if (!match) return val stacks = event.inventoryItems - isRuneSack = inventoryName == "Runes sacks" + isRuneSack = inventoryName == "Runes Sack" + isGemstoneSack = inventoryName == "Gemstones Sack" inInventory = true - var runeLine = "" for ((_, stack) in stacks) { val name = stack.name ?: continue val lore = stack.getLore() + val gem = Gemstone() + val rune = Rune() + val item = Item() 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 (isGemstoneSack) { + gemstonePattern.matchMatcher(line) { + val rarity = group("gemrarity") + val stored = group("stored") + gem.internalName = gemstoneMap[name.removeColor()].toString() + if (gemstoneMap.containsKey(name.removeColor())) { + val internalName = + "${rarity.uppercase()}_${name.uppercase().split(" ")[0].removeColor()}_GEM" + + when (rarity) { + "Rough" -> { + gem.rough = stored + gem.roughPrice = calculatePrice(internalName, stored) + } + + "Flawed" -> { + gem.flawed = stored + gem.flawedPrice = calculatePrice(internalName, stored) + } + + "Fine" -> { + gem.fine = stored + gem.finePrice = calculatePrice(internalName, stored) + } + + "Flawless" -> { + gem.flawless = stored + gem.flawlessPrice = calculatePrice(internalName, stored) + } + } + gemstoneItem[name] = gem } - if (level == "III") { - runeLine += "§7, §cIII $color$stored§7/§b$total" + } + } else { + numPattern.matchMatcher(line) { + val stored = group("stored") + val total = group("total") + val internalName = stack.getInternalName() + item.internalName = internalName + item.colorCode = group("color") + val price: Int = when (config.priceFrom) { + 0 -> { + (NEUItems.getPrice(internalName) * stored.formatNumber()).toInt() + } + + 1 -> { + try { + val bazaarData = BazaarApi.getBazaarDataByInternalName(internalName) + (((bazaarData?.npcPrice?.toInt() ?: 0) * stored.formatNumber())).toInt() + + } catch (e: Exception) { + 0 + } + } + + else -> 0 } + item.stored = stored + item.total = total + item.price = price - runeItem.put(colored, runeLine) - } else { - sackItem.put(colored, item) + if (isRuneSack) { + val level = group("level") + rune.stack = stack + if (level == "I") { + rune.lvl1 = stored + continue@loop + } + if (level == "II") { + rune.lvl2 = stored + continue@loop + } + if (level == "III") { + rune.lvl3 = stored + } + runeItem.put(name, rune) + } else { + sackItem.put(name, item) + } } - } } - } - update() } + + data class Gemstone( + var internalName: String = "", + var rough: String = "0", + var flawed: String = "0", + var fine: String = "0", + var flawless: String = "0", + var roughPrice: Int = 0, + var flawedPrice: Int = 0, + var finePrice: Int = 0, + var flawlessPrice: Int = 0, + ) + + data class Rune( + var stack: ItemStack? = null, + var lvl1: String = "0", + var lvl2: String = "0", + var lvl3: String = "0", + ) + + data class Item( + var internalName: String = "", + var colorCode: String = "", + var stored: String = "0", + var total: String = "0", + var price: Int = 0, + ) + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled private fun isRuneDisplayEnabled() = config.showRunes + + private fun calculatePrice(internalName: String, stored: String) = when (config.priceFrom) { + 0 -> (NEUItems.getPrice(internalName) * stored.formatNumber()).toInt() + + 1 -> try { + val npcPrice = BazaarApi.getBazaarDataByInternalName(internalName)?.npcPrice ?: 0.0 + (npcPrice * stored.formatNumber()).toInt() + } catch (e: Exception) { + 0 + } + + else -> 0 + } }
\ No newline at end of file |