aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-16 19:13:08 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-16 19:13:08 +0100
commit5ffe5dab3973b540a4e0cd1b57f13d0be77e3f84 (patch)
treedbfdcb73736f5141a0b3843636454968ce3f0a50 /src/main/java/at/hannibal2/skyhanni/features
parentef9313817a53f8b67db959128cc1b73dfacf6d1a (diff)
downloadSkyHanni-5ffe5dab3973b540a4e0cd1b57f13d0be77e3f84.tar.gz
SkyHanni-5ffe5dab3973b540a4e0cd1b57f13d0be77e3f84.tar.bz2
SkyHanni-5ffe5dab3973b540a4e0cd1b57f13d0be77e3f84.zip
Added jacob farming contest features
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt
new file mode 100644
index 000000000..c4da66bcc
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/JacobFarmingContestsInventory.kt
@@ -0,0 +1,162 @@
+package at.hannibal2.skyhanni.features.inventory
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.LateInventoryOpenEvent
+import at.hannibal2.skyhanni.events.LorenzToolTipEvent
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzColor
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import io.github.moulberry.notenoughupdates.util.SkyBlockTime
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraft.inventory.ContainerChest
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.text.SimpleDateFormat
+import java.util.*
+import java.util.regex.Pattern
+
+class JacobFarmingContestsInventory {
+
+ private val duplicateSlots = mutableListOf<Int>()
+ private val realTime = mutableMapOf<Int, String>()
+
+ private val formatDay = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault())
+ private val formatTime = SimpleDateFormat("HH:mm", Locale.getDefault())
+ private val pattern = Pattern.compile("§a(.*) (.*)(?:rd|st|nd|th), Year (.*)")
+ private val config get() = SkyHanniMod.feature.inventory
+
+ // Render the contests a tick delayed to feel smoother
+ private var hideEverything = true
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ duplicateSlots.clear()
+ realTime.clear()
+ hideEverything = true
+ }
+
+ @SubscribeEvent
+ fun onLateInventoryOpen(event: LateInventoryOpenEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (event.inventoryName != "Your Contests") return
+
+ duplicateSlots.clear()
+ realTime.clear()
+
+ val foundEvents = mutableListOf<String>()
+ for ((slot, item) in event.inventoryItems) {
+ if (!item.getLore().any { it.startsWith("§7Your score: §e") }) continue
+
+ val name = item.name!!
+
+ if (foundEvents.contains(name)) {
+ if (config.jacobFarmingContestHideDuplicates) {
+ duplicateSlots.add(slot)
+ }
+ } else {
+ foundEvents.add(name)
+ }
+ if (config.jacobFarmingContestRealTime) {
+ readRealTime(name, slot)
+ }
+ }
+ hideEverything = false
+ }
+
+ private fun readRealTime(name: String, slot: Int) {
+ val matcher = pattern.matcher(name)
+ if (!matcher.matches()) return
+
+ val month = matcher.group(1)
+ val day = matcher.group(2).toInt()
+ val year = matcher.group(3).toInt()
+
+ var monthNr = 0
+ for (i in 1..12) {
+ val monthName = SkyBlockTime.monthName(i)
+ if (month == monthName) {
+ monthNr = i
+ }
+ }
+ val time = SkyBlockTime(year, monthNr, day, 0, 0, 0)
+ val toMillis = time.toMillis()
+ val dayFormat = formatDay.format(toMillis)
+ val startTimeFormat = formatTime.format(toMillis)
+ val endTimeFormat = formatTime.format(toMillis + 1000 * 60 * 20)
+ realTime[slot] = "$dayFormat $startTimeFormat-$endTimeFormat"
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!InventoryUtils.openInventoryName().contains("Your Contests")) return
+ if (!config.jacobFarmingContestHighlightRewards) return
+
+ // hide green border for a tick
+ if (config.jacobFarmingContestHideDuplicates && hideEverything) return
+
+ if (event.gui !is GuiChest) return
+ val guiChest = event.gui
+ val chest = guiChest.inventorySlots as ContainerChest
+
+ for (slot in chest.inventorySlots) {
+ if (slot == null) continue
+ if (slot.slotNumber != slot.slotIndex) continue
+ if (duplicateSlots.contains(slot.slotNumber)) continue
+ val stack = slot.stack ?: continue
+ if (stack.getLore().any { it == "§eClick to claim reward!" }) {
+ slot highlight LorenzColor.GREEN
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onDrawSlot(event: GuiContainerEvent.DrawSlotEvent.GuiContainerDrawSlotPre) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.jacobFarmingContestHideDuplicates) return
+ if (!InventoryUtils.openInventoryName().contains("Your Contests")) return
+
+ if (hideEverything) {
+ val slot = event.slot
+ val number = slot.slotNumber
+ if (number in 10..43) {
+ event.isCanceled = true
+ return
+ }
+
+ }
+
+ val slot = event.slot.slotNumber
+ if (!duplicateSlots.contains(slot)) return
+ event.isCanceled = true
+ }
+
+ @SubscribeEvent
+ fun onTooltip(event: LorenzToolTipEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!InventoryUtils.openInventoryName().contains("Your Contests")) return
+
+ val slot = event.slot.slotNumber
+
+ if (config.jacobFarmingContestHideDuplicates) {
+ if (duplicateSlots.contains(slot)) {
+ event.toolTip.clear()
+ event.toolTip.add("§7Duplicate contest!")
+ return
+ }
+ }
+
+ if (config.jacobFarmingContestRealTime) {
+ realTime[slot]?.let {
+ val toolTip = event.toolTip
+ if (toolTip.size > 1) {
+ toolTip.add(1, it)
+ }
+ }
+ }
+ }
+} \ No newline at end of file