From f290d5285cb92dd427726cdc203156187690f068 Mon Sep 17 00:00:00 2001 From: Appability Date: Sun, 13 Nov 2022 23:32:10 -0800 Subject: fix trapper, add cd --- .../com/ambientaddons/features/misc/Trapper.kt | 44 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'src/main/kotlin/com/ambientaddons/features/misc') diff --git a/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt b/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt index d3269c2..ce468eb 100644 --- a/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt +++ b/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt @@ -2,37 +2,56 @@ package com.ambientaddons.features.misc import AmbientAddons.Companion.config import AmbientAddons.Companion.mc +import com.ambientaddons.features.display.WitherShieldOverlay +import com.ambientaddons.utils.Alignment import com.ambientaddons.utils.Area import com.ambientaddons.utils.SBLocation +import com.ambientaddons.utils.dungeon.TextStyle import com.ambientaddons.utils.render.EntityUtils +import com.ambientaddons.utils.render.OverlayUtils +import net.minecraft.client.gui.ScaledResolution import net.minecraft.entity.Entity import net.minecraft.entity.EntityLiving import net.minecraft.entity.passive.* import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color +import kotlin.math.ceil +import kotlin.math.roundToInt object Trapper { private var color: Color? = null private val trapperRegex = Regex("^§e\\[NPC\\] Trevor The Trapper§f: §rYou can find your §(?[0-9a-f])§l\\w+ §fanimal near the §(?[0-9a-f])(?[\\w ]+)§f.§r$") private val animals = - listOf(EntityCow::class, EntityPig::class, EntitySheep::class, EntityCow::class, EntityChicken::class, EntityRabbit::class) + listOf( + EntityCow::class, + EntityPig::class, + EntitySheep::class, + EntityCow::class, + EntityChicken::class, + EntityRabbit::class, + EntityHorse::class + ) private val animalHp: List = listOf(100F, 200F, 500F, 1000F, 1024F, 2048F) + private var cooldownEndTime = 0L + fun isTrapperAnimal(entity: Entity): Boolean = - entity.ticksExisted >= 10 && (entity::class in animals) && animalHp.contains((entity as? EntityLiving)?.maxHealth) + entity.ticksExisted >= 20 && (entity::class in animals) && animalHp.contains((entity as? EntityLiving)?.maxHealth) @SubscribeEvent fun onChat(event: ClientChatReceivedEvent) { if (SBLocation.area != Area.FarmingIslands || event.message == null || event.type == 2.toByte()) return - if (config.autoTrapper) { - val siblings = event.message.siblings ?: return - if (siblings.getOrNull(0)?.unformattedText == "Accept the trapper's task to hunt the animal?") { - val command = siblings.getOrNull(3)?.chatStyle?.chatClickEvent?.value ?: return + val siblings = event.message.siblings ?: return + if (siblings.getOrNull(0)?.unformattedText == "Accept the trapper's task to hunt the animal?") { + val command = siblings.getOrNull(3)?.chatStyle?.chatClickEvent?.value ?: return + if (config.autoTrapper) { mc.thePlayer.sendChatMessage(command) } + cooldownEndTime = System.currentTimeMillis() + 30000 } val matchResult = event.message.formattedText.let { trapperRegex.find(it) } if (matchResult != null) { @@ -46,6 +65,19 @@ object Trapper { } } + @SubscribeEvent + fun onRenderOverlay(event: RenderGameOverlayEvent) { + if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return + if (SBLocation.area != Area.FarmingIslands || config.trapperCooldown == 0) return + val diff = ((cooldownEndTime - System.currentTimeMillis()) / 1000.0).takeIf { it >= 0 } ?: return + val display = "§a${ceil(diff).roundToInt()}" + val resolution = ScaledResolution(mc) + val x = resolution.scaledWidth / 2 + 1 + val y = resolution.scaledHeight / 2 - 20 + val style = TextStyle.fromInt(config.trapperCooldown - 1) ?: return + OverlayUtils.drawString(x, y, display, style, Alignment.Center) + } + @SubscribeEvent fun onRenderWorld(event: RenderWorldLastEvent) { if (SBLocation.area != Area.FarmingIslands || !config.trapperEsp) return -- cgit