aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt22
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCustomKeybinds.kt38
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt6
5 files changed, 46 insertions, 40 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt
index 3d88710fe..b0bf8aa4e 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt
@@ -2,4 +2,6 @@ package at.hannibal2.skyhanni.events
import net.minecraft.item.ItemStack
-class GardenToolChangeEvent(val crop: String?, val heldItem: ItemStack?) : LorenzEvent() \ No newline at end of file
+class GardenToolChangeEvent(val crop: String?, val heldItem: ItemStack?) : LorenzEvent() {
+ val isRealCrop by lazy {crop != "Daedalus Axe"}
+} \ 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 4e40740f9..d3cf87954 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
@@ -4,11 +4,13 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
+import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraft.client.Minecraft
import net.minecraft.item.ItemStack
+import net.minecraft.network.play.client.C09PacketHeldItemChange
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
@@ -17,14 +19,29 @@ class GardenAPI {
var tick = 0
@SubscribeEvent
+ fun onSendPacket(event: PacketEvent.SendEvent) {
+ val packet = event.packet
+ if (packet !is C09PacketHeldItemChange) return
+
+ val heldItem = Minecraft.getMinecraft().thePlayer.heldItem
+ val crop = loadCropInHand(heldItem)
+ if (cropInHand != crop) {
+ cropInHand = crop
+ GardenToolChangeEvent(crop, heldItem).postAndCatch()
+ }
+ }
+
+ @SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
if (event.phase != TickEvent.Phase.START) return
if (!inGarden()) return
- if (tick++ % 5 != 0) return
+ if (tick++ % 10 != 0) return
val heldItem = Minecraft.getMinecraft().thePlayer.heldItem
val crop = loadCropInHand(heldItem)
if (cropInHand != crop) {
+ // We ignore random hypixel moments
+ Minecraft.getMinecraft().currentScreen ?: return
cropInHand = crop
GardenToolChangeEvent(crop, heldItem).postAndCatch()
}
@@ -42,7 +59,7 @@ class GardenAPI {
private fun loadCropInHand(heldItem: ItemStack?): String? {
if (heldItem == null) return null
- return getCropTypeFromItem(heldItem)
+ return getCropTypeFromItem(heldItem, true)
}
companion object {
@@ -96,6 +113,5 @@ class GardenAPI {
}
return cropsPerSecond[itemName]
}
-
}
} \ No newline at end of file
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 505a54ec3..156f3dd59 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
@@ -14,12 +14,12 @@ import java.util.*
class GardenCropMilestoneDisplay {
private val progressDisplay = mutableListOf<List<Any>>()
- private var needsInventory = false
private val cultivatingData = mutableMapOf<String, Int>()
private val config get() = SkyHanniMod.feature.garden
-
private val bestCropTime = GardenBestCropTime()
+ private var needsInventory = false
+
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
if (!isEnabled()) return
@@ -55,7 +55,7 @@ class GardenCropMilestoneDisplay {
val diff = counter - old
GardenCropMilestones.cropCounter[crop] = GardenCropMilestones.cropCounter[crop]!! + diff
EliteFarmingWeight.addCrop(crop, diff)
- if (GardenAPI.cropInHand == crop) {
+ if (currentCrop == crop) {
calculateSpeed(diff)
update()
}
@@ -68,7 +68,8 @@ class GardenCropMilestoneDisplay {
private var averageSpeedPerSecond = 0
private var countInLastSecond = 0
private val allCounters = mutableListOf<Int>()
- var lastItemInHand: ItemStack? = null
+ private var lastItemInHand: ItemStack? = null
+ private var currentCrop: String? = null
private fun resetSpeed() {
lastSecondStart = 0
@@ -97,7 +98,8 @@ class GardenCropMilestoneDisplay {
@SubscribeEvent
fun onGardenToolChange(event: GardenToolChangeEvent) {
- lastItemInHand = event.heldItem
+ lastItemInHand = if (event.isRealCrop) event.heldItem else null
+ currentCrop = if (event.isRealCrop) event.crop else null
if (isEnabled()) {
resetSpeed()
@@ -108,7 +110,7 @@ class GardenCropMilestoneDisplay {
private fun update() {
progressDisplay.clear()
bestCropTime.display.clear()
- GardenAPI.cropInHand?.let {
+ currentCrop?.let {
val crops = GardenCropMilestones.cropCounter[it]
if (crops == null) {
println("cropCounter is null for '$it'")
@@ -121,7 +123,7 @@ class GardenCropMilestoneDisplay {
}
}
if (config.cropMilestoneBestAlwaysOn) {
- if (GardenAPI.cropInHand == null) {
+ if (currentCrop == null) {
bestCropTime.drawBestDisplay(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 8ec5319d5..b0c6aed8c 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,12 @@ 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 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,20 +29,12 @@ class GardenCustomKeybinds {
Runtime.getRuntime().addShutdownHook(Thread { reset() })
}
- private var tick = 0
private var itemInHand = ""
@SubscribeEvent
- 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()
- }
+ fun onGardenToolChange(event: GardenToolChangeEvent) {
+ itemInHand = event.crop ?: ""
+ update()
}
private fun update() {
@@ -53,11 +45,6 @@ class GardenCustomKeybinds {
}
}
- private fun loadItemInHand(): String {
- val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return ""
- return GardenAPI.getCropTypeFromItem(heldItem, true) ?: ""
- }
-
@SubscribeEvent
fun onWorldChange(event: WorldEvent.Load) {
reset()
@@ -88,16 +75,13 @@ class GardenCustomKeybinds {
}
private fun disableAlreadyExistingKeybinds(newKeyCode: Int, alreadyBoundedKeys: MutableList<Int>) {
- if (newKeyCode != 0) {
- for (keyBinding in mcSettings.keyBindings) {
- if (keyBinding.keyCode == newKeyCode) {
- if (!alreadyBoundedKeys.contains(keyBinding.keyCodeDefault)) {
- keyBinding.unpressKeyIfDown()
- cache[keyBinding] = keyBinding.keyCode
- keyBinding.keyCode = 0
- }
- }
- }
+ if (newKeyCode == 0) return
+ for (keyBinding in mcSettings.keyBindings) {
+ if (keyBinding.keyCode != newKeyCode) continue
+ if (alreadyBoundedKeys.contains(keyBinding.keyCodeDefault)) continue
+ keyBinding.unpressKeyIfDown()
+ cache[keyBinding] = keyBinding.keyCode
+ keyBinding.keyCode = 0
}
}
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 bbffd92f3..26e0e5876 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
@@ -17,6 +17,7 @@ class GardenOptimalSpeed {
private var optimalSpeed = -1
private val currentSpeedPattern = Pattern.compile(" Speed: §r§f✦(.*)")
private var lastWarnTime = 0L
+ private var cropInHand: String? = null
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
@@ -30,8 +31,9 @@ class GardenOptimalSpeed {
@SubscribeEvent
fun onGardenToolChange(event: GardenToolChangeEvent) {
+ cropInHand = if (event.isRealCrop) event.crop else null
if (isEnabled()) {
- optimalSpeed = GardenAPI.cropInHand.let { if (it != null) speedForCrop(it) else -1 }
+ optimalSpeed = cropInHand.let { if (it != null) speedForCrop(it) else -1 }
}
}
@@ -64,7 +66,7 @@ class GardenOptimalSpeed {
if (System.currentTimeMillis() > lastWarnTime + 20_000) {
lastWarnTime = System.currentTimeMillis()
SendTitleHelper.sendTitle("§cWrong speed!", 3_000)
- GardenAPI.cropInHand?.let {
+ cropInHand?.let {
LorenzUtils.chat("§e[SkyHanni] Wrong speed for $it: §f$currentSpeed §e(§f$optimalSpeed §eis optimal)")
}
}