aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-01-17 21:45:05 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-01-17 21:45:05 +0100
commitbc48465ffb9fcac97a66f96fcefbbaa252b3df17 (patch)
treecb23f6ec68d01e0be05e736432229d547b87f356 /src/main/java/at/hannibal2/skyhanni/features
parent48a554fa076cc4bf2c6facefbf301088571d8a7f (diff)
downloadSkyHanni-bc48465ffb9fcac97a66f96fcefbbaa252b3df17.tar.gz
SkyHanni-bc48465ffb9fcac97a66f96fcefbbaa252b3df17.tar.bz2
SkyHanni-bc48465ffb9fcac97a66f96fcefbbaa252b3df17.zip
Added barn timer.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt
new file mode 100644
index 000000000..1567c52a3
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt
@@ -0,0 +1,95 @@
+package at.hannibal2.skyhanni.features.fishing
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.utils.LocationUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.StringUtils
+import net.minecraft.client.Minecraft
+import net.minecraft.entity.item.EntityArmorStand
+import net.minecraftforge.client.event.RenderGameOverlayEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+
+class BarnFishingTimer {
+
+ private val barnLocation = LorenzVec(108, 89, -252)
+
+ private var tick = 0
+ private var rightLocation = false
+ private var mobsCount = 0
+ private var startTime = 0L
+
+ @SubscribeEvent
+ fun onTick(event: TickEvent.ClientTickEvent) {
+ if (event.phase != TickEvent.Phase.START) return
+
+ if (!LorenzUtils.inSkyBlock) return
+ if (!SkyHanniMod.feature.fishing.barnTimer) return
+
+ tick++
+
+ if (tick % 60 == 0) {
+ checkIsland()
+ }
+// if (tick % 20 == 0) {
+ if (tick % 5 == 0) {
+ checkMobs()
+ }
+ }
+
+ private fun checkMobs() {
+ val newCounter = countMobs()
+
+ if (mobsCount == 0) {
+ if (newCounter > 0) {
+ startTimer()
+ }
+ }
+ mobsCount = newCounter
+
+ if (newCounter == 0) {
+ startTime = 0
+ }
+ }
+
+ private fun countMobs(): Int {
+ val counter = Minecraft.getMinecraft().theWorld.loadedEntityList
+ .filterIsInstance<EntityArmorStand>()
+ .map { it.name }
+ // .count { it.startsWith("§8[§7Lv") && it.endsWith("§c❤") }
+ .count { it.endsWith("§c❤") }
+ return counter
+ }
+
+ private fun startTimer() {
+ startTime = System.currentTimeMillis()
+ }
+
+ private fun checkIsland() {
+ if (LorenzUtils.skyBlockIsland == IslandType.THE_FARMING_ISLANDS) {
+ rightLocation = false
+ return
+ }
+
+ rightLocation = LocationUtils.playerLocation().distance(barnLocation) < 50
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: RenderGameOverlayEvent.Post) {
+ if (event.type != RenderGameOverlayEvent.ElementType.ALL) return
+ if (!LorenzUtils.inSkyBlock) return
+ if (!SkyHanniMod.feature.fishing.barnTimer) return
+ if (!rightLocation) return
+
+ if (mobsCount == 0) return
+
+ val duration = System.currentTimeMillis() - startTime
+ val format = StringUtils.formatDuration(duration / 1000, decimalFormat = true)
+ val text = "§e$format §8(§e$mobsCount §bsea creatures§8)"
+
+ SkyHanniMod.feature.fishing.barnTimerPos.renderString(text)
+ }
+} \ No newline at end of file