diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-01-07 08:47:50 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-01-07 08:47:50 +0100 |
commit | de538b99d540f155d49b4694b195b89ea60f18b9 (patch) | |
tree | 47cb32890df866992c9e3f8caadab2216f8efe81 /src/main/java/at/hannibal2/skyhanni | |
parent | f9d037aff483bff61b800fffa96d0afe8a85a9ef (diff) | |
download | skyhanni-de538b99d540f155d49b4694b195b89ea60f18b9.tar.gz skyhanni-de538b99d540f155d49b4694b195b89ea60f18b9.tar.bz2 skyhanni-de538b99d540f155d49b4694b195b89ea60f18b9.zip |
Added minion name display.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
4 files changed, 86 insertions, 37 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java index eef96aa56..b3d138269 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java @@ -14,5 +14,8 @@ public class Hidden { public String currentPet = ""; @Expose - public Map<String, Long> minions = new HashMap<>(); + public Map<String, Long> minionLastClick = new HashMap<>(); + + @Expose + public Map<String, String> minionName = new HashMap<>(); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java index 718c46576..d29eb45bd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java @@ -6,6 +6,11 @@ import com.google.gson.annotations.Expose; public class Minions { + @Expose + @ConfigOption(name = "Name Display", desc = "Show the minion name and tier over the minion.") + @ConfigEditorBoolean + public boolean nameDisplay = true; + @ConfigOption(name = "Last Clicked", desc = "") @ConfigEditorAccordion(id = 0) public boolean lastClickedMinion = false; @@ -43,15 +48,15 @@ public class Minions { public boolean emptiedTime = false; @Expose - @ConfigOption(name = "Emptied Time Display", desc = "Show the time when the hopper in the minion was last emptied") + @ConfigOption(name = "Emptied Time Display", desc = "Show the time when the hopper in the minion was last emptied.") @ConfigEditorBoolean @ConfigAccordionId(id = 1) public boolean emptiedTimeDisplay = false; @Expose @ConfigOption( - name = "Emptied Time Distance", - desc = "At what distance is this display shown" + name = "Distance", + desc = "At what distance is the minion display shown." ) @ConfigEditorSlider( minValue = 3, @@ -59,7 +64,7 @@ public class Minions { minStep = 1 ) @ConfigAccordionId(id = 1) - public int emptiedTimeDistance = 10; + public int distance = 10; @ConfigOption(name = "Hopper Profit", desc = "") @ConfigEditorAccordion(id = 2) @@ -69,7 +74,7 @@ public class Minions { @ConfigOption(name = "Hopper Profit Display", desc = "Using the held coins and the last empty time to calculate the coins a hopper collects in a day") @ConfigEditorBoolean @ConfigAccordionId(id = 2) - public boolean hopperProfitDisplay = false; + public boolean hopperProfitDisplay = true; @Expose @ConfigOption(name = "Best Sell Method Position", desc = "") diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionData.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionData.kt new file mode 100644 index 000000000..02ee25b51 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionData.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.features.minion + +import scala.Serializable + +class MinionData(var name: String,var lastClicked: Long) : Serializable
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt index ee72ff542..5751fefd7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils.formatInteger import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex +import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderString import net.minecraft.client.Minecraft @@ -28,21 +29,24 @@ import java.awt.Color class MinionFeatures { - var lastClickedEntity: LorenzVec? = null - var lastMinion: LorenzVec? = null - var lastMinionOpened = 0L - var minionInventoryOpen = false + private var lastClickedEntity: LorenzVec? = null + private var lastMinion: LorenzVec? = null + private var lastMinionOpened = 0L + private var minionInventoryOpen = false - var lastCoinsRecived = 0L - var lastMinionPickedUp = 0L - val minions = mutableMapOf<LorenzVec, Long>() - var coinsPerDay = "" + private var lastCoinsRecived = 0L + private var lastMinionPickedUp = 0L + private val minions = mutableMapOf<LorenzVec, MinionData>() + private var coinsPerDay = "" @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { - for (minion in SkyHanniMod.feature.hidden.minions) { - val vec = LorenzVec.decodeFromString(minion.key) - minions[vec] = minion.value + for (minion in SkyHanniMod.feature.hidden.minionLastClick) { + val key = minion.key + val vec = LorenzVec.decodeFromString(key) + val name = SkyHanniMod.feature.hidden.minionName[key] ?: "§cNo name saved!" + val data = MinionData(name, minion.value) + minions[vec] = data } } @@ -90,9 +94,20 @@ class MinionFeatures { fun onTick(event: TickEvent.ClientTickEvent) { if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return - if (InventoryUtils.currentlyOpenInventory().contains("Minion")) { - if (lastClickedEntity != null) { - lastMinion = lastClickedEntity + val openInventory = InventoryUtils.currentlyOpenInventory() + if (openInventory.contains("Minion")) { + lastClickedEntity?.let { + val name = getMinionName(openInventory) + if (!minions.contains(it)) { + minions[it] = MinionData(name, 0) + saveConfig() + } else { + if (minions[it]!!.name != name) { + minions[it]!!.name = name + saveConfig() + } + } + lastMinion = it lastClickedEntity = null minionInventoryOpen = true lastMinionOpened = 0 @@ -106,11 +121,11 @@ class MinionFeatures { if (location != null) { if (System.currentTimeMillis() - lastCoinsRecived < 2_000) { - minions[location] = System.currentTimeMillis() + minions[location]!!.lastClicked = System.currentTimeMillis() saveConfig() } if (location !in minions) { - minions[location] = 0 + minions[location]!!.lastClicked = 0 } if (System.currentTimeMillis() - lastMinionPickedUp < 2_000) { @@ -130,6 +145,15 @@ class MinionFeatures { } } + private fun getMinionName(inventoryName: String): String { + var list = inventoryName.split(" ").toList() + val last = list.last() + val number = last.romanToDecimal() + list = list.dropLast(1) + + return list.joinToString(" ") + " $number" + } + private fun updateCoinsPerDay(): String { val loc = lastMinion!! val slot = InventoryUtils.getItemsInOpenChest().find { it.slotNumber == 28 } ?: return "" @@ -139,8 +163,8 @@ class MinionFeatures { if (coinsPerDay != "") return coinsPerDay - val lastClicked = minions.getOrDefault(loc, -1) - if (lastClicked == -1L) { + val lastClicked = minions[loc]!!.lastClicked + if (lastClicked == 0L) { return "Can't calculate coins/day: No time data available!" } val duration = System.currentTimeMillis() - lastClicked @@ -156,13 +180,17 @@ class MinionFeatures { } private fun saveConfig() { - val minionConfig = SkyHanniMod.feature.hidden.minions + val minionConfig = SkyHanniMod.feature.hidden.minionLastClick + val minionName = SkyHanniMod.feature.hidden.minionName minionConfig.clear() + minionName.clear() for (minion in minions) { - minionConfig[minion.key.encodeToString()] = minion.value + val coordinates = minion.key.encodeToString() + val data = minion.value + minionConfig[coordinates] = data.lastClicked + minionName[coordinates] = data.name } - } @SubscribeEvent @@ -189,21 +217,29 @@ class MinionFeatures { @SubscribeEvent fun onRenderLastEmptied(event: RenderWorldLastEvent) { if (!LorenzUtils.inSkyBlock) return - if (!SkyHanniMod.feature.minions.emptiedTimeDisplay) return if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return val playerLocation = LocationUtils.playerLocation() val playerEyeLocation = LocationUtils.playerEyeLocation() for (minion in minions) { - val location = minion.key - if (playerLocation.distance(location) < SkyHanniMod.feature.minions.emptiedTimeDistance) { - val lastEmptied = minion.value - if (lastEmptied == 0L) continue - val duration = System.currentTimeMillis() - lastEmptied - val format = StringUtils.formatDuration(duration / 1000) + " ago" - if (LocationUtils.canSee(playerEyeLocation, location)) { - val text = "§eHopper Emptied: $format" - event.drawString(location.add(0.0, 2.0, 0.0), text, true) + val location = minion.key.add(0.0, 1.0, 0.0) + if (LocationUtils.canSee(playerEyeLocation, location)) { + val lastEmptied = minion.value.lastClicked + if (playerLocation.distance(location) < SkyHanniMod.feature.minions.distance) { + + if (SkyHanniMod.feature.minions.nameDisplay) { + val name = "§9" + minion.value.name + event.drawString(location.add(0.0, 0.65, 0.0), name, true) + } + + if (SkyHanniMod.feature.minions.emptiedTimeDisplay) { + if (lastEmptied != 0L) { + val duration = System.currentTimeMillis() - lastEmptied + val format = StringUtils.formatDuration(duration / 1000) + " ago" + val text = "§eHopper Emptied: $format" + event.drawString(location.add(0.0, 1.15, 0.0), text, true) + } + } } } } |