Skip to content

Commit

Permalink
Highlight boosted crop in Jacob's Contests
Browse files Browse the repository at this point in the history
  • Loading branch information
qtlunya committed Dec 2, 2023
1 parent a11d12c commit fbc9184
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,9 +143,14 @@ object GardenAPI {

fun readCounter(itemStack: ItemStack): Long = itemStack.getHoeCounter() ?: itemStack.getCultivatingCounter() ?: -1L

fun MutableList<Any>.addCropIcon(crop: CropType) {
fun MutableList<Any>.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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -291,17 +292,31 @@ object GardenNextJacobContest {
nextContest: FarmingContest,
list: MutableList<Any>,
): MutableList<Any> {
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)
Expand All @@ -310,23 +325,24 @@ object GardenNextJacobContest {
return list
}

private fun warn(timeInMillis: Long, crops: List<CropType>) {
private fun warn(timeInMillis: Long, crops: List<CropType>, 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) "<b>${it.cropName}</b>" else it.cropName }
if (config.warnPopup && !Display.isActive()) {
SkyHanniMod.coroutineScope.launch {
openPopupWindow(
"Farming Contest soon!\n" +
"Crops: ${cropText.removeColor()}"
"<html>Farming Contest soon!<br />" +
"Crops: ${cropTextNoColor}</html>"
)
}
}
Expand Down

0 comments on commit fbc9184

Please sign in to comment.