From 68d821450171db5bb9adbceee289aee793809d56 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:07:59 +0200 Subject: Moved garden features into different packages --- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 8 + .../hannibal2/skyhanni/config/commands/Commands.kt | 2 +- .../skyhanni/features/garden/AnitaMedalProfit.kt | 1 + .../skyhanni/features/garden/CropMoneyDisplay.kt | 251 ---------- .../skyhanni/features/garden/CropSpeedMeter.kt | 141 ------ .../features/garden/DicerRngDropCounter.kt | 127 ----- .../skyhanni/features/garden/EliteFarmingWeight.kt | 323 ------------ .../skyhanni/features/garden/FarmingArmorDrops.kt | 107 ---- .../skyhanni/features/garden/GardenBestCropTime.kt | 106 ---- .../features/garden/GardenCropMilestoneDisplay.kt | 385 -------------- .../features/garden/GardenCustomKeybinds.kt | 107 ---- .../skyhanni/features/garden/GardenDeskInSBMenu.kt | 51 -- .../features/garden/GardenInventoryNumbers.kt | 53 -- .../features/garden/GardenNextPlotPrice.kt | 46 -- .../features/garden/GardenVisitorColorNames.kt | 55 -- .../features/garden/GardenVisitorFeatures.kt | 549 -------------------- .../skyhanni/features/garden/GardenVisitorTimer.kt | 69 --- .../skyhanni/features/garden/SkyMartCopperPrice.kt | 86 ---- .../features/garden/WrongFungiCutterWarning.kt | 82 --- .../features/garden/farming/CropMoneyDisplay.kt | 254 ++++++++++ .../features/garden/farming/CropSpeedMeter.kt | 143 ++++++ .../features/garden/farming/DicerRngDropCounter.kt | 129 +++++ .../features/garden/farming/EliteFarmingWeight.kt | 325 ++++++++++++ .../features/garden/farming/FarmingArmorDrops.kt | 108 ++++ .../features/garden/farming/GardenBestCropTime.kt | 108 ++++ .../garden/farming/GardenCropMilestoneDisplay.kt | 387 +++++++++++++++ .../garden/farming/GardenCustomKeybinds.kt | 108 ++++ .../garden/farming/WrongFungiCutterWarning.kt | 83 ++++ .../garden/inventory/GardenDeskInSBMenu.kt | 52 ++ .../garden/inventory/GardenInventoryNumbers.kt | 54 ++ .../garden/inventory/GardenNextPlotPrice.kt | 47 ++ .../garden/inventory/SkyMartCopperPrice.kt | 87 ++++ .../garden/visitor/GardenVisitorColorNames.kt | 55 ++ .../garden/visitor/GardenVisitorFeatures.kt | 551 +++++++++++++++++++++ .../features/garden/visitor/GardenVisitorTimer.kt | 70 +++ .../features/inventory/HideNotClickableItems.kt | 2 +- .../java/at/hannibal2/skyhanni/test/LorenzTest.kt | 2 +- 37 files changed, 2573 insertions(+), 2541 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/FarmingArmorDrops.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenCustomKeybinds.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenDeskInSBMenu.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenInventoryNumbers.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextPlotPrice.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorColorNames.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorTimer.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartCopperPrice.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/WrongFungiCutterWarning.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropSpeedMeter.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/EliteFarmingWeight.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenBestCropTime.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenDeskInSBMenu.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenNextPlotPrice.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorColorNames.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 4b24f51fd..06c19a8a8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -28,6 +28,14 @@ import at.hannibal2.skyhanni.features.garden.*; import at.hannibal2.skyhanni.features.garden.composter.ComposterDisplay; import at.hannibal2.skyhanni.features.garden.composter.ComposterInventoryNumbers; import at.hannibal2.skyhanni.features.garden.composter.GardenComposterInventoryFeatures; +import at.hannibal2.skyhanni.features.garden.farming.*; +import at.hannibal2.skyhanni.features.garden.inventory.GardenDeskInSBMenu; +import at.hannibal2.skyhanni.features.garden.inventory.GardenInventoryNumbers; +import at.hannibal2.skyhanni.features.garden.inventory.GardenNextPlotPrice; +import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice; +import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames; +import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures; +import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorTimer; import at.hannibal2.skyhanni.features.inventory.*; import at.hannibal2.skyhanni.features.itemabilities.FireVeilWandParticles; import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbilityCooldown; diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index f45c8a035..f09836a5b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.features.bazaar.BazaarDataGrabber import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper -import at.hannibal2.skyhanni.features.garden.CropSpeedMeter +import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter import at.hannibal2.skyhanni.features.misc.CollectionCounter import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.test.LorenzTest diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt index 0f51e65aa..ed95ee8b4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt deleted file mode 100644 index 2bb43af93..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt +++ /dev/null @@ -1,251 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GardenToolChangeEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.features.bazaar.BazaarData -import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList -import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc -import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.NumberUtil -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import io.github.moulberry.notenoughupdates.NotEnoughUpdates -import kotlinx.coroutines.launch -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -class CropMoneyDisplay { - private var display = mutableListOf>() - private val config get() = SkyHanniMod.feature.garden - private var tick = 0 - private var loaded = false - private var ready = false - private val multipliers = mutableMapOf() - private val cropNames = mutableMapOf() // internalName -> cropName - private var hasCropInHand = false - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (!isEnabled()) return - - config.moneyPerHourPos.renderStringsAndItems(display, posLabel = "Garden Crop Money Per Hour") - } - - @SubscribeEvent - fun onGardenToolChange(event: GardenToolChangeEvent) { - hasCropInHand = event.crop != null - update() - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!isEnabled()) return - if (tick++ % (20 * 5) != 0) return - if (!hasCropInHand && !config.moneyPerHourAlwaysOn) return - - update() - } - - private fun update() { - init() - - display = drawDisplay() - } - - private fun drawDisplay(): MutableList> { - val newDisplay = mutableListOf>() - - val title = if (config.moneyPerHourCompact) { - "§7Money/Hour:" - } else { - "§7Money per Hour when selling:" - } - - if (!ready) { - newDisplay.addAsSingletonList(title) - newDisplay.addAsSingletonList("§eLoading...") - return newDisplay - } - - if (!hasCropInHand && !config.moneyPerHourAlwaysOn) return newDisplay - - newDisplay.addAsSingletonList(fullTitle(title)) - - if (!config.cropMilestoneProgress) { - newDisplay.addAsSingletonList("§cCrop Milestone Progress Display is disabled!") - return newDisplay - } - - val moneyPerHourData = calculateMoneyPerHour() - if (moneyPerHourData.isEmpty()) { - if (!GardenAPI.isSpeedDataEmpty()) { - val message = "money/hr empty but speed data not empty, retry" - LorenzUtils.debug(message) - println(message) - newDisplay.addAsSingletonList("§eStill Loading...") - ready = false - loaded = false - return newDisplay - } - newDisplay.addAsSingletonList("§cFarm crops to add them to this list!") - return newDisplay - } - - var number = 0 - val help = moneyPerHourData.mapValues { (_, value) -> value.max() } - for (internalName in help.sortedDesc().keys) { - number++ - val cropName = cropNames[internalName]!! - val isCurrent = cropName == GardenAPI.cropInHand - if (number > config.moneyPerHourShowOnlyBest && !isCurrent) continue - - val list = mutableListOf() - if (!config.moneyPerHourCompact) { - list.add("§7$number# ") - } - - try { - list.add(NEUItems.getItemStack(internalName)) - } catch (e: NullPointerException) { - e.printStackTrace() - } - - if (!config.moneyPerHourCompact) { - val itemName = NEUItems.getItemStack(internalName).name?.removeColor() ?: continue - val currentColor = if (isCurrent) "§e" else "§7" - val contestFormat = if (GardenNextJacobContest.isNextCrop(cropName)) "§n" else "" - list.add("$currentColor$contestFormat$itemName§7: ") - } - - val coinsColor = if (isCurrent && config.moneyPerHourCompact) "§e" else "§6" - val moneyArray = moneyPerHourData[internalName]!! - - for (price in moneyArray) { - val format = format(price) - list.add("$coinsColor$format") - list.add("§7/") - } - list.removeLast() - - newDisplay.add(list) - } - - return newDisplay - } - - private fun fullTitle(title: String): String { - val titleText: String - val nameList = mutableListOf() - if (config.moneyPerHourUseCustomFormat) { - val map = mapOf( - 0 to "Sell Offer", - 1 to "Instant Sell", - 2 to "NPC Price", - ) - val list = mutableListOf() - for (index in config.moneyPerHourCustomFormat) { - map[index]?.let { - list.add(it) - } - } - for (line in list) { - nameList.add("§e$line") - nameList.add("§7/") - } - nameList.removeLast() - titleText = nameList.joinToString("") - } else { - titleText = if (LorenzUtils.noTradeMode) "§eNPC Price" else "§eSell Offer" - } - return "$title §7($titleText§7)" - } - - private fun format(moneyPerHour: Double) = if (config.moneyPerHourCompactPrice) { - NumberUtil.format(moneyPerHour) - } else { - LorenzUtils.formatInteger(moneyPerHour.toLong()) - } - - private fun calculateMoneyPerHour(): Map> { - val moneyPerHours = mutableMapOf>() - for ((internalName, amount) in multipliers) { - val crop = cropNames[internalName]!! - val speed = crop.getSpeed() - // No speed data for item in hand - if (speed == -1) continue - - val speedPerHr = speed.toDouble() * 60 * 60 - val blocksPerHour = speedPerHr / amount.toDouble() - - val bazaarData = BazaarApi.getBazaarDataForInternalName(internalName) ?: continue - moneyPerHours[internalName] = formatNumbers(bazaarData, blocksPerHour) - } - return moneyPerHours - } - - private fun formatNumbers(bazaarData: BazaarData, blocksPerHour: Double): Array { - val npcPrice = bazaarData.npcPrice * blocksPerHour - val sellOffer = bazaarData.buyPrice * blocksPerHour - val instantSell = bazaarData.sellPrice * blocksPerHour - - return if (config.moneyPerHourUseCustomFormat) { - val map = mapOf( - 0 to sellOffer, - 1 to instantSell, - 2 to npcPrice, - ) - val newList = mutableListOf() - for (index in config.moneyPerHourCustomFormat) { - map[index]?.let { - newList.add(it) - } - } - newList.toTypedArray() - } else { - if (LorenzUtils.noTradeMode) { - arrayOf(npcPrice) - } else { - arrayOf(sellOffer) - } - } - } - - private fun init() { - if (loaded) return - - if (BazaarApi.bazaarMap.isEmpty()) { - LorenzUtils.debug("bz not ready for money/time!") - return - } - - loaded = true - - SkyHanniMod.coroutineScope.launch { - - for ((internalName, _) in NotEnoughUpdates.INSTANCE.manager.itemInformation) { - if (!BazaarApi.isBazaarItem(internalName)) continue - if (internalName == "ENCHANTED_PAPER") continue - - val (newId, amount) = NEUItems.getMultiplier(internalName) - if (amount < 10) continue - val itemName = NEUItems.getItemStack(newId).name?.removeColor() ?: continue - val crop = CropType.getByItemName(itemName) - crop?.let { - multipliers[internalName] = amount - cropNames[internalName] = it - } - } - - - ready = true - update() - } - } - - private fun isEnabled() = GardenAPI.inGarden() && config.moneyPerHourDisplay -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt deleted file mode 100644 index 9db52fe7c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt +++ /dev/null @@ -1,141 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter -import at.hannibal2.skyhanni.events.BlockClickEvent -import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType -import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.round -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -class CropSpeedMeter { - private var display = listOf() - private var currentCrop: CropType? = null - private var currentBlocks = 0 - private var tick = 0 - private var snapshot = listOf() - - @SubscribeEvent - fun onBlockBreak(event: BlockClickEvent) { - if (!isEnabled()) return - if (startCrops.isEmpty()) return - - val blockState = event.getBlockState - val cropBroken = blockState.getCropType() ?: return - if (cropBroken.multiplier == 1) { - if (blockState.isBabyCrop()) return - } - - if (currentCrop != cropBroken) { - currentCrop = cropBroken - currentBlocks = 0 - snapshot = emptyList() - } - breakBlock() - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!isEnabled()) return - if (tick++ % 30 != 0) return - - updateDisplay() - } - - private fun updateDisplay() { - display = renderDisplay() - } - - private fun renderDisplay(): MutableList { - val list = mutableListOf() - list.add("§7Crop Speed Meter") - if (startCrops.isEmpty()) { - list.add("§cOpen §e/cropmilestones §cto start!") - return list - } - - if (currentCrop == null) { - list.add("§cStart breaking blocks!") - return list - } - currentCrop?.let { - list.add(" §7Current ${it.cropName} counter: §e${currentBlocks.addSeparators()}") - } - - if (snapshot.isNotEmpty()) { - list += snapshot - } else { - list.add("§cOpen §e/cropmilestones §cagain to calculate!") - } - - return list - } - - @SubscribeEvent - fun onCropMilestoneUpdate(event: CropMilestoneUpdateEvent) { - if (!isEnabled()) return - val counters = mutableMapOf() - for (cropType in CropType.values()) { - counters[cropType] = cropType.getCounter() - } - if (startCrops.isEmpty()) { - startCrops = counters - currentCrop = null - snapshot = emptyList() - } else { - currentCrop?.let { - val crops = it.getCounter() - startCrops[it]!! - val blocks = currentBlocks - val cropsPerBlocks = (crops.toDouble() / blocks.toDouble()).round(3) - - val list = mutableListOf() - list.add("") - list.add("§6Calculation results") - list.add(" §7Crops collected: " + crops.addSeparators()) - list.add(" §7Blocks broken: " + blocks.addSeparators()) - list.add(" §7Crops per Block: " + cropsPerBlocks.addSeparators()) - - val baseDrops = it.baseDrops - val farmingFortune = (cropsPerBlocks * 100 / baseDrops).round(3) - - - list.add(" §7Calculated farming Fortune: §e" + farmingFortune.addSeparators()) - list.add("§cOpen /cropmilestones again to recalculate!") - - snapshot = list - updateDisplay() - } - } - } - - private fun breakBlock() { - currentBlocks++ - } - - companion object { - var enabled = false - private var startCrops = mapOf() - - fun toggle() { - enabled = !enabled - LorenzUtils.chat("§e[SkyHanni] Crop Speed Meter " + if (enabled) "§aEnabled" else "§cDisabled") - startCrops = emptyMap() - - } - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (!isEnabled()) return - - SkyHanniMod.feature.garden.cropSpeedMeterPos.renderStrings(display, posLabel = "Crop Speed Meter") - } - - fun isEnabled() = enabled && GardenAPI.inGarden() -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt deleted file mode 100644 index 7f2facf4f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt +++ /dev/null @@ -1,127 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.ConfigLoadEvent -import at.hannibal2.skyhanni.events.GardenToolChangeEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class DicerRngDropCounter { - private var display = listOf() - private val drops = mutableMapOf>() - private val itemDrops = mutableListOf() - private val config get() = SkyHanniMod.feature.garden - - init { - drops[CropType.MELON] = mutableMapOf() - drops[CropType.PUMPKIN] = mutableMapOf() - - itemDrops.add(ItemDrop(CropType.MELON, DropRarity.UNCOMMON, "§a§lUNCOMMON DROP! §r§eDicer dropped §r§a1x §r§aEnchanted Melon§r§e!")) - itemDrops.add(ItemDrop(CropType.MELON, DropRarity.RARE, "§9§lRARE DROP! §r§eDicer dropped §r§a5x §r§aEnchanted Melon§r§e!")) - itemDrops.add(ItemDrop(CropType.MELON, DropRarity.CRAZY_RARE, "§d§lCRAZY RARE DROP! §r§eDicer dropped §r§a50x §r§aEnchanted Melon§r§e!")) - itemDrops.add(ItemDrop(CropType.MELON, DropRarity.PRAY_TO_RNGESUS, "§5§lPRAY TO RNGESUS DROP! §r§eDicer dropped §r§92x §r§9Enchanted Melon Block§r§e!")) - - itemDrops.add(ItemDrop(CropType.PUMPKIN, DropRarity.UNCOMMON, "§a§lUNCOMMON DROP! §r§eDicer dropped §r§f64x §r§fPumpkin§r§e!")) - itemDrops.add(ItemDrop(CropType.PUMPKIN, DropRarity.RARE, "§9§lRARE DROP! §r§eDicer dropped §r§a1x §r§aEnchanted Pumpkin§r§e!")) - itemDrops.add(ItemDrop(CropType.PUMPKIN, DropRarity.CRAZY_RARE, "§d§lCRAZY RARE DROP! §r§eDicer dropped §r§a10x §r§aEnchanted Pumpkin§r§e!")) - itemDrops.add(ItemDrop(CropType.PUMPKIN, DropRarity.PRAY_TO_RNGESUS, "§5§lPRAY TO RNGESUS DROP! §r§eDicer dropped §r§a64x §r§aEnchanted Pumpkin§r§e!")) - } - - enum class DropRarity(val displayName: String) { - UNCOMMON("§a§lUNCOMMON DROP"), - RARE("§9§lRARE DROP"), - CRAZY_RARE("§d§lCRAZY RARE DROP"), - PRAY_TO_RNGESUS("§5§lPRAY TO RNGESUS DROP"), - } - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (!isEnabled()) return - - val message = event.message - for (drop in itemDrops) { - if (message == drop.message) { - addDrop(drop.crop, drop.rarity) - saveConfig() - update() - if (config.dicerCounterHideChat) { - event.blockedReason = "dicer_rng_drop_counter" - } - return - } - } - } - - private fun update() { - display = drawDisplay() - } - - private fun drawDisplay(): List { - val help = mutableListOf() - val items = drops[cropInHand] ?: return help - help.add("§7RNG Drops for $toolName§7:") - for ((rarity, amount) in items.sortedDesc()) { - val displayName = rarity.displayName - help.add(" §7- §e${amount.addSeparators()}x $displayName") - } - - return help - } - - private var cropInHand: CropType? = null - private var toolName = "" - - @SubscribeEvent - fun onGardenToolChange(event: GardenToolChangeEvent) { - val crop = event.crop - cropInHand = if (crop == CropType.MELON || crop == CropType.PUMPKIN) crop else null - if (cropInHand != null) { - toolName = event.toolItem!!.name!! - } - update() - } - - private fun addDrop(crop: CropType, rarity: DropRarity) { - val map = drops[crop]!! - val old = map[rarity] ?: 0 - map[rarity] = old + 1 - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (isEnabled()) { - config.dicerCounterPos.renderStrings(display, posLabel = "Dicer Counter") - } - } - - class ItemDrop(val crop: CropType, val rarity: DropRarity, val message: String) - - private fun saveConfig() { - val map = SkyHanniMod.feature.hidden.gardenDicerRngDrops - map.clear() - for (drop in drops) { - val crop = drop.key - for ((rarity, amount) in drop.value) { - map[crop.cropName + "." + rarity.name] = amount - } - } - } - - @SubscribeEvent - fun onConfigLoad(event: ConfigLoadEvent) { - for ((internalName, amount) in SkyHanniMod.feature.hidden.gardenDicerRngDrops) { - val split = internalName.split(".") - val crop = CropType.getByNameNoNull(split[0]) - val rarityName = split[1] - val rarity = DropRarity.valueOf(rarityName) - drops[crop]!![rarity] = amount - } - } - - fun isEnabled() = GardenAPI.inGarden() && config.dicerCounterDisplay -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt deleted file mode 100644 index bbcdd13dc..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt +++ /dev/null @@ -1,323 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.HypixelData -import at.hannibal2.skyhanni.events.GardenToolChangeEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed -import at.hannibal2.skyhanni.utils.APIUtil -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.round -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import at.hannibal2.skyhanni.utils.TimeUtils -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import net.minecraftforge.event.world.WorldEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent -import java.util.* - -class EliteFarmingWeight { - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (isEnabled()) { - config.eliteFarmingWeightPos.renderStrings(display, posLabel = "Elite Farming Weight") - } - } - - @SubscribeEvent - fun onGardenToolChange(event: GardenToolChangeEvent) { - // Reset speed - weightPerSecond = -1.0 - } - - @SubscribeEvent - fun onWorldChange(event: WorldEvent.Load) { - // We want to try to connect to the api again after a world switch. - apiError = false - // We ask both api endpoints after every world switch - weight = -1.0 - weightPerSecond = -1.0 - - leaderboardPosition = -1 - dirtyCropWeight = true - lastLeaderboardUpdate = 0 - nextPlayerWeight = 0.0 - nextPlayerName = "" - hasPassedNext = false - } - - var tick = 0 - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!isEnabled()) return - if (tick++ % 5 != 0) return - update() - } - - companion object { - private val config get() = SkyHanniMod.feature.garden - private val localCounter = mutableMapOf() - - private var display = listOf() - private var profileId = "" - private var lastLeaderboardUpdate = 0L - private var apiError = false - private var leaderboardPosition = -1 - private var weight = -2.0 - private var localWeight = 0.0 - private var weightPerSecond = -1.0 - private var dirtyCropWeight = false - private var isLoadingWeight = false - private var isLoadingLeaderboard = false - - private var nextPlayerName = "" - private var nextPlayerWeight = 0.0 - private var hasPassedNext = false - - private fun update() { - if (!GardenAPI.inGarden()) return - if (apiError) { - display = listOf( - "§6Farming Weight§7: §cError!", - "§cCannot load data from Elite Farmers!", - "§eRejoin garden to try again." - ) - return - } - if (weight == -2.0) { - display = Collections.singletonList("§6Farming Weight§7: §eLoading..") - return - } - - if (weight == -1.0) { - if (!isLoadingWeight) { - val localProfile = HypixelData.profileName - if (localProfile == "") return - - isLoadingWeight = true - SkyHanniMod.coroutineScope.launch { - loadWeight(localProfile) - isLoadingWeight = false - } - } - return - } - - val weight = getWeight() - val leaderboard = getLeaderboard() - - val list = mutableListOf() - list.add("§6Farming Weight§7: $weight$leaderboard") - - if (isEtaEnabled() && (weightPerSecond != -1.0 || config.eliteFarmingWeightOvertakeETAAlways)) { - list.add(getETA()) - } - display = list - } - - private fun getLeaderboard(): String { - if (!config.eliteFarmingWeightLeaderboard) return "" - - // Fetching new leaderboard position every 10 minutes - if (System.currentTimeMillis() > lastLeaderboardUpdate + 600_000) { - if (!isLoadingLeaderboard) { - isLoadingLeaderboard = true - SkyHanniMod.coroutineScope.launch { - leaderboardPosition = loadLeaderboardPosition() - lastLeaderboardUpdate = System.currentTimeMillis() - isLoadingLeaderboard = false - } - } - } - - return if (leaderboardPosition != -1) { - val format = LorenzUtils.formatInteger(leaderboardPosition) - " §7[§b#$format§7]" - } else { - if (isLoadingLeaderboard) { - " §7[§b#?§7]" - } else "" - } - } - - private fun getWeight(): String { - if (dirtyCropWeight) { - val values = calculateCollectionWeight().values - if (values.isNotEmpty()) { - localWeight = values.sum() - dirtyCropWeight = false - } - } - - val totalWeight = (localWeight + weight) - return "§e" + LorenzUtils.formatDouble(totalWeight, 2) - } - - private fun getETA(): String { - if (weight < 0) return "" - val nextName = if (leaderboardPosition == -1) "#1000" else nextPlayerName - - val totalWeight = (localWeight + weight) - val weightUntilOvertake = nextPlayerWeight - totalWeight - if (weightUntilOvertake < 0) { - if (!hasPassedNext) { - if (weightPerSecond > 0) { - LorenzUtils.debug("weightPerSecond: '$weightPerSecond'") - LorenzUtils.chat("§e[SkyHanni] You passed §b$nextName §ein the Farming Weight Leaderboard!") - } - if (leaderboardPosition == -1) { - leaderboardPosition = 1000 - } else { - leaderboardPosition-- - } - hasPassedNext = true - } - return "§cWaiting for leaderboard update..." - } - - if (nextPlayerWeight == 0.0) { - return "§cRejoin the garden to show ETA!" - } - val timeFormat = if (weightPerSecond != -1.0) { - val timeTillOvertake = (weightUntilOvertake / weightPerSecond) * 1000 - val format = TimeUtils.formatDuration(timeTillOvertake.toLong()) - " §7(§b$format§7)" - } else "" - - val weightFormat = LorenzUtils.formatDouble(weightUntilOvertake, 2) - return "§e$weightFormat$timeFormat §7behind §b$nextName" - } - - private fun isEnabled() = GardenAPI.inGarden() && config.eliteFarmingWeightDisplay - private fun isEtaEnabled() = config.eliteFarmingWeightOvertakeETA - - fun addCrop(crop: CropType, addedCounter: Int) { - val before = getExactWeight() - localCounter[crop] = crop.getLocalCounter() + addedCounter - val after = getExactWeight() - - updateWeightPerSecond(crop, before, after, addedCounter) - - dirtyCropWeight = true - } - - private fun updateWeightPerSecond(crop: CropType, before: Double, after: Double, diff: Int) { - val speed = crop.getSpeed() - if (speed != -1) { - val weightDiff = (after - before) * 1000 - weightPerSecond = weightDiff / diff * speed / 1000 - } - } - - private fun getExactWeight(): Double { - val values = calculateCollectionWeight(false).values - return if (values.isNotEmpty()) { - values.sum() - } else 0.0 - } - - private suspend fun loadLeaderboardPosition() = try { - val uuid = LorenzUtils.getPlayerUuid() - val showNext = if (isEtaEnabled()) "?showNext=true" else "" - val url = "https://elitebot.dev/api/leaderboard/rank/weight/farming/$uuid/$profileId$showNext" - val result = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }.asJsonObject - - if (isEtaEnabled()) { - result["next"]?.asJsonObject?.let { - nextPlayerName = it["ign"].asString - nextPlayerWeight = it["amount"].asDouble - } - } - - result["rank"].asInt - } catch (e: Exception) { - error() - e.printStackTrace() - -1 - } - - private suspend fun loadWeight(localProfile: String) { - val uuid = LorenzUtils.getPlayerUuid() - val url = "https://elitebot.dev/api/weight/$uuid" - - try { - val result = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }.asJsonObject - for (profileEntry in result["profiles"].asJsonObject.entrySet()) { - val profile = profileEntry.value.asJsonObject - val profileName = profile["cute_name"].asString.lowercase() - if (profileName == localProfile) { - profileId = profileEntry.key - weight = profile["farming"].asJsonObject["total"].asDouble - - localCounter.clear() - dirtyCropWeight = true - - return - } - } - println("localProfile: '$localProfile'") - println("url: '$url'") - println("result: '$result'") - } catch (e: Exception) { - println("url: '$url'") - e.printStackTrace() - } - error() - } - - private fun error() { - apiError = true - LorenzUtils.error("[SkyHanni] Loading the farming weight data from elitebot.dev failed!") - LorenzUtils.chat("§eYou can re-enter the garden to try to fix the problem. If this message repeats itself, please report it on Discord!") - } - - private fun calculateCollectionWeight(round: Boolean = true): MutableMap { - val weightPerCrop = mutableMapOf() - var totalWeight = 0.0 - for (crop in CropType.values()) { - val weight = crop.getLocalCounter() / crop.getFactor() - val roundedWeight = weight.let { if (round) it.round(2) else it } - weightPerCrop[crop] = roundedWeight - totalWeight += roundedWeight - } - if (totalWeight > 0) { - weightPerCrop[CropType.MUSHROOM] = specialMushroomWeight(weightPerCrop, totalWeight) - } - return weightPerCrop - } - - private fun specialMushroomWeight(weightPerCrop: MutableMap, totalWeight: Double): Double { - val cactusWeight = weightPerCrop[CropType.CACTUS]!! - val sugarCaneWeight = weightPerCrop[CropType.SUGAR_CANE]!! - val doubleBreakRatio = (cactusWeight + sugarCaneWeight) / totalWeight; - val normalRatio = (totalWeight - cactusWeight - sugarCaneWeight) / totalWeight; - - val mushroomFactor = CropType.MUSHROOM.getFactor() - val mushroomCollection = CropType.MUSHROOM.getLocalCounter() - return doubleBreakRatio * (mushroomCollection / (2 * mushroomFactor)) + normalRatio * (mushroomCollection / mushroomFactor) - } - - private fun CropType.getLocalCounter() = localCounter[this] ?: 0L - - private fun CropType.getFactor() = factorPerCrop[this]!! - - private val factorPerCrop by lazy { - mapOf( - CropType.WHEAT to 100_000.0, - CropType.CARROT to 300_000.0, - CropType.POTATO to 300_000.0, - CropType.SUGAR_CANE to 200_000.0, - CropType.NETHER_WART to 250_000.0, - CropType.PUMPKIN to 90_066.27, - CropType.MELON to 450_324.6, - CropType.MUSHROOM to 90_178.06, - CropType.COCOA_BEANS to 267_174.04, - CropType.CACTUS to 177_254.45, - ) - } - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingArmorDrops.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingArmorDrops.kt deleted file mode 100644 index c56347122..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingArmorDrops.kt +++ /dev/null @@ -1,107 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.ConfigLoadEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent -import java.util.regex.Pattern - -class FarmingArmorDrops { - private var display = listOf() - private val drops = mutableMapOf() - private var hasArmor = false - private var tick = 0 - private val armorPattern = Pattern.compile("(FERMENTO|CROPIE|SQUASH|MELON)_(LEGGINGS|CHESTPLATE|BOOTS|HELMET)") - private val config get() = SkyHanniMod.feature.garden - - enum class ArmorDropType(val dropName: String, val chatMessage: String) { - CROPIE("§9Cropie", "§6§lRARE CROP! §r§f§r§9Cropie §r§b(Armor Set Bonus)"), - SQUASH("§5Squash", "§6§lRARE CROP! §r§f§r§5Squash §r§b(Armor Set Bonus)"), - FERMENTO("§6Fermento", "§6§lRARE CROP! §r§f§r§6Fermento §r§b(Armor Set Bonus)"), - } - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - for (dropType in ArmorDropType.values()) { - if (dropType.chatMessage == event.message) { - addDrop(dropType) - if (config.farmingArmorDropsEnabled && config.farmingArmorDropsHideChat) { - event.blockedReason = "farming_armor_drops" - } - } - } - } - - private fun addDrop(drop: ArmorDropType) { - val old = drops[drop] ?: 0 - drops[drop] = old + 1 - saveConfig() - update() - } - - private fun update() { - display = drawDisplay() - } - - private fun drawDisplay(): List { - val help = mutableListOf() - help.add("§7RNG Drops for Farming Armor:") - for ((drop, amount) in drops.sortedDesc()) { - val dropName = drop.dropName - help.add(" §7- §e${amount.addSeparators()}x $dropName") - } - - return help - } - - private fun saveConfig() { - val map = SkyHanniMod.feature.hidden.gardenFarmingArmorDrops - map.clear() - for ((drop, amount) in drops) { - map[drop.toString()] = amount - } - } - - @SubscribeEvent - fun onConfigLoad(event: ConfigLoadEvent) { - for ((rawName, amount) in SkyHanniMod.feature.hidden.gardenFarmingArmorDrops) { - drops[ArmorDropType.valueOf(rawName)] = amount - } - update() - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (!GardenAPI.inGarden()) return - if (!config.farmingArmorDropsEnabled) return - if (!hasArmor) return - - config.farmingArmorDropsPos.renderStrings(display, posLabel = "Farming Armor Drops") - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (event.phase != TickEvent.Phase.START) return - if (!GardenAPI.inGarden()) return - if (!config.farmingArmorDropsEnabled) return - - tick++ - if (tick % 30 == 0) { - checkArmor() - } - } - - private fun checkArmor() { - val armorPieces = InventoryUtils.getArmor() - .mapNotNull { it?.getInternalName() } - .count { armorPattern.matcher(it).matches() } - hasArmor = armorPieces > 1 - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt deleted file mode 100644 index 049ef2552..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt +++ /dev/null @@ -1,106 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.GardenCropMilestones -import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter -import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon -import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed -import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList -import at.hannibal2.skyhanni.utils.LorenzUtils.sorted -import at.hannibal2.skyhanni.utils.TimeUtils - -class GardenBestCropTime { - var display = listOf>() - val timeTillNextCrop = mutableMapOf() - private val config get() = SkyHanniMod.feature.garden - - fun drawBestDisplay(currentCrop: CropType?): List> { - val newList = mutableListOf>() - if (timeTillNextCrop.size < CropType.values().size) { - updateTimeTillNextCrop() - } - - val gardenExp = config.cropMilestoneBestType == 0 - val sorted = if (gardenExp) { - val helpMap = mutableMapOf() - for ((cropName, time) in timeTillNextCrop) { - val currentTier = GardenCropMilestones.getTierForCrops(cropName.getCounter()) - val gardenExpForTier = getGardenExpForTier(currentTier + 1) - val fakeTime = time / gardenExpForTier - helpMap[cropName] = fakeTime - } - helpMap.sorted() - } else { - timeTillNextCrop.sorted() - } - - val title = if (gardenExp) "§2Garden Experience" else "§bSkyBlock Level" - if (config.cropMilestoneBestCompact) { - newList.addAsSingletonList("§eBest Crop Time") - } else { - newList.addAsSingletonList("§eBest Crop Time §7($title§7)") - } - - if (!config.cropMilestoneProgress) { - newList.addAsSingletonList("§cCrop Milestone Progress Display is disabled!") - return newList - } - - if (sorted.isEmpty()) { - newList.addAsSingletonList("§cFarm crops to add them to this list!") - return newList - } - - var number = 0 - for (crop in sorted.keys) { - val millis = timeTillNextCrop[crop]!! - val duration = TimeUtils.formatDuration(millis, maxUnits = 2) - val isCurrent = crop == currentCrop - number++ - if (number > config.cropMilestoneShowOnlyBest && !isCurrent) continue - - val list = mutableListOf() - list.add("§7$number# ") - list.addCropIcon(crop) - - val color = if (isCurrent) "§e" else "§7" - val contestFormat = if (GardenNextJacobContest.isNextCrop(crop)) "§n" else "" - val nextTier = GardenCropMilestones.getTierForCrops(crop.getCounter()) + 1 - - val cropName = if (!config.cropMilestoneBestCompact) crop.cropName + " " else "" - val cropNameDisplay = "$color$contestFormat$cropName$nextTier§r" - list.add("$cropNameDisplay §b$duration") - - if (gardenExp && !config.cropMilestoneBestCompact) { - val gardenExpForTier = getGardenExpForTier(nextTier) - list.add(" §7(§2$gardenExpForTier §7Exp)") - } - newList.add(list) - } - return newList - } - - private fun getGardenExpForTier(gardenLevel: Int) = if (gardenLevel > 30) 300 else gardenLevel * 10 - - fun updateTimeTillNextCrop() { - for (crop in CropType.values()) { - val speed = crop.getSpeed() - if (speed == -1) continue - - val counter = crop.getCounter() - val currentTier = GardenCropMilestones.getTierForCrops(counter) - - val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) - val nextTier = currentTier + 1 - val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier) - - val have = counter - cropsForCurrentTier - val need = cropsForNextTier - cropsForCurrentTier - - val missing = need - have - val missingTimeSeconds = missing / speed - val millis = missingTimeSeconds * 1000 - timeTillNextCrop[crop] = millis - } - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt deleted file mode 100644 index 9e4013088..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ /dev/null @@ -1,385 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ClickType -import at.hannibal2.skyhanni.data.GardenCropMilestones -import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter -import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter -import at.hannibal2.skyhanni.data.MayorElectionData -import at.hannibal2.skyhanni.data.TitleUtils -import at.hannibal2.skyhanni.events.* -import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType -import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon -import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType -import at.hannibal2.skyhanni.features.garden.GardenAPI.setSpeed -import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.TimeUtils -import net.minecraft.item.ItemStack -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.* -import kotlin.concurrent.fixedRateTimer - -class GardenCropMilestoneDisplay { - private var progressDisplay = listOf>() - private var mushroomCowPerkDisplay = listOf>() - private val cultivatingData = mutableMapOf() - private val config get() = SkyHanniMod.feature.garden - private val bestCropTime = GardenBestCropTime() -// val cropMilestoneLevelUpPattern = Pattern.compile(" §r§b§lGARDEN MILESTONE §3(.*) §8XXIII➜§3(.*)") - - private var lastPlaySoundTime = 0L - - private var needsInventory = false - - private var mushroom_cow_nether_warts = true - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - try { - val constant = event.getConstant("DisabledFeatures") - mushroom_cow_nether_warts = if (constant != null) { - if (constant.has("mushroom_cow_nether_warts")) { - constant["mushroom_cow_nether_warts"].asBoolean - } else false - } else false - } catch (e: Exception) { - e.printStackTrace() - } - } - - @SubscribeEvent - fun onChatMessage(event: LorenzChatEvent) { - if (!isEnabled()) return - // TODO remove this once hypixel counts 64x pumpkin drops to cultivating - if (event.message == "§a§lUNCOMMON DROP! §r§eDicer dropped §r§f64x §r§fPumpkin§r§e!") { - CropType.PUMPKIN.setCounter(CropType.PUMPKIN.getCounter() + 64) - } -// if (config.cropMilestoneWarnClose) { -// val matcher = cropMilestoneLevelUpPattern.matcher(event.message) -// if (matcher.matches()) { -// val cropType = matcher.group(1) -// val newLevel = matcher.group(2).romanToDecimalIfNeeded() -// LorenzUtils.debug("found milestone messsage!") -// SendTitleHelper.sendTitle("§b$cropType $newLevel", 1_500) -// } -// } - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (!isEnabled()) return - - config.cropMilestoneProgressDisplayPos.renderStringsAndItems( - progressDisplay, - posLabel = "Crop Milestone Progress" - ) - - if (config.cropMilestoneMushroomPetPerkEnabled) { - config.cropMilestoneMushroomPetPerkPos.renderStringsAndItems( - mushroomCowPerkDisplay, - posLabel = "Mushroom Cow Perk" - ) - } - - if (config.cropMilestoneBestDisplay) { - config.cropMilestoneNextDisplayPos.renderStringsAndItems(bestCropTime.display, posLabel = "Best Crop Time") - } - } - - @SubscribeEvent(priority = EventPriority.LOW) - fun onProfileJoin(event: ProfileJoinEvent) { - if (GardenCropMilestones.cropCounter.values.sum() == 0L) { - needsInventory = true - } - } - - @SubscribeEvent - fun onCropMilestoneUpdate(event: CropMilestoneUpdateEvent) { - needsInventory = false - bestCropTime.updateTimeTillNextCrop() - update() - } - - @SubscribeEvent - fun onOwnInventoryItemUpdate(event: OwnInventorItemUpdateEvent) { - if (!GardenAPI.inGarden()) return - - try { - val item = event.itemStack - val counter = GardenAPI.readCounter(item) - if (counter == -1) return - val crop = item.getCropType() ?: return - if (cultivatingData.containsKey(crop)) { - val old = cultivatingData[crop]!! - val addedCounter = counter - old - - if (GardenCropMilestones.cropCounter.isEmpty()) { - for (innerCrop in CropType.values()) { - innerCrop.setCounter(0) - } - } - if (GardenAPI.isSpeedDataEmpty()) { - for (cropType in CropType.values()) { - cropType.setSpeed(-1) - } - } - if (!finneganPerkActive()) { - crop.setCounter(crop.getCounter() + addedCounter) - } - EliteFarmingWeight.addCrop(crop, addedCounter) - if (currentCrop == crop) { - calculateSpeed(addedCounter) - update() - } - } - cultivatingData[crop] = counter - } catch (e: Throwable) { - LorenzUtils.error("[SkyHanni] Error in OwnInventorItemUpdateEvent") - e.printStackTrace() - } - } - - private fun finneganPerkActive(): Boolean { - val forcefullyEnabledAlwaysFinnegan = config.forcefullyEnabledAlwaysFinnegan - val perkActive = MayorElectionData.isPerkActive("Finnegan", "Farming Simulator") - MayorElectionData.currentCandidate?.let { - - } - return forcefullyEnabledAlwaysFinnegan || perkActive - } - - @SubscribeEvent - fun onBlockClick(event: BlockClickEvent) { - if (!isEnabled()) return - if (event.clickType != ClickType.LEFT_CLICK) return - - val blockState = event.getBlockState - - val cropType = blockState.getCropType() ?: return - val multiplier = cropType.multiplier - if (multiplier == 1) { - if (blockState.isBabyCrop()) return - } - blocksBroken += multiplier - } - - private var currentSpeed = 0 - private var averageSpeedPerSecond = 0 - private var countInLastSecond = 0 - private val allCounters = mutableListOf() - private var lastItemInHand: ItemStack? = null - private var currentCrop: CropType? = null - private var blocksBroken = 0 - private var lastBlocksPerSecond = 0 - - private fun resetSpeed() { - currentSpeed = 0 - averageSpeedPerSecond = 0 - countInLastSecond = 0 - allCounters.clear() - } - - init { - fixedRateTimer(name = "skyhanni-crop-milestone-speed", period = 1000L) { - if (GardenAPI.inGarden() && GardenAPI.mushroomCowPet) { - CropType.MUSHROOM.setCounter(CropType.MUSHROOM.getCounter() + blocksBroken) - update() - } - if (isEnabled()) { - checkSpeed() - } - } - } - - private fun checkSpeed() { - if (finneganPerkActive()) { - currentSpeed = (currentSpeed.toDouble() * 0.8).toInt() - } - - if (countInLastSecond > 8) { - allCounters.add(currentSpeed) - while (allCounters.size > 30) { - allCounters.removeFirst() - } - averageSpeedPerSecond = allCounters.average().toInt() - } - countInLastSecond = 0 - - if (finneganPerkActive()) { - currentCrop?.let { - it.setCounter(it.getCounter() + currentSpeed) - } - } - currentSpeed = 0 - - lastBlocksPerSecond = blocksBroken - blocksBroken = 0 - } - - - private fun calculateSpeed(addedCounter: Int) { - currentSpeed += addedCounter - countInLastSecond++ - } - - @SubscribeEvent - fun onGardenToolChange(event: GardenToolChangeEvent) { - lastItemInHand = event.toolItem - currentCrop = event.crop - - if (isEnabled()) { - resetSpeed() - update() - } - } - - private fun update() { - progressDisplay = emptyList() - mushroomCowPerkDisplay = emptyList() - bestCropTime.display = emptyList() - currentCrop?.let { - progressDisplay = drawProgressDisplay(it, it.getCounter()) - if (config.cropMilestoneBestDisplay) { - bestCropTime.display = bestCropTime.drawBestDisplay(it) - } - } - if (config.cropMilestoneBestAlwaysOn) { - if (currentCrop == null) { - bestCropTime.display = bestCropTime.drawBestDisplay(null) - } - } - } - - private fun drawProgressDisplay(crop: CropType, counter: Long): MutableList> { - val lineMap = HashMap>() - lineMap[0] = Collections.singletonList("§6Crop Milestones") - - val currentTier = GardenCropMilestones.getTierForCrops(counter) - val nextTier = currentTier + 1 - - val list = mutableListOf() - list.addCropIcon(crop) - list.add("§7" + crop.cropName + " Tier $nextTier") - lineMap[1] = list - - val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) - val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier) - - val have = counter - cropsForCurrentTier - val need = cropsForNextTier - cropsForCurrentTier - - val haveFormat = LorenzUtils.formatInteger(have) - val needFormat = LorenzUtils.formatInteger(need) - lineMap[2] = Collections.singletonList("§e$haveFormat§8/§e$needFormat") - - lastItemInHand?.let { - if (GardenAPI.readCounter(it) == -1) { - lineMap[3] = Collections.singletonList("§cWarning: You need Cultivating!") - return formatDisplay(lineMap) - } - } - - if (averageSpeedPerSecond != 0) { - crop.setSpeed(averageSpeedPerSecond) - val missing = need - have - val missingTimeSeconds = missing / averageSpeedPerSecond - val millis = missingTimeSeconds * 1000 - bestCropTime.timeTillNextCrop[crop] = millis - val duration = TimeUtils.formatDuration(millis) - if (config.cropMilestoneWarnClose) { - if (millis < 5_900) { - if (System.currentTimeMillis() > lastPlaySoundTime + 1_000) { - lastPlaySoundTime = System.currentTimeMillis() - SoundUtils.playBeepSound() - } - TitleUtils.sendTitle("§b${crop.cropName} $nextTier in $duration", 1_500) - } - } - lineMap[3] = Collections.singletonList("§7In §b$duration") - - val format = LorenzUtils.formatInteger(averageSpeedPerSecond * 60) - lineMap[4] = Collections.singletonList("§7Crops/Minute§8: §e$format") - lineMap[5] = Collections.singletonList("§7Blocks/Second§8: §e$lastBlocksPerSecond") - } - - if (GardenAPI.mushroomCowPet && crop != CropType.MUSHROOM) { - if (mushroom_cow_nether_warts && crop == CropType.NETHER_WART) { - mushroomCowPerkDisplay = listOf( - listOf("§6Mooshroom Cow Perk"), - listOf("§cNether Warts don't give mushrooms."), - listOf("§7(Hypixel please fix this)") - ) - } else { - addMushroomCowData() - } - } - - return formatDisplay(lineMap) - } - - private fun formatDisplay(lineMap: HashMap>): MutableList> { - val newList = mutableListOf>() - for (index in config.cropMilestoneText) { - lineMap[index]?.let { - newList.add(it) - } - } - - if (needsInventory) { - newList.addAsSingletonList("§cOpen §e/cropmilestones §cto update!") - } - - return newList - } - - private fun addMushroomCowData() { - val lineMap = HashMap>() - val counter = CropType.MUSHROOM.getCounter() - - val currentTier = GardenCropMilestones.getTierForCrops(counter) - val nextTier = currentTier + 1 - - val cropsForCurrentTier = GardenCropMilestones.getCropsForTier(currentTier) - val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier) - - val have = counter - cropsForCurrentTier - val need = cropsForNextTier - cropsForCurrentTier - - val haveFormat = LorenzUtils.formatInteger(have) - val needFormat = LorenzUtils.formatInteger(need) - - val missing = need - have - - // We assume perfect 20 blocks per seconds - val blocksPerSecond = 20 * (currentCrop?.multiplier ?: 1) - - val missingTimeSeconds = missing / blocksPerSecond - val millis = missingTimeSeconds * 1000 - val duration = TimeUtils.formatDuration(millis) - - lineMap[0] = Collections.singletonList("§6Mooshroom Cow Perk") - - val list = mutableListOf<