diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt | 16 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/IsFishingDetection.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/fishing/FishingDetection.kt) | 13 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt | 1 |
5 files changed, 16 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index e95f05d5d..c51e29d03 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -134,9 +134,9 @@ import at.hannibal2.skyhanni.features.fame.CityProjectFeatures import at.hannibal2.skyhanni.features.fishing.ChumBucketHider import at.hannibal2.skyhanni.features.fishing.FishingAPI import at.hannibal2.skyhanni.features.fishing.FishingBaitWarnings -import at.hannibal2.skyhanni.features.fishing.FishingDetection import at.hannibal2.skyhanni.features.fishing.FishingHookDisplay import at.hannibal2.skyhanni.features.fishing.FishingTimer +import at.hannibal2.skyhanni.features.fishing.IsFishingDetection import at.hannibal2.skyhanni.features.fishing.SeaCreatureFeatures import at.hannibal2.skyhanni.features.fishing.SeaCreatureManager import at.hannibal2.skyhanni.features.fishing.SeaCreatureMessageShortener @@ -472,7 +472,7 @@ class SkyHanniMod { loadModule(SackAPI) loadModule(BingoAPI) loadModule(FishingAPI) - loadModule(FishingDetection) + loadModule(IsFishingDetection) loadModule(LorenzUtils) loadModule(NEUItems) 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 a3d3a1cb7..e3ac0c219 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.events.FishingBobberCastEvent +import at.hannibal2.skyhanni.events.ItemInHandChangeEvent import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.getFilletValue import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity @@ -27,10 +28,11 @@ object FishingAPI { private val waterBlocks = listOf(Blocks.water, Blocks.flowing_water) var lastCastTime = SimpleTimeMark.farPast() + var holdingRod = false @SubscribeEvent fun onJoinWorld(event: EntityJoinWorldEvent) { - if (!LorenzUtils.inSkyBlock || !hasFishingRodInHand()) return + if (!LorenzUtils.inSkyBlock || !holdingRod) return val entity = event.entity ?: return if (entity !is EntityFishHook) return if (entity.angler != Minecraft.getMinecraft().thePlayer) return @@ -39,15 +41,19 @@ object FishingAPI { FishingBobberCastEvent(entity).postAndCatch() } - fun hasFishingRodInHand() = InventoryUtils.itemInHandId.isFishingRod() - - fun NEUInternalName.isFishingRod() = contains("ROD") + private fun NEUInternalName.isFishingRod() = contains("ROD") fun ItemStack.isBait(): Boolean { val name = name ?: return false return stackSize == 1 && (name.removeColor().startsWith("Obfuscated") || name.endsWith(" Bait")) } + @SubscribeEvent + fun onItemInHandChange(event: ItemInHandChangeEvent) { + // TODO correct rod type per island water/lava + holdingRod = event.newItem.isFishingRod() + } + fun isLavaRod() = InventoryUtils.getItemInHand()?.getLore()?.any { it.contains("Lava Rod") } ?: false fun getAllowedBlocks() = if (isLavaRod()) lavaBlocks else waterBlocks @@ -62,7 +68,7 @@ object FishingAPI { return info?.getFilletValue(rarity) ?: 0 } - fun isFishing() = FishingDetection.isFishing + fun isFishing(checkRodInHand: Boolean = true) = IsFishingDetection.isFishing || (checkRodInHand && holdingRod) fun seaCreatureCount(entity: EntityArmorStand): Int { val name = entity.name diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt index 73fe5e23a..671ae0841 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt @@ -86,5 +86,5 @@ class FishingHookDisplay { return pattern.matcher(name).matches() } - fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && FishingAPI.hasFishingRodInHand() + fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && FishingAPI.holdingRod } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingDetection.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/IsFishingDetection.kt index bbd029100..1e3d73f5a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingDetection.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/IsFishingDetection.kt @@ -1,9 +1,7 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.events.FishingBobberCastEvent -import at.hannibal2.skyhanni.events.ItemInHandChangeEvent import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.features.fishing.FishingAPI.isFishingRod import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer @@ -15,10 +13,9 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds -object FishingDetection { +object IsFishingDetection { var isFishing = false - private var holdingRod = false private var lastRodCastLocation: LorenzVec? = null private var lastRodCastTime = SimpleTimeMark.farPast() private var lastInAreaTime = SimpleTimeMark.farPast() @@ -27,12 +24,6 @@ object FishingDetection { private var lastSeaCreatureKillAreaTime = SimpleTimeMark.farPast() @SubscribeEvent - fun onItemInHandChange(event: ItemInHandChangeEvent) { - // TODO correct rod type per island water/lava - holdingRod = event.newItem.isFishingRod() - } - - @SubscribeEvent fun onBobberThrow(event: FishingBobberCastEvent) { lastRodCastLocation = LocationUtils.playerLocation() lastRodCastTime = SimpleTimeMark.now() @@ -59,8 +50,6 @@ object FishingDetection { } private fun testIsFishing(): Boolean { - if (holdingRod) return true - if (inRodCastArea()) return true if (lastRodCastTime.passedSince() < 5.seconds) return true diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt index 1c5e6f7b6..6b7e7cea9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt @@ -221,6 +221,7 @@ object FishingProfitTracker { } private fun maybeAddItem(internalName: NEUInternalName, amount: Int) { + if (!FishingAPI.isFishing(checkRodInHand = false)) return if (!isAllowedItem(internalName)) { ChatUtils.debug("Ignored non-fishing item pickup: $internalName'") return |