summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-04-19 15:34:43 +0200
committerGitHub <noreply@github.com>2023-04-19 15:34:43 +0200
commitee84a09894c450c35ac619cd3870b3887059985d (patch)
tree67a3754e86c4f720a6d98370c6289c520e4ce5b9 /src/main/java/at/hannibal2/skyhanni/features
parent8161cf66231cec9a18a4db74e5334065f23f9073 (diff)
downloadskyhanni-ee84a09894c450c35ac619cd3870b3887059985d.tar.gz
skyhanni-ee84a09894c450c35ac619cd3870b3887059985d.tar.bz2
skyhanni-ee84a09894c450c35ac619cd3870b3887059985d.zip
composter fix (#50)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt37
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt6
2 files changed, 27 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
index 0e0271b52..adbe90245 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
@@ -17,12 +17,14 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson
import at.hannibal2.skyhanni.utils.renderables.Renderable
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
+import java.util.*
import kotlin.math.ceil
import kotlin.time.Duration
import kotlin.time.DurationUnit
@@ -64,6 +66,8 @@ class ComposterOverlay {
var inInventory = false
}
+ var garden: GardenJson? = null
+
@SubscribeEvent
fun onInventoryClose(event: GuiContainerEvent.CloseWindowEvent) {
inInventory = false
@@ -128,6 +132,12 @@ class ComposterOverlay {
}
private fun update() {
+ if (organicMatterFactors.isEmpty()) {
+ organicMatterDisplay =
+ Collections.singletonList(listOf("§cSkyHanni composter error:", "§cRepo data not loaded!"))
+ return
+ }
+
if (inComposter) {
organicMatterDisplay = drawOrganicMatterDisplay()
fuelExtraDisplay = drawFuelExtraDisplay()
@@ -380,28 +390,29 @@ class ComposterOverlay {
}
@SubscribeEvent
+ fun onRepoReload(event: io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent) {
+ updateOrganicMatterFactors()
+ }
+
+ @SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- try {
- val garden = event.getConstant("Garden")!!
+ garden = event.getConstant<GardenJson>("Garden")!!
+ updateOrganicMatterFactors()
+ }
- val baseValues = mutableMapOf<String, Double>()
- for ((name, value) in garden["organic_matter"].asJsonObject.entrySet()) {
- baseValues[name] = value.asDouble
- }
- organicMatterFactors = updateOrganicMatterFactors(baseValues)
+ private fun updateOrganicMatterFactors() {
+ try {
+ val garden = this.garden ?: return
+ organicMatterFactors = updateOrganicMatterFactors(garden.organic_matter)
+ fuelFactors = garden.fuel
- val fuelMap = mutableMapOf<String, Double>()
- for ((name, value) in garden["fuel"].asJsonObject.entrySet()) {
- fuelMap[name] = value.asDouble
- }
- fuelFactors = fuelMap
} catch (e: Exception) {
e.printStackTrace()
LorenzUtils.error("error in RepositoryReloadEvent")
}
}
- private fun updateOrganicMatterFactors(baseValues: MutableMap<String, Double>): Map<String, Double> {
+ private fun updateOrganicMatterFactors(baseValues: Map<String, Double>): Map<String, Double> {
val map = mutableMapOf<String, Double>()
for ((internalName, _) in NotEnoughUpdates.INSTANCE.manager.itemInformation) {
if (internalName.endsWith("_BOOTS")) continue
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 7145c77d2..7b644578a 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
@@ -5,7 +5,7 @@ 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.MayorElection
import at.hannibal2.skyhanni.data.TitleUtils
import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.features.garden.CropType
@@ -151,8 +151,8 @@ class GardenCropMilestoneDisplay {
private fun finneganPerkActive(): Boolean {
val forcefullyEnabledAlwaysFinnegan = config.forcefullyEnabledAlwaysFinnegan
- val perkActive = MayorElectionData.isPerkActive("Finnegan", "Farming Simulator")
- MayorElectionData.currentCandidate?.let {
+ val perkActive = MayorElection.isPerkActive("Finnegan", "Farming Simulator")
+ MayorElection.currentCandidate?.let {
}
return forcefullyEnabledAlwaysFinnegan || perkActive