aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/FishingConfig.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/fishing/BaitChangeWarning.kt)62
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt5
5 files changed, 42 insertions, 39 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 02d196cc3..78828fe8e 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -105,8 +105,8 @@ import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasureT
import at.hannibal2.skyhanni.features.event.spook.TheGreatSpook
import at.hannibal2.skyhanni.features.fame.AccountUpgradeReminder
import at.hannibal2.skyhanni.features.fame.CityProjectFeatures
-import at.hannibal2.skyhanni.features.fishing.BaitChangeWarning
import at.hannibal2.skyhanni.features.fishing.ChumBucketHider
+import at.hannibal2.skyhanni.features.fishing.FishingBaitWarnings
import at.hannibal2.skyhanni.features.fishing.FishingHookDisplay
import at.hannibal2.skyhanni.features.fishing.FishingTimer
import at.hannibal2.skyhanni.features.fishing.SeaCreatureFeatures
@@ -622,7 +622,7 @@ class SkyHanniMod {
loadModule(LockMouseLook)
loadModule(DungeonFinderFeatures())
loadModule(PabloHelper())
- loadModule(BaitChangeWarning());
+ loadModule(FishingBaitWarnings());
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/FishingConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/FishingConfig.java
index 235b606f8..11a21d083 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/FishingConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/FishingConfig.java
@@ -236,7 +236,7 @@ public class FishingConfig {
@Expose
@ConfigOption(name = "Bait Warnings", desc = "")
@Accordion
- public FishingBaitWarningsConfig fishingBaitWarning = new FishingBaitWarningsConfig();
+ public FishingBaitWarningsConfig fishingBaitWarnings = new FishingBaitWarningsConfig();
public static class FishingBaitWarningsConfig {
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
index bfe3cb5bb..ccadaec94 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
@@ -1,7 +1,15 @@
package at.hannibal2.skyhanni.features.fishing
import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import net.minecraft.item.ItemStack
object FishingAPI {
fun hasFishingRodInHand() = InventoryUtils.itemInHandId.asString().contains("ROD")
+
+ fun ItemStack.isBait(): Boolean {
+ val name = name ?: return false
+ return stackSize == 1 && (name.removeColor().startsWith("Obfuscated") || name.endsWith(" Bait"))
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/BaitChangeWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt
index 3f0487639..3be74ea8a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/BaitChangeWarning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt
@@ -3,13 +3,14 @@ package at.hannibal2.skyhanni.features.fishing
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.features.fishing.FishingAPI.isBait
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.getLorenzVec
-import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.client.Minecraft
import net.minecraft.entity.item.EntityItem
import net.minecraft.entity.projectile.EntityFishHook
@@ -17,70 +18,65 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
-class BaitChangeWarning {
- private val config get() = SkyHanniMod.feature.fishing.fishingBaitWarning
+class FishingBaitWarnings {
+ private val config get() = SkyHanniMod.feature.fishing.fishingBaitWarnings
private var bobber: EntityFishHook? = null
private var lastBait: String? = null
- private var timeLastCast: Long = 0L
+ private var timeLastCast = SimpleTimeMark.farPast()
private var isUsingBait: Boolean = false
@SubscribeEvent
- fun onJoinWorld(event: EntityJoinWorldEvent){
- if(!isEnabled()) return
+ fun onJoinWorld(event: EntityJoinWorldEvent) {
+ if (!isEnabled()) return
val entity = event.entity ?: return
- if(entity !is EntityFishHook) return
- if(entity.angler != Minecraft.getMinecraft().thePlayer) return
+ if (entity !is EntityFishHook) return
+ if (entity.angler != Minecraft.getMinecraft().thePlayer) return
- bobber = entity;
- timeLastCast = System.currentTimeMillis()
+ bobber = entity
+ timeLastCast = SimpleTimeMark.now()
isUsingBait = false
}
@SubscribeEvent
- fun onTick(event: LorenzTickEvent){
- if(!isEnabled() || bobber == null) return
+ fun onTick(event: LorenzTickEvent) {
+ if (!isEnabled() || bobber == null) return
//Is there a way to get event sent time to be more accurate?
- if(System.currentTimeMillis() - timeLastCast < 1000L) return
+ if (timeLastCast.passedSince() < 1.seconds) return
- if(!isUsingBait && config.noBaitWarning) showNoBaitWarning()
+ if (!isUsingBait && config.noBaitWarning) showNoBaitWarning()
reset()
}
- fun reset(){
+ fun reset() {
bobber = null
isUsingBait = false
}
@SubscribeEvent
- fun onRenderWorld(event: LorenzRenderWorldEvent){
- if(!isEnabled() || !config.baitChangeWarning) return
- if(bobber == null) return
- for(entityItem in EntityUtils.getEntitiesNearby<EntityItem>(bobber!!.getLorenzVec(), 1.5)){
+ fun onRenderWorld(event: LorenzRenderWorldEvent) {
+ if (!isEnabled() || !config.baitChangeWarning) return
+ val bobber = bobber ?: return
+ for (entityItem in EntityUtils.getEntitiesNearby<EntityItem>(bobber.getLorenzVec(), 1.5)) {
val itemStack = entityItem.entityItem
- var name = itemStack.name ?: continue
- name = name.removeColor()
-
- if((!name.endsWith(" Bait") && !name.startsWith("Obfuscated"))
- || itemStack.stackSize != 1) continue
+ if (!itemStack.isBait()) continue
+ val name = itemStack.name?.removeColor() ?: continue
isUsingBait = true
- if(lastBait == null){
- lastBait = name.removeColor()
- continue
+ lastBait?.let {
+ if (name == it) continue
+ showBaitChangeWarning(it, name)
}
- if(name.removeColor() == lastBait) continue
- showBaitChangeWarning(lastBait!!, name.removeColor())
- lastBait = name.removeColor()
+ lastBait = name
}
}
- fun showBaitChangeWarning(before: String, after: String){
+ private fun showBaitChangeWarning(before: String, after: String) {
SoundUtils.playClickSound()
LorenzUtils.sendTitle("§eBait changed!", 2.seconds)
- LorenzUtils.chat("§e" + before + " -> " + after)
+ LorenzUtils.chat("§e[SkyHanni] Fishing Bait change detected: $before -> $after")
}
- fun showNoBaitWarning(){
+ private fun showNoBaitWarning() {
SoundUtils.playErrorSound()
LorenzUtils.sendTitle("§cNo bait is used!", 2.seconds)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt
index 99fcca5e4..a64d3da77 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.fishing
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.features.fishing.FishingAPI.isBait
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.name
@@ -55,9 +56,7 @@ class ShowFishingItemName {
if (name.removeColor() == "Stone") continue
val size = itemStack.stackSize
- val isBait = (name.removeColor().startsWith("Obfuscated")
- || name.endsWith(" Bait")) && size == 1
- val prefix = if (!isBait) {
+ val prefix = if (!itemStack.isBait()) {
"§a§l+"
} else {
if (!config.showBaits) continue