aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/ShowMotesNpcSellPrice.kt156
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt12
4 files changed, 182 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
index af531667f..48882f49e 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
@@ -566,6 +566,27 @@ public class RiftConfig {
@ConfigOption(name = "Burger Stacks", desc = "Set your McGrubber's burger stacks.")
@ConfigEditorSlider(minStep = 1, minValue = 0, maxValue = 5)
public int burgerStacks = 0;
+
+ @Expose
+ @ConfigOption(name = "Inventory value", desc = "")
+ @Accordion
+ public InventoryValue inventoryValue = new InventoryValue();
+
+ public static class InventoryValue {
+ @Expose
+ @ConfigOption(name = "Inventory value", desc = "Show total Motes NPC price for the current opened inventory.")
+ @ConfigEditorBoolean
+ public boolean enabled = true;
+
+ @Expose
+ @ConfigOption(name = "Number format type", desc = "Short: 1.2M\n" +
+ "Long: 1,200,000")
+ @ConfigEditorDropdown(values = {"Short", "Long"})
+ public int formatType = 0;
+
+ @Expose
+ public Position position = new Position(126, 156, false, true);
+ }
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/ShowMotesNpcSellPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/ShowMotesNpcSellPrice.kt
index c4c7b2786..36229aeb8 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/ShowMotesNpcSellPrice.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/ShowMotesNpcSellPrice.kt
@@ -1,35 +1,114 @@
package at.hannibal2.skyhanni.features.rift
-import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.features.rift.everywhere.RiftAPI
import at.hannibal2.skyhanni.features.rift.everywhere.RiftAPI.motesNpcPrice
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
+import at.hannibal2.skyhanni.utils.LorenzColor
+import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector
import at.hannibal2.skyhanni.utils.LorenzUtils.chat
+import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraftforge.event.entity.player.ItemTooltipEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class ShowMotesNpcSellPrice {
private val config get() = RiftAPI.config.motes
+ private var display = emptyList<List<Any>>()
private val pattern = ".*(?:§\\w)+You have (?:§\\w)+(?<amount>\\d) Grubber Stacks.*".toPattern()
+ private val itemMap = mutableMapOf<String, Pair<MutableList<Int>, Double>>()
+ private var inInventory = false
+ private val slotList = mutableListOf<Int>()
+
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestBackgroundRenderEvent) {
+ if (!isInventoryValueEnabled()) return
+ if (inInventory) {
+ config.inventoryValue.position.renderStringsAndItems(
+ display,
+ itemScale = 1.3,
+ posLabel = "Inventory Motes Value"
+ )
+ }
+ }
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!isInventoryValueEnabled()) return
+ if (event.isMod(10))
+ processItems()
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOW)
+ fun onDrawSelectedTemplate(event: GuiContainerEvent.BackgroundDrawnEvent) {
+ if (!isInventoryValueEnabled()) return
+ val name = InventoryUtils.openInventoryName()
+ if (!name.contains("Rift Storage")) return
+ for (slot in InventoryUtils.getItemsInOpenChest()) {
+ if (slotList.contains(slot.slotIndex))
+ slot highlight LorenzColor.GREEN
+ }
+ }
@SubscribeEvent
fun onItemTooltipLow(event: ItemTooltipEvent) {
- if (!isEnabled()) return
+ if (!isShowPriceEnabled()) return
val itemStack = event.itemStack ?: return
val baseMotes = itemStack.motesNpcPrice() ?: return
val burgerStacks = config.burgerStacks
- val motesPerItem = baseMotes + (burgerStacks * 5) * baseMotes / 100
val burgerText = if (burgerStacks > 0) "(${burgerStacks}x≡) " else ""
val size = itemStack.stackSize
if (size > 1) {
- val motes = motesPerItem * size
- event.toolTip.add("§6NPC price: $burgerText§d${motes.addSeparators()} Motes §7($size x §d${motesPerItem.addSeparators()} Motes§7)")
+ event.toolTip.add("§6NPC price: $burgerText§d${baseMotes.addSeparators()} Motes §7($size x §d${(baseMotes / size).addSeparators()} Motes§7)")
} else {
- event.toolTip.add("§6NPC price: $burgerText§d${motesPerItem.addSeparators()} Motes")
+ event.toolTip.add("§6NPC price: $burgerText§d${baseMotes.addSeparators()} Motes")
+ }
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryOpenEvent) {
+ reset()
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ reset()
+ }
+
+ private fun reset() {
+ if (!isInventoryValueEnabled()) return
+ itemMap.clear()
+ slotList.clear()
+ inInventory = false
+ }
+
+ private fun processItems() {
+ val inventoryName = InventoryUtils.openInventoryName()
+ if (!inventoryName.contains("Rift Storage")) return
+ val stacks = InventoryUtils.getItemsInOpenChest().map { it.slotIndex to it.stack }
+ itemMap.clear()
+ for ((index, stack) in stacks) {
+ val itemValue = stack.motesNpcPrice() ?: continue
+ if (itemMap.contains(stack.getInternalName())) {
+ val (oldIndex, oldValue) = itemMap[stack.getInternalName()] ?: return
+ oldIndex.add(index)
+ itemMap[stack.getInternalName()] = Pair(oldIndex, oldValue + itemValue)
+ } else {
+ itemMap[stack.getInternalName()] = Pair(mutableListOf(index), itemValue)
+ }
}
+ inInventory = true
+ update()
}
@SubscribeEvent
@@ -41,5 +120,68 @@ class ShowMotesNpcSellPrice {
}
}
- fun isEnabled() = RiftAPI.inRift() && config.showPrice
+ private fun update() {
+ display = drawDisplay()
+ }
+
+ private fun drawDisplay() = buildList<List<Any>> {
+ val newDisplay = mutableListOf<List<Any>>()
+ newDisplay.addAsSingletonList("§7Item Values:")
+ val sorted = itemMap.toList().sortedByDescending { it.second.second }.toMap().toMutableMap()
+
+ for ((internalName, pair) in sorted) {
+ newDisplay.add(buildList {
+ val (index, value) = pair
+ val dashColor = if (slotList.containsAll(index)) "§a" else "§7"
+ add(" $dashColor- ")
+ val stack = NEUItems.getItemStack(internalName)
+ add(stack)
+ val price = value.formatPrice()
+ val valuePer = stack.motesNpcPrice() ?: continue
+ val tips = buildList {
+ add("§eClick to highlight in the chest !")
+ add("§6Value per: §d$valuePer Motes")
+ add("§6Total in chest: §d${(value / valuePer).toInt()}")
+ }
+ add(Renderable.clickAndHover("§6${stack.displayName}: §b$price", tips) {
+ for (slot in InventoryUtils.getItemsInOpenChest()) {
+ if (index.contains(slot.slotIndex)) {
+ if (slotList.contains(slot.slotIndex)) {
+ slotList.remove(slot.slotIndex)
+ } else {
+ slotList.add(slot.slotIndex)
+ }
+ }
+ }
+ })
+ })
+ }
+ val total = itemMap.values.fold(0.0) { acc, pair -> acc + pair.second }.formatPrice()
+ newDisplay.addAsSingletonList("§7Total price: §b$total")
+ val name = FormatType.values()[config.inventoryValue.formatType].type
+ newDisplay.addAsSingletonList("§7Price format: §c$name")
+ newDisplay.addSelector(" ", FormatType.values(),
+ getName = { type -> type.type },
+ isCurrent = { it.ordinal == config.inventoryValue.formatType },
+ onChange = {
+ config.inventoryValue.formatType = it.ordinal
+ update()
+ })
+ return newDisplay
+ }
+
+ enum class FormatType(val type: String) {
+ SHORT("Short"),
+ LONG("Long")
+ }
+
+ private fun Double.formatPrice(): String = when (config.inventoryValue.formatType) {
+ 0 -> NumberUtil.format(this)
+ 1 -> this.addSeparators()
+ else -> "0"
+ }
+
+ private fun isShowPriceEnabled() = RiftAPI.inRift() && config.showPrice
+
+ private fun isInventoryValueEnabled() = RiftAPI.inRift() && config.inventoryValue.enabled
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt
index 8d4c6cf99..4609b3057 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt
@@ -15,7 +15,12 @@ object RiftAPI {
// internal name -> motes
var motesPrice = emptyMap<String, Double>()
- fun ItemStack.motesNpcPrice() = motesPrice[getInternalName()]
+ fun ItemStack.motesNpcPrice(): Double? {
+ val baseMotes = motesPrice[getInternalName()] ?: return null
+ val burgerStacks = config.motes.burgerStacks
+ return baseMotes + (burgerStacks * 5) * baseMotes / 100
+ }
+
fun inLivingCave() = LorenzUtils.skyBlockArea == "Living Cave"
fun inLivingStillness() = LorenzUtils.skyBlockArea == "Living Stillness"
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
index 9edd186d2..9e1ade646 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
@@ -23,11 +23,11 @@ object InventoryUtils {
}
fun openInventoryName() = Minecraft.getMinecraft().currentScreen.let {
- if (it is GuiChest) {
- val chest = it.inventorySlots as ContainerChest
- chest.getInventoryName()
- } else ""
- }
+ if (it is GuiChest) {
+ val chest = it.inventorySlots as ContainerChest
+ chest.getInventoryName()
+ } else ""
+ }
fun ContainerChest.getInventoryName() = this.lowerChestInventory.displayName.unformattedText.trim()
@@ -39,7 +39,7 @@ object InventoryUtils {
fun getArmor(): Array<ItemStack?> = Minecraft.getMinecraft().thePlayer.inventory.armorInventory
fun inStorage() =
- openInventoryName().let { it.contains("Storage") || it.contains("Ender Chest") || it.contains("Backpack") }
+ openInventoryName().let { (it.contains("Storage") && it != "Rift Storage") || it.contains("Ender Chest") || it.contains("Backpack")}
fun getItemInHand(): ItemStack? = Minecraft.getMinecraft().thePlayer.heldItem
} \ No newline at end of file