From fbc91848570fe86931794bcb755aa3ba257ed574 Mon Sep 17 00:00:00 2001 From: alexia Date: Sat, 2 Dec 2023 09:37:56 +0100 Subject: [PATCH] Highlight boosted crop in Jacob's Contests --- .../skyhanni/features/garden/GardenAPI.kt | 10 +++++-- .../features/garden/GardenNextJacobContest.kt | 28 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index aafd3fd7c2cb..6ef4800dc255 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -34,6 +34,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCultivatingCounter import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter import net.minecraft.client.Minecraft +import net.minecraft.enchantment.Enchantment import net.minecraft.item.ItemStack import net.minecraft.network.play.client.C09PacketHeldItemChange import net.minecraft.util.AxisAlignedBB @@ -142,9 +143,14 @@ object GardenAPI { fun readCounter(itemStack: ItemStack): Long = itemStack.getHoeCounter() ?: itemStack.getCultivatingCounter() ?: -1L - fun MutableList.addCropIcon(crop: CropType) { + fun MutableList.addCropIcon(crop: CropType, highlight: Boolean = false) { try { - add(crop.icon) + var icon = crop.icon.copy() + if (highlight) { + // Hack to add enchant glint, like Hypixel does it + icon.addEnchantment(Enchantment.protection, 0) + } + add(icon) } catch (e: NullPointerException) { e.printStackTrace() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index 6291b253edff..937299d22e51 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -19,6 +19,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.TimeUtils import com.google.gson.Gson import io.github.moulberry.notenoughupdates.util.SkyBlockTime @@ -291,17 +292,31 @@ object GardenNextJacobContest { nextContest: FarmingContest, list: MutableList, ): MutableList { + var boostedCrop: CropType? = null + outer@ for (line in TabListData.getTabList()) { + val lineStripped = line.removeColor().trim() + if (lineStripped.startsWith("☘ ")) { + for (crop in nextContest.crops) { + if (line.removeColor().trim() == "☘ ${crop.cropName}") { + boostedCrop = crop + break@outer + } + } + break + } + } + var duration = nextContest.endTime - System.currentTimeMillis() if (duration < contestDuration) { list.add("§aActive: ") } else { list.add("§eNext: ") duration -= contestDuration - warn(duration, nextContest.crops) + warn(duration, nextContest.crops, boostedCrop) } for (crop in nextContest.crops) { list.add(" ") - list.addCropIcon(crop) + list.addCropIcon(crop, highlight = (crop == boostedCrop)) nextContestCrops.add(crop) } val format = TimeUtils.formatDuration(duration) @@ -310,23 +325,24 @@ object GardenNextJacobContest { return list } - private fun warn(timeInMillis: Long, crops: List) { + private fun warn(timeInMillis: Long, crops: List, boostedCrop: CropType?) { if (!config.warn) return if (config.warnTime <= timeInMillis / 1000) return if (System.currentTimeMillis() < lastWarningTime) return lastWarningTime = System.currentTimeMillis() + 60_000 * 40 - val cropText = crops.joinToString("§7, ") { "§a${it.cropName}" } + val cropText = crops.joinToString("§7, ") { (if (it == boostedCrop) "§6" else "§a") + it.cropName } LorenzUtils.chat("Next farming contest: $cropText") LorenzUtils.sendTitle("§eFarming Contest!", 5.seconds) SoundUtils.playBeepSound() + val cropTextNoColor = crops.joinToString(", ") { if (it == boostedCrop) "${it.cropName}" else it.cropName } if (config.warnPopup && !Display.isActive()) { SkyHanniMod.coroutineScope.launch { openPopupWindow( - "Farming Contest soon!\n" + - "Crops: ${cropText.removeColor()}" + "Farming Contest soon!
" + + "Crops: ${cropTextNoColor}" ) } }