diff options
Diffstat (limited to 'src/main/java')
3 files changed, 40 insertions, 7 deletions
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 406213ec9..14858122c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -218,7 +218,7 @@ public class Garden { public boolean keybind = false; @Expose - @ConfigOption(name = "Enabled", desc = "Use custom keybinds while having a farming tool in the hand in the garden. §cOnly updates after scrolling in the hotbar.") + @ConfigOption(name = "Enabled", desc = "Use custom keybinds while having a farming tool or Daedalus Axe in the hand in the garden. §cOnly updates after scrolling in the hotbar.") @ConfigEditorBoolean @ConfigAccordionId(id = 8) public boolean keyBindEnabled = false; 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 9febca860..a8f8e84a8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -41,15 +41,19 @@ class GardenAPI { fun getCropTypeFromItem(heldItem: ItemStack): String? { val name = heldItem.name ?: return null + return getCropTypeFromItem(name) + } + + fun getCropTypeFromItem(itemName: String): String? { for ((crop, _) in GardenCropMilestones.cropCounter) { - if (name.contains(crop)) { + if (itemName.contains(crop)) { return crop } } - if (name.contains("Coco Chopper")) { + if (itemName.contains("Coco Chopper")) { return "Cocoa Beans" } - if (name.contains("Fungi Cutter")) { + if (itemName.contains("Fungi Cutter")) { return "Mushroom" } return null diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCustomKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCustomKeybinds.kt index f80fcb0ce..7130bac5b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCustomKeybinds.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCustomKeybinds.kt @@ -3,12 +3,13 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.core.config.KeybindHelper import at.hannibal2.skyhanni.config.features.Garden -import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.mixins.transformers.AccessorKeyBinding +import at.hannibal2.skyhanni.utils.ItemUtils.name import net.minecraft.client.Minecraft import net.minecraft.client.settings.KeyBinding import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent class GardenCustomKeybinds { private val shConfig: Garden get() = SkyHanniMod.feature.garden @@ -29,15 +30,43 @@ class GardenCustomKeybinds { Runtime.getRuntime().addShutdownHook(Thread { reset() }) } + private var tick = 0 + private var itemInHand = "" + @SubscribeEvent - fun onGardenToolChange(event: GardenToolChangeEvent) { - if (isEnabled() && GardenAPI.cropInHand != null) { + fun onTick(event: TickEvent.ClientTickEvent) { + if (event.phase != TickEvent.Phase.START) return + if (!GardenAPI.inGarden()) return + if (tick++ % 5 != 0) return + + val crop = loadItemInHand() + if (itemInHand != crop) { + itemInHand = crop + update() + } + } + + private fun update() { + if (isEnabled() && itemInHand != "") { applyCustomKeybinds() } else { reset() } } + private fun loadItemInHand(): String { + val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return "" + val name = heldItem.name ?: return "" + if (GardenAPI.readCounter(heldItem) == -1) { + if (name.contains("Daedalus Axe")) { + return "Daedalus Axe" + } + return "" + } + + return GardenAPI.getCropTypeFromItem(name) ?: "" + } + @SubscribeEvent fun onWorldChange(event: WorldEvent.Load) { reset() |