diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden/farming')
7 files changed, 61 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index c00e2c6e0..31eea71e2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -329,7 +329,8 @@ object CropMoneyDisplay { if (debug) { debugList.addAsSingletonList(" added seedsPerHour: $seedsPerHour") } - npcPrice += internalName.getNpcPrice() * seedsPerHour + val factor = NEUItems.getMultiplier(internalName).second + npcPrice += internalName.getNpcPrice() * seedsPerHour / factor sellOffer += it.buyPrice * seedsPerHour instantSell += it.sellPrice * seedsPerHour } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt index 053fae0ca..7a993f0de 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt @@ -66,6 +66,11 @@ class FarmingWeightDisplay { if (!isEnabled()) return if (!event.isMod(5)) return update() + + SkyHanniMod.coroutineScope.launch { + getCropWeights() + hasFetchedCropWeights = true + } } companion object { @@ -209,7 +214,7 @@ class FarmingWeightDisplay { } else { leaderboardPosition-- } - ProfileStorageData.profileSpecific?.garden?.faramingWeight?.lastFarmingWeightLeaderboard = + ProfileStorageData.profileSpecific?.garden?.farmingWeight?.lastFarmingWeightLeaderboard = leaderboardPosition // Remove passed player to present the next one @@ -283,7 +288,7 @@ class FarmingWeightDisplay { if (wasNotLoaded && config.eliteFarmingWeightoffScreenDropMessage) { checkOffScreenLeaderboardChanges() } - ProfileStorageData.profileSpecific?.garden?.faramingWeight?.lastFarmingWeightLeaderboard = + ProfileStorageData.profileSpecific?.garden?.farmingWeight?.lastFarmingWeightLeaderboard = leaderboardPosition lastLeaderboardUpdate = System.currentTimeMillis() isLoadingLeaderboard = false @@ -292,7 +297,7 @@ class FarmingWeightDisplay { private fun checkOffScreenLeaderboardChanges() { val profileSpecific = ProfileStorageData.profileSpecific ?: return - val oldPosition = profileSpecific.garden.faramingWeight.lastFarmingWeightLeaderboard + val oldPosition = profileSpecific.garden.farmingWeight.lastFarmingWeightLeaderboard if (oldPosition == -1) return val diff = leaderboardPosition - oldPosition @@ -403,15 +408,35 @@ class FarmingWeightDisplay { private fun CropType.getLocalCounter() = localCounter[this] ?: 0L - private fun CropType.getFactor() = factorPerCrop[this]!! + private fun CropType.getFactor(): Double { + return factorPerCrop[this] ?: backupFactors[this] ?: error("Crop $this not in backupFactors!") + } fun lookUpCommand(it: Array<String>) { val name = if (it.size == 1) it[0] else LorenzUtils.getPlayerName() OSUtils.openBrowser("https://elitebot.dev/@$name/") - LorenzUtils.chat("§e[SkyHanni] Opening Farming Profile from §b$name") + LorenzUtils.chat("§e[SkyHanni] Opening Farming Profile of player §b$name") + } + + private val factorPerCrop = mutableMapOf<CropType, Double>() + private var attemptingCropWeightFetch = false + private var hasFetchedCropWeights = false + + private suspend fun getCropWeights() { + if (attemptingCropWeightFetch || hasFetchedCropWeights) return + attemptingCropWeightFetch = true + + val url = "https://api.elitebot.dev/weights" + val result = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }.asJsonObject + + for (crop in result.entrySet()) { + val cropType = CropType.getByName(crop.key) + factorPerCrop[cropType] = crop.value.asDouble + } } - private val factorPerCrop by lazy { + // still needed when first joining garden and if they cant make https requests + private val backupFactors by lazy { mapOf( CropType.WHEAT to 100_000.0, CropType.CARROT to 302_061.86, @@ -425,7 +450,7 @@ class FarmingWeightDisplay { CropType.CACTUS to 177_254.45, ) } - } - class UpcomingPlayer(val name: String, val weight: Double) + class UpcomingPlayer(val name: String, val weight: Double) + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBurrowingSporesNotifier.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBurrowingSporesNotifier.kt index 73d5bcaea..8d67434de 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBurrowingSporesNotifier.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBurrowingSporesNotifier.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.TitleUtils import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds class GardenBurrowingSporesNotifier { @@ -14,7 +15,7 @@ class GardenBurrowingSporesNotifier { if (!SkyHanniMod.feature.garden.burrowingSporesNotification) return if (event.message.endsWith("§6§lVERY RARE CROP! §r§f§r§9Burrowing Spores")) { - TitleUtils.sendTitle("§9Burrowing Spores!", 5_000) + TitleUtils.sendTitle("§9Burrowing Spores!", 5.seconds) // would be sent too often, nothing special then // ItemBlink.setBlink(NEUItems.getItemStackOrNull("BURROWING_SPORES"), 5_000) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt index dad33a902..3975e2471 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt @@ -23,6 +23,7 @@ import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.* +import kotlin.time.Duration.Companion.seconds object GardenCropMilestoneDisplay { private var progressDisplay = emptyList<List<Any>>() @@ -82,7 +83,7 @@ object GardenCropMilestoneDisplay { } @SubscribeEvent - fun onOwnInventoryItemUpdate(event: OwnInventorItemUpdateEvent) { + fun onOwnInventoryItemUpdate(event: OwnInventoryItemUpdateEvent) { if (!GardenAPI.inGarden()) return try { @@ -103,7 +104,7 @@ object GardenCropMilestoneDisplay { } cultivatingData[crop] = counter } catch (e: Throwable) { - LorenzUtils.error("[SkyHanni] Error in OwnInventorItemUpdateEvent") + LorenzUtils.error("[SkyHanni] Error in OwnInventoryItemUpdateEvent") e.printStackTrace() } } @@ -215,7 +216,7 @@ object GardenCropMilestoneDisplay { SoundUtils.playBeepSound() } if (!needsInventory) { - TitleUtils.sendTitle(title, 1_500) + TitleUtils.sendTitle(title, 1.5.seconds) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt index c9868d4e3..c7817066e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy import com.google.gson.JsonObject import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer @@ -28,7 +29,7 @@ object GardenCropSpeed { var averageBlocksPerSecond = 0.0 - private val blocksSpeedList = mutableListOf<Int>() + private var blocksSpeedList = listOf<Int>() private var blocksBroken = 0 private var secondsStopped = 0 @@ -81,20 +82,22 @@ object GardenCropSpeed { this.blocksBroken = 0 if (blocksBroken == 0) { - if (blocksSpeedList.size == 0) return + if (blocksSpeedList.isEmpty()) return secondsStopped++ } else { if (secondsStopped >= config.blocksBrokenResetTime) { resetSpeed() } - while (secondsStopped > 0) { - blocksSpeedList.add(0) - secondsStopped -= 1 - } - blocksSpeedList.add(blocksBroken) - if (blocksSpeedList.size == 2) { - blocksSpeedList.removeFirst() - blocksSpeedList.add(blocksBroken) + blocksSpeedList = blocksSpeedList.editCopy { + while (secondsStopped > 0) { + this.add(0) + secondsStopped -= 1 + } + this.add(blocksBroken) + if (this.size == 2) { + this.removeFirst() + this.add(blocksBroken) + } } averageBlocksPerSecond = if (blocksSpeedList.size > 1) { blocksSpeedList.dropLast(1).average() @@ -170,7 +173,7 @@ object GardenCropSpeed { private fun resetSpeed() { averageBlocksPerSecond = 0.0 - blocksSpeedList.clear() + blocksSpeedList = emptyList() secondsStopped = 0 } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt index 9c2d38e4b..1e5736f91 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.garden.farming import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.TitleUtils import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.OwnInventorItemUpdateEvent +import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemBlink import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.SoundUtils import io.github.moulberry.notenoughupdates.util.MinecraftExecutor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds class WildStrawberryDyeNotification { var lastCloseTime = 0L @@ -23,7 +24,7 @@ class WildStrawberryDyeNotification { } @SubscribeEvent - fun onOwnInventoryItemUpdate(event: OwnInventorItemUpdateEvent) { + fun onOwnInventoryItemUpdate(event: OwnInventoryItemUpdateEvent) { if (!GardenAPI.inGarden()) return if (!SkyHanniMod.feature.garden.wildStrawberryDyeNotification) return @@ -36,7 +37,7 @@ class WildStrawberryDyeNotification { val internalName = event.itemStack.getInternalName_old() if (internalName == "DYE_WILD_STRAWBERRY") { val name = event.itemStack.name!! - TitleUtils.sendTitle(name, 5_000) + TitleUtils.sendTitle(name, 5.seconds) LorenzUtils.chat("§e[SkyHanni] You found a $name§e!") SoundUtils.playBeepSound() ItemBlink.setBlink(NEUItems.getItemStackOrNull("DYE_WILD_STRAWBERRY"), 5_000) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt index 76a5b50ad..916c31524 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.SoundUtils import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds class WrongFungiCutterWarning { private var mode = FungiMode.UNKNOWN @@ -48,7 +49,7 @@ class WrongFungiCutterWarning { private fun notifyWrong() { if (!SkyHanniMod.feature.garden.fungiCutterWarn) return - TitleUtils.sendTitle("§cWrong Fungi Cutter Mode!", 2_000) + TitleUtils.sendTitle("§cWrong Fungi Cutter Mode!", 2.seconds) if (System.currentTimeMillis() > lastPlaySoundTime + 3_00) { lastPlaySoundTime = System.currentTimeMillis() SoundUtils.playBeepSound() |
