aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-02-19 23:46:19 +0100
committerLinnea Gräf <nea@nea.moe>2024-02-19 23:46:19 +0100
commit5db2ea9e6c19c7c5054499ee7ca020546949df3d (patch)
tree44e6df4b1650b312911c577bc430fa44d104ad6e /src/main/java/at/hannibal2
parent128b8db7ad7e8633af231d6f547aca1eed3c1e95 (diff)
downloadSkyHanni-feat/sackmonitor.tar.gz
SkyHanni-feat/sackmonitor.tar.bz2
SkyHanni-feat/sackmonitor.zip
Add sack HUDfeat/sackmonitor
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackHudConfig.java34
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt26
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/SackHud.kt158
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt10
6 files changed, 233 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index e6be89916..fec3c0de2 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -217,6 +217,7 @@ import at.hannibal2.skyhanni.features.inventory.PowerStoneGuideFeatures
import at.hannibal2.skyhanni.features.inventory.QuickCraftFeatures
import at.hannibal2.skyhanni.features.inventory.RngMeterInventory
import at.hannibal2.skyhanni.features.inventory.SackDisplay
+import at.hannibal2.skyhanni.features.inventory.SackHud
import at.hannibal2.skyhanni.features.inventory.ShiftClickBrewing
import at.hannibal2.skyhanni.features.inventory.ShiftClickEquipment
import at.hannibal2.skyhanni.features.inventory.ShiftClickNPCSell
@@ -473,6 +474,7 @@ class SkyHanniMod {
loadModule(NEUItems)
// features
+ loadModule(SackHud)
loadModule(BazaarOrderHelper())
loadModule(AuctionsHighlighter())
loadModule(ChatFilter())
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
index ab7c71831..4d9f34aff 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
@@ -48,6 +48,11 @@ public class InventoryConfig {
public SackDisplayConfig sackDisplay = new SackDisplayConfig();
@Expose
+ @ConfigOption(name = "Sack HUD", desc = "")
+ @Accordion
+ public SackHudConfig sackHud = new SackHudConfig();
+
+ @Expose
@ConfigOption(name = "Chest Value", desc = "")
@Accordion
public ChestValueConfig chestValueConfig = new ChestValueConfig();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackHudConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackHudConfig.java
new file mode 100644
index 000000000..011ec2815
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/SackHudConfig.java
@@ -0,0 +1,34 @@
+package at.hannibal2.skyhanni.config.features.inventory;
+
+import at.hannibal2.skyhanni.config.FeatureToggle;
+import at.hannibal2.skyhanni.config.core.config.Position;
+import at.hannibal2.skyhanni.features.inventory.SackHud;
+import at.hannibal2.skyhanni.utils.NEUInternalName;
+import com.google.gson.annotations.Expose;
+import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.moulberry.moulconfig.annotations.ConfigEditorButton;
+import io.github.moulberry.moulconfig.annotations.ConfigOption;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SackHudConfig {
+ @Expose
+ @ConfigOption(name = "Enabled", desc = "Display a HUD with your sack contents.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean enabled = false;
+
+ @ConfigOption(
+ name = "Configure",
+ desc = "Configure the items display in your Sack HUD"
+ )
+ @ConfigEditorButton
+ public Runnable configure = SackHud::openConfigureScreen;
+
+ @Expose
+ public List<NEUInternalName> trackedItems = new ArrayList<>();
+
+ @Expose
+ public Position position = new Position(144, 139, false, true);
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
index ee9ea621c..bbb8c26aa 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
@@ -288,6 +288,16 @@ object SackAPI {
sackData = sackData.editCopy { this[item] = SackItem(amount, 0, SackStatus.CORRECT) }
}
+ /**
+ * Get a list of all known items the sacks.
+ */
+ fun getAllKnownSackItems(): Set<NEUInternalName> {
+ return ProfileStorageData.sackProfiles?.sackContents?.keys ?: emptySet()
+ }
+
+ /**
+ * Get information about how many items are contained within the sacks for the given item type.
+ */
fun fetchSackItem(item: NEUInternalName): SackItem {
sackData = ProfileStorageData.sackProfiles?.sackContents ?: return SackItem(0, 0, SackStatus.MISSING)
@@ -299,7 +309,21 @@ object SackAPI {
return sackData[item] ?: return SackItem(0, 0, SackStatus.MISSING)
}
- fun commandGetFromSacks(item: String, amount: Int) = LorenzUtils.sendCommandToServer("gfs $item $amount")
+ /**
+ * Send a request to hypixel to receive items from the sacks. Has a roughly 2 second cooldown.
+ * Note that our own internal command queueing sends faster than that cooldown, so additional measures need to be
+ * taken to slow down those requests.
+ */
+ fun commandGetFromSacks(
+ /**
+ * The [item id](NEUInternalName) or the name of the item you want to get.
+ */
+ item: String,
+ /**
+ * The amount of items you want to request
+ */
+ amount: Int
+ ) = LorenzUtils.sendCommandToServer("gfs $item $amount")
private fun saveSackData() {
ProfileStorageData.sackProfiles?.sackContents = sackData
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackHud.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackHud.kt
new file mode 100644
index 000000000..c19c61410
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackHud.kt
@@ -0,0 +1,158 @@
+package at.hannibal2.skyhanni.features.inventory
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.SackAPI
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.events.SackChangeEvent
+import at.hannibal2.skyhanni.utils.ItemUtils.getNBTName
+import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
+import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import io.github.moulberry.moulconfig.common.IItemStack
+import io.github.moulberry.moulconfig.common.MyResourceLocation
+import io.github.moulberry.moulconfig.forge.ForgeItemStack
+import io.github.moulberry.moulconfig.gui.GuiContext
+import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapperNew
+import io.github.moulberry.moulconfig.observer.ObservableList
+import io.github.moulberry.moulconfig.xml.Bind
+import io.github.moulberry.moulconfig.xml.XMLUniverse
+import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object SackHud {
+
+ private val config get() = SkyHanniMod.feature.inventory.sackHud
+ private var display: List<List<Any?>>? = null
+
+ @SubscribeEvent
+ fun onRender(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (!config.enabled) return
+ val d = display ?: return
+ config.position.renderStringsAndItems(d, posLabel = "Sack HUD")
+ }
+
+ @SubscribeEvent
+ fun onSackChange(event: SackChangeEvent) {
+ rebuildDisplay()
+ }
+
+ @SubscribeEvent
+ fun onProfileSwitchEvent(event: ProfileJoinEvent) {
+ rebuildDisplay()
+ }
+
+ fun rebuildDisplay() {
+ display =
+ config.trackedItems.map {
+ val itemStack = it.getItemStack()
+ val sackData = SackAPI.fetchSackItem(it)
+ listOf(itemStack, "${itemStack.getNBTName()}§7: §b${sackData.amount}")
+ }
+ }
+
+ @JvmStatic
+ fun openConfigureScreen() {
+ val editor = SackHudEditor()
+ editor.entries.addAll(config.trackedItems.map {
+ SackHudEntry(it, editor, it.getItemStack())
+ })
+ SkyHanniMod.screenToOpen = GuiScreenElementWrapperNew(
+ GuiContext(
+ XMLUniverse.getDefaultUniverse()
+ .load(editor, MyResourceLocation("skyhanni", "gui/sackhudeditor.xml"))
+ )
+ )
+ }
+
+ class SackHudEntry(
+ val neuItem: NEUInternalName,
+ val editor: SackHudEditor,
+ item: ItemStack,
+ ) {
+ @field: Bind
+ val icon: IItemStack = ForgeItemStack.of(item)
+
+ @field: Bind
+ val name: String = item.getNBTName() ?: "null"
+
+ @Bind
+ fun moveDown() {
+ val idx = editor.entries.indexOf(this)
+ if (idx == editor.entries.size - 1) return
+ editor.entries.removeAt(idx)
+ editor.entries.add(idx + 1, this)
+ editor.save()
+ }
+
+ @Bind
+ fun moveUp() {
+ val idx = editor.entries.indexOf(this)
+ if (idx == 0) return
+ editor.entries.removeAt(idx)
+ editor.entries.add(idx - 1, this)
+ editor.save()
+ }
+
+ @Bind
+ fun delete() {
+ editor.entries.remove(this)
+ editor.save()
+ }
+ }
+
+ class PotentialEntry(
+ val neuItem: NEUInternalName,
+ val editor: SackHudEditor,
+ val item: ItemStack,
+ ) {
+
+ @field: Bind
+ val icon: IItemStack = ForgeItemStack.of(item)
+
+ @field: Bind
+ val name: String = item.getNBTName() ?: "null"
+
+ @Bind
+ fun addToList() {
+ editor.entries.add(SackHudEntry(neuItem, editor, item))
+ editor.save()
+ }
+ }
+
+
+ class SackHudEditor {
+ @field: Bind
+ val entries = ObservableList(mutableListOf<SackHudEntry>())
+
+ @field: Bind
+ var searchField = ""
+ var lastSearch: String? = null
+
+ @field: Bind
+ var results = ObservableList(mutableListOf<PotentialEntry>())
+
+ @Bind
+ fun update(): String {
+ if (lastSearch == searchField)
+ return ""
+ lastSearch = searchField
+ results.delegate.clear()
+ for (itemId in SackAPI.getAllKnownSackItems()) {
+ val item = itemId.getItemStackOrNull() ?: continue
+ results.delegate.add(PotentialEntry(itemId, this, item))
+ }
+ results.delegate.retainAll {
+ it.name.contains(searchField, ignoreCase = true)
+ }
+ results.update()
+ return ""
+ }
+
+ fun save() {
+ config.trackedItems = entries.map { it.neuItem }
+ rebuildDisplay()
+ }
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 6b52d1eb2..9f2f45a1a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -49,6 +49,13 @@ object ItemUtils {
return list
}
+ fun ItemStack.getNBTName(): String? {
+ return this.tagCompound
+ ?.getCompoundTag("display")
+ ?.getString("Name")
+ ?.takeIf { it.isNotBlank() }
+ }
+
// TODO change else janni is sad
fun isCoopSoulBound(stack: ItemStack): Boolean =
stack.getLore().any {
@@ -61,7 +68,8 @@ object ItemUtils {
fun isRecombobulated(stack: ItemStack) = stack.isRecombobulated()
- fun isPet(name: String): Boolean = UtilsPatterns.petLevelPattern.matches(name) && !ignoredPetStrings.any { name.contains(it) }
+ fun isPet(name: String): Boolean =
+ UtilsPatterns.petLevelPattern.matches(name) && !ignoredPetStrings.any { name.contains(it) }
fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100