diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-01-31 18:55:38 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-01-31 18:55:38 +0100 |
commit | 1f99d218c62418a401cd69754e95eef329e3279d (patch) | |
tree | 7abb28b2f46a723647479689ba79cb9c34c8a183 /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | d9478299376f302773b59bb0961f2282ab1a03dc (diff) | |
download | skyhanni-1f99d218c62418a401cd69754e95eef329e3279d.tar.gz skyhanni-1f99d218c62418a401cd69754e95eef329e3279d.tar.bz2 skyhanni-1f99d218c62418a401cd69754e95eef329e3279d.zip |
Updating optimal speed immediately when changing the setting.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt index 3e5888868..f2e37e353 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent @@ -11,6 +12,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.renderables.Renderable +import io.github.moulberry.moulconfig.observer.Property import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiEditSign import net.minecraftforge.client.event.GuiOpenEvent @@ -79,10 +81,23 @@ class GardenOptimalSpeed { @SubscribeEvent fun onGardenToolChange(event: GardenToolChangeEvent) { cropInHand = event.crop - optimalSpeed = cropInHand.let { it?.getOptimalSpeed() ?: -1 } + optimalSpeed = cropInHand?.getOptimalSpeed() ?: -1 } - private fun CropType.getOptimalSpeed() = when (this) { + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + for (value in CropType.entries) { + LorenzUtils.onToggle(value.getConfig()) { + if (value == cropInHand) { + optimalSpeed = value.getOptimalSpeed() + } + } + } + } + + private fun CropType.getOptimalSpeed() = getConfig().get().toInt() + + private fun CropType.getConfig(): Property<Float> = when (this) { CropType.WHEAT -> configCustomSpeed.wheat CropType.CARROT -> configCustomSpeed.carrot CropType.POTATO -> configCustomSpeed.potato |