diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2023-02-22 18:33:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 18:33:20 +0100 |
commit | cf3f08e4fd340ab331a4b61c1159fb527027ade7 (patch) | |
tree | f0fa524ef72817eeab73bdacc6df0f360b646060 /src/main/kotlin/io | |
parent | 30bd46e46aab73e2927fa5631c49ace84708e590 (diff) | |
download | NotEnoughUpdates-cf3f08e4fd340ab331a4b61c1159fb527027ade7.tar.gz NotEnoughUpdates-cf3f08e4fd340ab331a4b61c1159fb527027ade7.tar.bz2 NotEnoughUpdates-cf3f08e4fd340ab331a4b61c1159fb527027ade7.zip |
Added Sky Mall to Dwarven Overlay (#604)
* Added Sky Mall to Dwarven Overlay.
* Made SkyBlockTime a data object.
* Added color to names and display item per different perk variant.
* Added daySuffix support for days greater 10.
* Data classes have a copy method already.
* Green color does not work.
* Fixed a bug in monthName.
* Add Unit Tests and make use of Instant
* Fixed Sky Mall overlay showing in crystal hollows.
* 11st
12nd
13rd
---------
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: nea <nea@nea.moe>
Co-authored-by: nopo <nopotheemail@gmail.com>
Diffstat (limited to 'src/main/kotlin/io')
-rw-r--r-- | src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt | 103 | ||||
-rw-r--r-- | src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt | 122 |
2 files changed, 225 insertions, 0 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt new file mode 100644 index 00000000..2821473b --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/guifeatures/SkyMallDisplay.kt @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.guifeatures + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.util.SBInfo +import io.github.moulberry.notenoughupdates.util.SkyBlockTime +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.init.Items +import net.minecraft.item.ItemStack +import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.time.Duration +import java.time.Instant +import java.util.regex.Pattern + +@NEUAutoSubscribe +class SkyMallDisplay { + + private val pattern = Pattern.compile("§r§eNew buff§r§r§r: (.*)§r") + + @SubscribeEvent(receiveCanceled = true) + fun onChatReceive(event: ClientChatReceivedEvent) { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return + if (SBInfo.getInstance().getLocation() != "mining_3") return + + val matcher = pattern.matcher(event.message.formattedText) + if (!matcher.matches()) return + + val message = matcher.group(1) ?: return + currentPerk = SkyMallPerk.values().find { it.chatMessage == message } + + currentPerk?.let { + val manager = NotEnoughUpdates.INSTANCE.manager + displayItem = manager.jsonToStack(manager.itemInformation[it.displayItemId]) + } + } + + companion object { + private var displayText = "" + private var displayItem: ItemStack? = null + private var lastUpdated = 0L + private var currentPerk: SkyMallPerk? = null + + fun getDisplayText(): String { + return if (lastUpdated + 1_000 > System.currentTimeMillis()) { + displayText + } else { + update() + displayText + } + } + + fun getDisplayItem(): ItemStack { + return displayItem ?: ItemStack(Items.apple) + } + + private fun update() { + val nextDayBeginning = SkyBlockTime.now() + .let { it.copy(day = it.day + 1, hour = 0, minute = 0, second = 0) } + .toInstant() + val untilNextDay = Duration.between(Instant.now(), nextDayBeginning) + displayText = (currentPerk?.displayName ?: "?") + " §a(${ + Utils.prettyTime(untilNextDay.toMillis()) + })" + lastUpdated = System.currentTimeMillis() + } + } + + enum class SkyMallPerk(val displayName: String, val displayItemId: String, val chatMessage: String) { + PICKAXE_COOLDOWN( + "20% §6Pickaxe Ability cooldown", "DIAMOND_PICKAXE", + "§r§fReduce Pickaxe Ability cooldown by §r§a20%§r§f." + ), + MORE_POWDER("+15% more §6Powder", "MITHRIL_ORE", "§r§fGain §r§a+15% §r§fmore Powder while mining."), + MINING_FORTUNE("+50 §6☘ Mining Fortune", "ENCHANTED_RABBIT_FOOT", "§r§fGain §r§a+50 §r§6☘ Mining Fortune§r§f."), + MINING_SPEED("+100 §6⸕ Mining Speed", "ENCHANTED_FEATHER", "§r§fGain §r§a+100 §r§6⸕ Mining Speed§r§f."), + MORE_GOBLINS("10x §6Goblin chance", "GOBLIN_HELMET", "§r§f§r§a10x §r§fchance to find Goblins while mining."), + TITANIUM_DROPS("5x §9Titanium drops", "TITANIUM_ORE", "§r§fGain §r§a5x §r§9Titanium §r§fdrops"), + + // In case hypixel finds some day the missing dot at the end. + TITANIUM_DROPS_WITH_DOT("5x §9Titanium drops", "TITANIUM_ORE", "§r§fGain §r§a5x §r§9Titanium §r§fdrops."), + ; + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt new file mode 100644 index 00000000..8ceb1c51 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/SkyBlockTime.kt @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.util + +import java.time.Instant + +data class SkyBlockTime( + val year: Int = 1, + val month: Int = 1, + val day: Int = 1, + val hour: Int = 0, + val minute: Int = 0, + val second: Int = 0, +) { + + val monthName get() = monthName(month) + val dayName get() = "$day${daySuffix(day)}" + + + fun toInstant(): Instant? { + return Instant.ofEpochMilli(toMillis()) + } + + fun toMillis(): Long { + val skyBlockYear = 124 * 60 * 60.0 + val skyBlockMonth = skyBlockYear / 12 + val skyBlockDay = skyBlockMonth / 31 + val skyBlockHour = skyBlockDay / 24 + val skyBlockMinute = skyBlockHour / 60 + val skyBlockSecond = skyBlockMinute / 60 + + var time = 0.0 + time += year * skyBlockYear + time += (month - 1) * skyBlockMonth + time += (day - 1) * skyBlockDay + time += hour * skyBlockHour + time += minute * skyBlockMinute + time += second * skyBlockSecond + time += 1559829300 + return time.toLong() * 1000 + } + + companion object { + fun fromInstant(instant: Instant): SkyBlockTime { + val skyBlockTimeZero = 1559829300000 // Day 1, Year 1 + var realMillis = (instant.toEpochMilli() - skyBlockTimeZero) + + val skyBlockYear = 124 * 60 * 60 * 1000 + val skyBlockMonth = skyBlockYear / 12 + val skyBlockDay = skyBlockMonth / 31 + val skyBlockHour = skyBlockDay / 24 + val skyBlockMinute = skyBlockHour / 60 + val skyBlockSecond = skyBlockMinute / 60 + + fun getUnit(factor: Int): Int { + val result = realMillis / factor + realMillis %= factor + return result.toInt() + } + + val year = getUnit(skyBlockYear) + val month = getUnit(skyBlockMonth) + 1 + val day = getUnit(skyBlockDay) + 1 + val hour = getUnit(skyBlockHour) + val minute = getUnit(skyBlockMinute) + val second = getUnit(skyBlockSecond) + return SkyBlockTime(year, month, day, hour, minute, second) + + } + + fun now(): SkyBlockTime { + return fromInstant(Instant.now()) + } + + fun monthName(month: Int): String { + val prefix = when ((month - 1) % 3) { + 0 -> "Early " + 1 -> "" + 2 -> "Late " + else -> "Undefined!" + } + + val name = when ((month - 1) / 3) { + 0 -> "Spring" + 1 -> "Summer" + 2 -> "Autumn" + 3 -> "Winter" + else -> "lol" + } + + return prefix + name + } + + fun daySuffix(n: Int): String { + return if (n in 11..13) { + "th" + } else when (n % 10) { + 1 -> "st" + 2 -> "nd" + 3 -> "rd" + else -> "th" + } + } + } +} |