aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-28 23:00:02 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-28 23:00:02 +0200
commitfb6ab0c95b805617898123a393347b17d7eb2bb9 (patch)
tree06cc18a3532e5f4c968a0cff37dbb46af1d0bc83 /src/main/java
parentb8ad16add932307fc2ac4b2c82763938abbe2ddc (diff)
downloadskyhanni-fb6ab0c95b805617898123a393347b17d7eb2bb9.tar.gz
skyhanni-fb6ab0c95b805617898123a393347b17d7eb2bb9.tar.bz2
skyhanni-fb6ab0c95b805617898123a393347b17d7eb2bb9.zip
Removed cultivating requirements from crop milestone display, best crop time display and money per hour display
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt160
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt101
5 files changed, 140 insertions, 141 deletions
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<String, CropType>() // internalName -> cropName
- private var hasCropInHand = false
private val toolHasBountiful: MutableMap<CropType, Boolean> 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<Any>()
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<List<Any>>()
private var mushroomCowPerkDisplay = listOf<List<Any>>()
private val cultivatingData = mutableMapOf<CropType, Long>()
@@ -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<Int>()
- 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<Int>()
+ 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