From 1f99d218c62418a401cd69754e95eef329e3279d Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:55:38 +0100 Subject: Updating optimal speed immediately when changing the setting. --- .../garden/optimalspeed/CustomSpeedConfig.java | 21 +++++++++++---------- .../skyhanni/features/garden/GardenOptimalSpeed.kt | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/CustomSpeedConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/CustomSpeedConfig.java index 615883c96..768a155a6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/CustomSpeedConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/CustomSpeedConfig.java @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.config.features.garden.optimalspeed; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider; import io.github.moulberry.moulconfig.annotations.ConfigOption; +import io.github.moulberry.moulconfig.observer.Property; public class CustomSpeedConfig { @@ -11,56 +12,56 @@ public class CustomSpeedConfig { "§e5 Blocks§7: §f✦ 93 speed\n" + "§e4 Blocks§7: §f✦ 116 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int wheat = 93; + public Property wheat = Property.of(93f); @Expose @ConfigOption(name = "Carrot", desc = "Suggested farm speed:\n" + "§e5 Blocks§7: §f✦ 93 speed\n" + "§e4 Blocks§7: §f✦ 116 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int carrot = 93; + public Property carrot = Property.of(93f); @Expose @ConfigOption(name = "Potato", desc = "Suggested farm speed:\n" + "§e5 Blocks§7: §f✦ 93 speed\n" + "§e4 Blocks§7: §f✦ 116 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int potato = 93; + public Property potato = Property.of(93f); @Expose @ConfigOption(name = "Nether Wart", desc = "Suggested farm speed:\n" + "§e5 Blocks§7: §f✦ 93 speed\n" + "§e4 Blocks§7: §f✦ 116 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int netherWart = 93; + public Property netherWart = Property.of(93f); @Expose @ConfigOption(name = "Pumpkin", desc = "Suggested farm speed:\n" + "§e3 Blocks§7: §f✦ 155 speed\n" + "§e2 Blocks§7: §f✦ 265 §7or §f400 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int pumpkin = 155; + public Property pumpkin = Property.of(155f); @Expose @ConfigOption(name = "Melon", desc = "Suggested farm speed:\n" + "§e3 Blocks§7: §f✦ 155 speed\n" + "§e2 Blocks§7: §f✦ 265 or 400 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int melon = 155; + public Property melon = Property.of(155f); @Expose @ConfigOption(name = "Cocoa Beans", desc = "Suggested farm speed:\n" + "§e3 Blocks§7: §f✦ 155 speed\n" + "§e4 Blocks§7: §f✦ 116 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int cocoaBeans = 155; + public Property cocoaBeans = Property.of(155f); // TODO does other speed settings exist? @Expose @ConfigOption(name = "Sugar Cane", desc = "Suggested farm speed:\n" + "§eYaw 45§7: §f✦ 328 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int sugarCane = 328; + public Property sugarCane = Property.of(328f); @Expose @ConfigOption(name = "Cactus", desc = "Suggested farm speed:\n" + @@ -68,12 +69,12 @@ public class CustomSpeedConfig { "§eRacing Helmet§7: §f✦ 464 speed\n" + "§eBlack Cat§7: §f✦ 464 speed") @ConfigEditorSlider(minValue = 1, maxValue = 500, minStep = 1) - public int cactus = 400; + public Property cactus = Property.of(400f); // TODO does other speed settings exist? @Expose @ConfigOption(name = "Mushroom", desc = "Suggested farm speed:\n" + "§eYaw 60§7: §f✦ 233 speed") @ConfigEditorSlider(minValue = 1, maxValue = 400, minStep = 1) - public int mushroom = 233; + public Property mushroom = Property.of(233f); } 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 = when (this) { CropType.WHEAT -> configCustomSpeed.wheat CropType.CARROT -> configCustomSpeed.carrot CropType.POTATO -> configCustomSpeed.potato -- cgit