diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-06 03:32:24 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-06 03:32:24 +0100 |
commit | cc9d2e1b3a285a21d9c85884a7741439f3a90e31 (patch) | |
tree | dc80cf269a10793372abef9172f272077f4afac1 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 97d8742e1e14385ddec929a35eb0b77180c501c6 (diff) | |
download | skyhanni-cc9d2e1b3a285a21d9c85884a7741439f3a90e31.tar.gz skyhanni-cc9d2e1b3a285a21d9c85884a7741439f3a90e31.tar.bz2 skyhanni-cc9d2e1b3a285a21d9c85884a7741439f3a90e31.zip |
Added Chicken head Timer
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/ChickenHeadTimer.kt | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ChickenHeadTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ChickenHeadTimer.kt new file mode 100644 index 000000000..d9e68a1e3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ChickenHeadTimer.kt @@ -0,0 +1,65 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.TimeUtils +import net.minecraft.client.Minecraft +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +class ChickenHeadTimer { + + private var tick = 0 + private var hasChickenHead = false + private var lastTime = 0L + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + if (tick++ % 5 != 0) return + + val itemStack = Minecraft.getMinecraft().thePlayer.inventory.armorInventory[3] + val name = itemStack?.name ?: "" + hasChickenHead = name.contains("Chicken Head") + } + + @SubscribeEvent + fun onWorldLoad(event: WorldEvent.Load) { + lastTime = System.currentTimeMillis() + } + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!isEnabled()) return + if (!hasChickenHead) return + if (event.message == "§aYou laid an egg!") { + lastTime = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + if (!hasChickenHead) return + + val sinceLastTime = System.currentTimeMillis() - lastTime + val cooldown = 20_000 + val remainingTime = cooldown - sinceLastTime + + val displayText = if (remainingTime < 0) { + "Chicken Head Timer: §aNow" + } else { + val formatDuration = TimeUtils.formatDuration(remainingTime) + "Chicken Head Timer: §b$formatDuration" + } + + SkyHanniMod.feature.misc.chickenHeadTimerPosition.renderString(displayText) + } + + fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.misc.chickenHeadTimerDisplay +}
\ No newline at end of file |