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/events/FishingBobberCastEvent.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt24
5 files changed, 41 insertions, 32 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 78828fe8e..fb75e37b5 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -106,6 +106,7 @@ 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.ChumBucketHider
+import at.hannibal2.skyhanni.features.fishing.FishingAPI
import at.hannibal2.skyhanni.features.fishing.FishingBaitWarnings
import at.hannibal2.skyhanni.features.fishing.FishingHookDisplay
import at.hannibal2.skyhanni.features.fishing.FishingTimer
@@ -388,6 +389,7 @@ class SkyHanniMod {
loadModule(RiftAPI)
loadModule(SackAPI)
loadModule(BingoAPI)
+ loadModule(FishingAPI)
// features
loadModule(BazaarOrderHelper())
@@ -622,7 +624,7 @@ class SkyHanniMod {
loadModule(LockMouseLook)
loadModule(DungeonFinderFeatures())
loadModule(PabloHelper())
- loadModule(FishingBaitWarnings());
+ loadModule(FishingBaitWarnings())
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/events/FishingBobberCastEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/FishingBobberCastEvent.kt
new file mode 100644
index 000000000..01ea0222e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/FishingBobberCastEvent.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.events
+
+import net.minecraft.entity.projectile.EntityFishHook
+
+class FishingBobberCastEvent(val bobber: EntityFishHook) : LorenzEvent()
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 70bd0ea9b..550388893 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
@@ -1,16 +1,36 @@
package at.hannibal2.skyhanni.features.fishing
+import at.hannibal2.skyhanni.events.FishingBobberCastEvent
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import net.minecraft.client.Minecraft
+import net.minecraft.entity.projectile.EntityFishHook
import net.minecraft.init.Blocks
import net.minecraft.item.ItemStack
+import net.minecraftforge.event.entity.EntityJoinWorldEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object FishingAPI {
private val lavaBlocks = listOf(Blocks.lava, Blocks.flowing_lava)
private val waterBlocks = listOf(Blocks.water, Blocks.flowing_water)
+ var lastCastTime = SimpleTimeMark.farPast()
+
+ @SubscribeEvent
+ fun onJoinWorld(event: EntityJoinWorldEvent) {
+ if (!LorenzUtils.inSkyBlock || !hasFishingRodInHand()) return
+ val entity = event.entity ?: return
+ if (entity !is EntityFishHook) return
+ if (entity.angler != Minecraft.getMinecraft().thePlayer) return
+
+ lastCastTime = SimpleTimeMark.now()
+ FishingBobberCastEvent(entity).postAndCatch()
+ }
+
fun hasFishingRodInHand() = InventoryUtils.itemInHandId.asString().contains("ROD")
fun ItemStack.isBait(): Boolean {
@@ -21,4 +41,5 @@ object FishingAPI {
fun isLavaRod() = InventoryUtils.getItemInHand()?.getLore()?.any { it.contains("Lava Rod") } ?: false
fun getAllowedBlocks() = if (isLavaRod()) lavaBlocks else waterBlocks
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt
index 03e3e393b..8caf8cb20 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.fishing
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.FishingBobberCastEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.features.fishing.FishingAPI.isBait
@@ -8,15 +9,12 @@ import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt
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 net.minecraft.client.Minecraft
import net.minecraft.entity.item.EntityItem
import net.minecraft.entity.projectile.EntityFishHook
import net.minecraft.item.ItemStack
-import net.minecraftforge.event.entity.EntityJoinWorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
@@ -24,18 +22,11 @@ class FishingBaitWarnings {
private val config get() = SkyHanniMod.feature.fishing.fishingBaitWarnings
private var bobber: EntityFishHook? = null
private var lastBait: String? = null
- private var timeLastCast = SimpleTimeMark.farPast()
private var isUsingBait: Boolean = false
@SubscribeEvent
- fun onJoinWorld(event: EntityJoinWorldEvent) {
- if (!isEnabled()) return
- val entity = event.entity ?: return
- if (entity !is EntityFishHook) return
- if (entity.angler != Minecraft.getMinecraft().thePlayer) return
-
- bobber = entity
- timeLastCast = SimpleTimeMark.now()
+ fun onBobberThrow(event: FishingBobberCastEvent) {
+ bobber = event.bobber
isUsingBait = false
}
@@ -48,10 +39,10 @@ class FishingBaitWarnings {
return
}
if (!event.isMod(5)) return
- if (timeLastCast.passedSince() < 1.seconds) return
+ if (FishingAPI.lastCastTime.passedSince() < 1.seconds) return
val block = bobber.getLorenzVec().getBlockAt()
- if (block in FishingAPI.getAllowedBlocks()) return
+ if (block !in FishingAPI.getAllowedBlocks()) return
if (!isUsingBait && config.noBaitWarning) showNoBaitWarning()
reset()
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 c05ffcc80..be076222f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt
@@ -2,30 +2,30 @@ package at.hannibal2.skyhanni.features.fishing
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
+import at.hannibal2.skyhanni.events.FishingBobberCastEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
-import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
-import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.entity.item.EntityArmorStand
-import net.minecraft.entity.projectile.EntityFishHook
import net.minecraftforge.event.entity.EntityJoinWorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class FishingHookDisplay {
private val config get() = SkyHanniMod.feature.fishing.fishingHookDisplay
- private var bobber: EntityFishHook? = null
private var armorStand: EntityArmorStand? = null
private val potentionArmorStands = mutableListOf<EntityArmorStand>()
private val pattern = "§e§l(\\d+(\\.\\d+)?)".toPattern()
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
- bobber = null
- armorStand = null
- potentionArmorStands.clear()
+ reset()
+ }
+
+ @SubscribeEvent
+ fun onBobberThrow(event: FishingBobberCastEvent) {
+ reset()
}
@SubscribeEvent
@@ -38,16 +38,6 @@ class FishingHookDisplay {
armorStand = filter[0]
}
}
-
- if (event.isMod(5)) {
- val entities = EntityUtils.getEntities<EntityFishHook>()
- val foundBobber = entities.firstOrNull { it.angler is EntityPlayerSP }
- if (foundBobber != bobber) {
- bobber = foundBobber
- reset()
- }
- }
-
}
private fun reset() {