diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-08 16:08:47 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-08 16:08:47 +0100 |
commit | 2aa43969da8e5413e25bfa107d60e6a5835ee1e1 (patch) | |
tree | b9a6e71b6951489485a0fb8c9c02e9120925bb9a /src/main/java | |
parent | 6a52e0a5c9d168ad0e3ef549f6a77e140f92b174 (diff) | |
download | skyhanni-2aa43969da8e5413e25bfa107d60e6a5835ee1e1.tar.gz skyhanni-2aa43969da8e5413e25bfa107d60e6a5835ee1e1.tar.bz2 skyhanni-2aa43969da8e5413e25bfa107d60e6a5835ee1e1.zip |
Add rancher boots speed display and optimal speed display
Diffstat (limited to 'src/main/java')
4 files changed, 114 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index cf5f62502..c9ab200ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -198,6 +198,11 @@ public class Features extends Config { editOverlay(activeConfigCategory, 200, 16, misc.chickenHeadTimerPosition); return; } + + if (runnableId.equals("optimalSpeed")) { + editOverlay(activeConfigCategory, 200, 16, garden.optimalSpeedPos); + return; + } } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index 14858122c..58e014ce9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -156,7 +156,7 @@ public class Garden { @ConfigOption(name = "Display Position", desc = "") @ConfigEditorButton(runnableId = "cropMilestoneProgress", buttonText = "Edit") @ConfigAccordionId(id = 6) - public Position cropMilestoneProgressDisplayPos = new Position(-363, 12, false, true); + public Position cropMilestoneProgressDisplayPos = new Position(376, 19, false, true); @Expose @ConfigOption(name = "Best Crop", desc = "") @@ -206,11 +206,6 @@ public class Garden { @ConfigAccordionId(id = 7) public Position cropMilestoneNextDisplayPos = new Position(-112, -143, false, true); - @Expose - @ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.") - @ConfigEditorBoolean - public boolean plotPrice = true; - // TODO moulconfig runnable suppoort @Expose @ConfigOption(name = "Custom Keybind", desc = "") @@ -274,4 +269,32 @@ public class Garden { @ConfigAccordionId(id = 8) @ConfigEditorKeybind(defaultKey = Keyboard.KEY_LSHIFT) public int keyBindSneak = Keyboard.KEY_LSHIFT; + + @Expose + @ConfigOption(name = "Optimal Speed", desc = "") + @ConfigEditorAccordion(id = 9) + public boolean optimalSpeed = false; + + @Expose + @ConfigOption(name = "Enabled", desc = "Show the optimal speed for your current tool in the hand. (Ty MelonKingDE for the values)") + @ConfigEditorBoolean + @ConfigAccordionId(id = 9) + public boolean optimalSpeedEnabled = true; + + @Expose + @ConfigOption(name = "Enabled", desc = "Warn via title when you don't have the optimal speed.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 9) + public boolean optimalSpeedWarning = false; + + @Expose + @ConfigOption(name = "Speed Warning Position", desc = "") + @ConfigEditorButton(runnableId = "optimalSpeed", buttonText = "Edit") + @ConfigAccordionId(id = 9) + public Position optimalSpeedPos = new Position(188, -105, false, true); + + @Expose + @ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.") + @ConfigEditorBoolean + public boolean plotPrice = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt new file mode 100644 index 000000000..1189d69cd --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt @@ -0,0 +1,79 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.Garden +import at.hannibal2.skyhanni.data.SendTitleHelper +import at.hannibal2.skyhanni.events.GardenToolChangeEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class GardenOptimalSpeed { + private val config: Garden get() = SkyHanniMod.feature.garden + private var currentSpeed = 100 + private var optimalSpeed = -1 + private val currentSpeedPattern = Pattern.compile(" Speed: §r§f✦(.*)") + private var lastWarnTime = 0L + + @SubscribeEvent + fun onTabListUpdate(event: TabListUpdateEvent) { + for (line in event.tabList) { + val matcher = currentSpeedPattern.matcher(line) + if (matcher.matches()) { + currentSpeed = matcher.group(1).toInt() + } + } + } + + @SubscribeEvent + fun onGardenToolChange(event: GardenToolChangeEvent) { + if (isEnabled()) { + optimalSpeed = GardenAPI.cropInHand.let { if (it != null) speedForCrop(it) else -1 } + } + } + + private fun speedForCrop(crop: String) = when (crop) { + "Wheat" -> 93 + "Carrot" -> 93 + "Potato" -> 93 + "Pumpkin" -> 155 + "Sugar Cane" -> 328 + "Melon" -> 155 + "Cactus" -> 400 // 500 with racing helmet + "Cocoa Beans" -> 155 + "Mushroom" -> 233 + "Nether Wart" -> 93 + + else -> -1 + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + if (!Minecraft.getMinecraft().thePlayer.onGround) return + + if (optimalSpeed == -1) return + + val text = "Optimal Speed: §f$optimalSpeed" + if (optimalSpeed != currentSpeed) { + config.optimalSpeedPos.renderString("§c$text") + if (config.optimalSpeedWarning) { + if (System.currentTimeMillis() > lastWarnTime + 20_000) { + lastWarnTime = System.currentTimeMillis() + SendTitleHelper.sendTitle("§cWrong speed!", 3_000) + GardenAPI.cropInHand?.let { + LorenzUtils.chat("§e[SkyHanni] Wrong speed for $it: §f$currentSpeed §e(§f$optimalSpeed §eis optimal)") + } + } + } + } else { + config.optimalSpeedPos.renderString("§a$text") + } + } + + private fun isEnabled() = GardenAPI.inGarden() && config.optimalSpeedEnabled +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt index 5f5b1eea5..20ee57028 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -219,7 +219,7 @@ class GardenVisitorFeatures { } @SubscribeEvent - fun onTick(event: TabListUpdateEvent) { + fun onTabListUpdate(event: TabListUpdateEvent) { if (!isEnabled()) return var found = false val visitorsInTab = mutableListOf<String>() |