From 66193709ac7f5ceb2932490827d647b88ab6d346 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:11:04 +0100 Subject: Showing optimal speed and best crop time for tools without cultivating. Added a warning to farming tools without cultivating --- .../skyhanni/events/GardenToolChangeEvent.kt | 4 +++- .../hannibal2/skyhanni/features/garden/GardenAPI.kt | 11 +++++------ .../features/garden/GardenCropMilestoneDisplay.kt | 19 +++++++++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt index cc9f6c961..3d88710fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt @@ -1,3 +1,5 @@ package at.hannibal2.skyhanni.events -class GardenToolChangeEvent: LorenzEvent() \ No newline at end of file +import net.minecraft.item.ItemStack + +class GardenToolChangeEvent(val crop: String?, val heldItem: ItemStack?) : LorenzEvent() \ No newline at end of file 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 44298a16d..e71f809ce 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -14,7 +14,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent class GardenAPI { - var tick = 0 @SubscribeEvent @@ -23,10 +22,11 @@ class GardenAPI { if (!inGarden()) return if (tick++ % 5 != 0) return - val crop = loadCropInHand() + val heldItem = Minecraft.getMinecraft().thePlayer.heldItem + val crop = loadCropInHand(heldItem) if (cropInHand != crop) { cropInHand = crop - GardenToolChangeEvent().postAndCatch() + GardenToolChangeEvent(crop, heldItem).postAndCatch() } } @@ -40,9 +40,8 @@ class GardenAPI { } } - private fun loadCropInHand(): String? { - val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return null - if (readCounter(heldItem) == -1) return null + private fun loadCropInHand(heldItem: ItemStack?): String? { + if (heldItem == null) return null return getCropTypeFromItem(heldItem) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt index 756922f0a..d6ba45ebd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.TimeUtils +import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.* @@ -67,6 +68,7 @@ class GardenCropMilestoneDisplay { private var averageSpeedPerSecond = 0 private var countInLastSecond = 0 private val allCounters = mutableListOf() + var lastItemInHand: ItemStack? = null private fun resetSpeed() { lastSecondStart = 0 @@ -95,10 +97,12 @@ class GardenCropMilestoneDisplay { @SubscribeEvent fun onGardenToolChange(event: GardenToolChangeEvent) { - if (!isEnabled()) return + lastItemInHand = event.heldItem - resetSpeed() - update() + if (isEnabled()) { + resetSpeed() + update() + } } private fun update() { @@ -152,6 +156,13 @@ class GardenCropMilestoneDisplay { progressDisplay.add(Collections.singletonList("§7Progress to Tier $nextTier§8:")) progressDisplay.add(Collections.singletonList("§e$haveFormat§8/§e$needFormat")) + lastItemInHand?.let { + if (GardenAPI.readCounter(it) == -1) { + progressDisplay.add(Collections.singletonList("§cWarning: You need Cultivating!")) + return + } + } + if (averageSpeedPerSecond != 0) { GardenAPI.cropsPerSecond[it] = averageSpeedPerSecond val missing = need - have @@ -162,7 +173,7 @@ class GardenCropMilestoneDisplay { progressDisplay.add(Collections.singletonList("§7in §b$duration")) val format = LorenzUtils.formatInteger(averageSpeedPerSecond * 60) - progressDisplay.add(Collections.singletonList("§7Crops/minute§8: §e$format")) + progressDisplay.add(Collections.singletonList("§7Drops/minute§8: §e$format")) } if (needsInventory) { -- cgit