From 2cc794f53b19b345f93f3167b6c4d3b164dd4a1d Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 28 Apr 2023 20:49:53 +0200 Subject: Code cleanup --- src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt | 2 +- src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt | 2 +- .../at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt index 2aa1ec65a..7346d4310 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt @@ -7,5 +7,5 @@ class InventoryCloseEvent(val inventory: OtherInventoryData.Inventory): LorenzEv val inventoryId: Int by lazy { inventory.windowId } val inventoryName: String by lazy {inventory.title } val inventorySize: Int by lazy {inventory.slotCount } - val inventoryItems: MutableMap by lazy {inventory.items } + val inventoryItems: Map by lazy {inventory.items } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt index 3c95e4507..0b894d87e 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt @@ -7,7 +7,7 @@ open class BaseInventoryOpenEvent(inventory: OtherInventoryData.Inventory): Lore val inventoryId: Int by lazy { inventory.windowId } val inventoryName: String by lazy {inventory.title } val inventorySize: Int by lazy {inventory.slotCount } - val inventoryItems: MutableMap by lazy {inventory.items } + val inventoryItems: Map by lazy {inventory.items } } class InventoryOpenEvent(inventory: OtherInventoryData.Inventory): BaseInventoryOpenEvent(inventory) 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 c7ea644cb..10ecc6df0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -103,7 +103,7 @@ class GardenNextJacobContest { } } - private fun readCalendar(items: MutableCollection, year: Int, month: Int) { + private fun readCalendar(items: Collection, year: Int, month: Int) { if (contests.isNotEmpty()) { val contest = contests.values.first() val endTime = contest.endTime -- cgit From 2b3a1c48a751bdfcb810143429610da299824f7d Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:23:19 +0200 Subject: Added fake message when garden level up higher than 15 --- .../skyhanni/features/garden/GardenLevelDisplay.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt index 38b31b57e..4ee33e2b4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -38,9 +38,24 @@ class GardenLevelDisplay { if (!isEnabled()) return visitorRewardPattern.matchMatcher(event.message) { - gardenExp += group("exp").toInt() - update() + addExp(group("exp").toInt()) + } + } + + private fun addExp(moreExp: Int) { + val oldLevel = getLevelForExp(gardenExp.toLong()) + gardenExp += moreExp + val newLevel = getLevelForExp(gardenExp.toLong()) + if (newLevel == oldLevel + 1) { + if (newLevel > 15) { + LorenzUtils.chat( + " \n" + + "§b§lGARDEN LEVEL UP §8$oldLevel -> §b$newLevel\n" + + " §8+§aRespect from Elite Farmers and SkyHanni members :)\n " + ) + } } + update() } @SubscribeEvent -- cgit From b87e6ed0fc245878d81c3f69ed2fa8b8d57299f9 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 28 Apr 2023 23:00:02 +0200 Subject: Removed cultivating requirements from crop milestone display, best crop time display and money per hour display --- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 3 +- .../skyhanni/features/garden/GardenAPI.kt | 6 + .../features/garden/farming/CropMoneyDisplay.kt | 11 +- .../garden/farming/GardenCropMilestoneDisplay.kt | 160 ++++----------------- .../features/garden/farming/GardenCropSpeed.kt | 101 +++++++++++++ 5 files changed, 140 insertions(+), 141 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 66452e7e2..97e90936a 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -155,6 +155,7 @@ public class SkyHanniMod { loadModule(new GardenComposterUpgradesData()); loadModule(new ActionBarStatsData()); loadModule(new GardenCropMilestoneAverage()); + loadModule(GardenCropSpeed.INSTANCE); // APIs loadModule(new BazaarApi()); @@ -251,7 +252,7 @@ public class SkyHanniMod { loadModule(new GardenInventoryNumbers()); loadModule(new GardenVisitorTimer()); loadModule(new GardenNextPlotPrice()); - loadModule(new GardenCropMilestoneDisplay()); + loadModule(GardenCropMilestoneDisplay.INSTANCE); loadModule(GardenCustomKeybinds.INSTANCE); loadModule(new ChickenHeadTimer()); loadModule(new GardenOptimalSpeed()); 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 bd393589a..31cfa4b49 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI import at.hannibal2.skyhanni.features.garden.farming.GardenBestCropTime +import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils @@ -173,4 +174,9 @@ object GardenAPI { updateGardenTool() LorenzUtils.chat("§e[SkyHanni] Manually reset all crop speed data!") } + + fun getCurrentlyFarmedCrop(): CropType? { + val brokenCrop = if (toolInHand != null) GardenCropSpeed.lastBrokenCrop else null + return cropInHand ?: brokenCrop + } } \ No newline at end of file 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 485ba6435..c26fbd278 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 @@ -36,7 +36,6 @@ class CropMoneyDisplay { private var loaded = false private var ready = false private val cropNames = mutableMapOf() // internalName -> cropName - private var hasCropInHand = false private val toolHasBountiful: MutableMap get() = SkyHanniMod.feature.hidden.gardenToolHasBountiful @SubscribeEvent @@ -50,7 +49,6 @@ class CropMoneyDisplay { @SubscribeEvent fun onGardenToolChange(event: GardenToolChangeEvent) { - hasCropInHand = event.crop != null update() } @@ -58,7 +56,8 @@ class CropMoneyDisplay { fun onTick(event: TickEvent.ClientTickEvent) { if (!isEnabled()) return if (tick++ % (20 * 5) != 0) return - if (!hasCropInHand && !config.moneyPerHourAlwaysOn) return + + if (GardenAPI.getCurrentlyFarmedCrop() == null && !config.moneyPerHourAlwaysOn) return update() } @@ -84,7 +83,7 @@ class CropMoneyDisplay { return newDisplay } - if (!hasCropInHand && !config.moneyPerHourAlwaysOn) return newDisplay + if (GardenAPI.getCurrentlyFarmedCrop() == null && !config.moneyPerHourAlwaysOn) return newDisplay newDisplay.addAsSingletonList(fullTitle(title)) @@ -94,7 +93,7 @@ class CropMoneyDisplay { } var extraNetherWartPrices = 0.0 - GardenAPI.cropInHand?.let { + GardenAPI.getCurrentlyFarmedCrop()?.let { val reforgeName = Minecraft.getMinecraft().thePlayer.heldItem?.getReforgeName() toolHasBountiful[it] = reforgeName == "bountiful" @@ -127,7 +126,7 @@ class CropMoneyDisplay { for (internalName in help.sortedDesc().keys) { number++ val cropName = cropNames[internalName]!! - val isCurrent = cropName == GardenAPI.cropInHand + val isCurrent = cropName == GardenAPI.getCurrentlyFarmedCrop() if (number > config.moneyPerHourShowOnlyBest && (!config.moneyPerHourShowCurrent || !isCurrent)) continue val list = mutableListOf() 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 7a712cc0d..1fcd91fcf 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 @@ -1,35 +1,28 @@ package at.hannibal2.skyhanni.features.garden.farming 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.MayorElection import at.hannibal2.skyhanni.data.TitleUtils import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.features.garden.CropType -import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType import at.hannibal2.skyhanni.features.garden.FarmingFortuneDisplay import at.hannibal2.skyhanni.features.garden.GardenAPI 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.LorenzUtils.round 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 -import kotlin.math.abs -class GardenCropMilestoneDisplay { +object GardenCropMilestoneDisplay { private var progressDisplay = listOf>() private var mushroomCowPerkDisplay = listOf>() private val cultivatingData = mutableMapOf() @@ -107,14 +100,13 @@ class GardenCropMilestoneDisplay { cropType.setSpeed(-1) } } - if (!finneganPerkActive()) { - crop.setCounter(crop.getCounter() + addedCounter) - } EliteFarmingWeight.addCrop(crop, addedCounter) - if (currentCrop == crop) { - calculateSpeed(addedCounter) - update() - } + update() + crop.setCounter( + crop.getCounter() + if (GardenCropSpeed.finneganPerkActive()) { + (addedCounter.toDouble() * 0.8).toInt() + } else addedCounter + ) } cultivatingData[crop] = counter } catch (e: Throwable) { @@ -123,117 +115,18 @@ class GardenCropMilestoneDisplay { } } - private fun finneganPerkActive(): Boolean { - val forcefullyEnabledAlwaysFinnegan = config.forcefullyEnabledAlwaysFinnegan - val perkActive = MayorElection.isPerkActive("Finnegan", "Farming Simulator") - MayorElection.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 - if (cropType.multiplier == 1) { - if (blockState.isBabyCrop()) return - } - blocksBroken++ - } - - private var currentSpeed = 0 - private var averageBlocksPerSecond = 0.0 - - private val blocksSpeedList = mutableListOf() - private var lastItemInHand: ItemStack? = null - private var currentCrop: CropType? = null - private var blocksBroken = 0 - private var lastBlocksBroken = 0 - - private fun resetSpeed() { - currentSpeed = 0 - averageBlocksPerSecond = 0.0 - blocksBroken = 0 - blocksSpeedList.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() - } - - val blocksBroken = blocksBroken.coerceAtMost(20) - this.blocksBroken = 0 - - // If the difference in speed between the current and the previous bps value is too high, disregard this value - if (abs(lastBlocksBroken - blocksBroken) > 4) { - if (blocksSpeedList.isNotEmpty()) { - blocksSpeedList.removeLast() - } - } else if (blocksBroken >= 2) { - blocksSpeedList.add(blocksBroken) - while (blocksSpeedList.size > 120) { - blocksSpeedList.removeFirst() - } - averageBlocksPerSecond = blocksSpeedList.average() - - } - lastBlocksBroken = blocksBroken - - if (finneganPerkActive()) { - currentCrop?.let { - it.setCounter(it.getCounter() + currentSpeed) - } - } - currentSpeed = 0 - } - - - private fun calculateSpeed(addedCounter: Int) { - currentSpeed += addedCounter - } - - @SubscribeEvent - fun onGardenToolChange(event: GardenToolChangeEvent) { - lastItemInHand = event.toolItem - currentCrop = event.crop - - if (isEnabled()) { - resetSpeed() - update() - } - } - - private fun update() { + fun update() { progressDisplay = emptyList() mushroomCowPerkDisplay = emptyList() bestCropTime.display = emptyList() + val currentCrop = GardenAPI.getCurrentlyFarmedCrop() 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) + + if (config.cropMilestoneBestDisplay) { + if (config.cropMilestoneBestAlwaysOn || currentCrop != null) { + bestCropTime.display = bestCropTime.drawBestDisplay(currentCrop) } } } @@ -260,16 +153,9 @@ class GardenCropMilestoneDisplay { val needFormat = LorenzUtils.formatInteger(need) lineMap[2] = Collections.singletonList("§e$haveFormat§8/§e$needFormat") - lastItemInHand?.let { - if (GardenAPI.readCounter(it) == -1L) { - lineMap[3] = Collections.singletonList("§cWarning: You need Cultivating!") - return formatDisplay(lineMap) - } - } - - val farmingFortune = FarmingFortuneDisplay.getCurrentFarmingFortune(true) - val farmingFortuneSpeed = (farmingFortune * crop.baseDrops * averageBlocksPerSecond / 100).round(1).toInt() + val speed = GardenCropSpeed.averageBlocksPerSecond + val farmingFortuneSpeed = (farmingFortune * crop.baseDrops * speed / 100).round(1).toInt() if (farmingFortuneSpeed > 0) { crop.setSpeed(farmingFortuneSpeed) @@ -289,11 +175,17 @@ class GardenCropMilestoneDisplay { } } } - lineMap[3] = Collections.singletonList("§7In §b$duration") + val speedText = "§7In §b$duration" + lineMap[3] = Collections.singletonList(speedText) + GardenAPI.itemInHand?.let { + if (GardenAPI.readCounter(it) == -1L) { + lineMap[3] = listOf(speedText, " §7Inaccurate!") + } + } val format = LorenzUtils.formatInteger(farmingFortuneSpeed * 60) lineMap[4] = Collections.singletonList("§7Crops/Minute§8: §e$format") - val formatBps = LorenzUtils.formatDouble(averageBlocksPerSecond, 2) + val formatBps = LorenzUtils.formatDouble(speed, 2) lineMap[5] = Collections.singletonList("§7Blocks/Second§8: §e$formatBps") } @@ -349,9 +241,9 @@ class GardenCropMilestoneDisplay { lineMap[2] = Collections.singletonList("§e$haveFormat§8/§e$needFormat") - - if (averageBlocksPerSecond != 0.0) { - val blocksPerSecond = averageBlocksPerSecond * (currentCrop?.multiplier ?: 1) + val speed = GardenCropSpeed.averageBlocksPerSecond + if (speed != 0.0) { + val blocksPerSecond = speed * (GardenAPI.getCurrentlyFarmedCrop()?.multiplier ?: 1) val missingTimeSeconds = missing / blocksPerSecond val millis = missingTimeSeconds * 1000 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 new file mode 100644 index 000000000..a7b1846d7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -0,0 +1,101 @@ +package at.hannibal2.skyhanni.features.garden.farming + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ClickType +import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter +import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter +import at.hannibal2.skyhanni.data.MayorElection +import at.hannibal2.skyhanni.events.BlockClickEvent +import at.hannibal2.skyhanni.events.GardenToolChangeEvent +import at.hannibal2.skyhanni.features.garden.CropType +import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.concurrent.fixedRateTimer +import kotlin.math.abs + +object GardenCropSpeed { + private val config get() = SkyHanniMod.feature.garden + + var lastBrokenCrop: CropType? = null + var averageBlocksPerSecond = 0.0 + + private val blocksSpeedList = mutableListOf() + private var blocksBroken = 0 + private var lastBlocksBroken = 0 + + + init { + fixedRateTimer(name = "skyhanni-crop-milestone-speed", period = 1000L) { + if (isEnabled()) { + if (GardenAPI.mushroomCowPet) { + CropType.MUSHROOM.setCounter(CropType.MUSHROOM.getCounter() + blocksBroken) + } + checkSpeed() + update() + } + } + } + + @SubscribeEvent + fun onGardenToolChange(event: GardenToolChangeEvent) { + if (isEnabled()) { + resetSpeed() + update() + } + } + + private fun update() { + GardenCropMilestoneDisplay.update() + } + + @SubscribeEvent + fun onBlockClick(event: BlockClickEvent) { + if (!GardenAPI.inGarden()) return + if (event.clickType != ClickType.LEFT_CLICK) return + + val blockState = event.getBlockState + + val cropType = blockState.getCropType() ?: return + if (cropType.multiplier == 1) { + if (blockState.isBabyCrop()) return + } + lastBrokenCrop = cropType + blocksBroken++ + } + + private fun checkSpeed() { + val blocksBroken = blocksBroken.coerceAtMost(20) + this.blocksBroken = 0 + + // If the difference in speed between the current and the previous bps value is too high, disregard this value + if (abs(lastBlocksBroken - blocksBroken) > 4) { + if (blocksSpeedList.isNotEmpty()) { + blocksSpeedList.removeLast() + } + } else if (blocksBroken >= 2) { + blocksSpeedList.add(blocksBroken) + while (blocksSpeedList.size > 120) { + blocksSpeedList.removeFirst() + } + averageBlocksPerSecond = blocksSpeedList.average() + + } + lastBlocksBroken = blocksBroken + } + + private fun resetSpeed() { + averageBlocksPerSecond = 0.0 + blocksBroken = 0 + blocksSpeedList.clear() + } + + fun finneganPerkActive(): Boolean { + val forcefullyEnabledAlwaysFinnegan = config.forcefullyEnabledAlwaysFinnegan + val perkActive = MayorElection.isPerkActive("Finnegan", "Farming Simulator") + return forcefullyEnabledAlwaysFinnegan || perkActive + } + + fun isEnabled() = GardenAPI.inGarden() +} \ No newline at end of file -- cgit