diff options
author | Appability <appable@icloud.com> | 2022-11-14 11:38:54 -0800 |
---|---|---|
committer | Appability <appable@icloud.com> | 2022-11-14 11:38:54 -0800 |
commit | 60efa336225fccc2e470d45e4222cdf331b83643 (patch) | |
tree | 3f2733d46f5f441599478afea311b164fc559340 /src/main | |
parent | 7cdbe4dcbb8ae7e31dc9b881f347cd54662c845a (diff) | |
download | AmbientAddons-60efa336225fccc2e470d45e4222cdf331b83643.tar.gz AmbientAddons-60efa336225fccc2e470d45e4222cdf331b83643.tar.bz2 AmbientAddons-60efa336225fccc2e470d45e4222cdf331b83643.zip |
trapper alarm kinda
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt b/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt index f850a36..7311b7b 100644 --- a/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt +++ b/src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt @@ -17,6 +17,8 @@ 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 net.minecraftforge.fml.common.gameevent.TickEvent +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent import java.awt.Color import kotlin.math.ceil import kotlin.math.roundToInt @@ -25,19 +27,22 @@ object Trapper { private var color: Color? = null private val trapperRegex = Regex("^§e\\[NPC\\] Trevor The Trapper§f: §rYou can find your §(?<color>[0-9a-f])§l\\w+ §fanimal near the §(?<locationColor>[0-9a-f])(?<location>[\\w ]+)§f.§r$") - private val animals = - listOf( - EntityCow::class, - EntityPig::class, - EntitySheep::class, - EntityCow::class, - EntityChicken::class, - EntityRabbit::class, - EntityHorse::class - ) + private val animals = listOf( + EntityCow::class, + EntityPig::class, + EntitySheep::class, + EntityCow::class, + EntityChicken::class, + EntityRabbit::class, + EntityHorse::class + ) private val animalHp: List<Float?> = listOf(100F, 200F, 500F, 1000F, 1024F, 2048F) private var cooldownEndTime = 0L + private val cooldownTime: Double + get() = (cooldownEndTime - System.currentTimeMillis()) / 1000.0 + + private var ticks = 0 fun isTrapperAnimal(entity: Entity): Boolean = entity.ticksExisted >= 20 && (entity::class in animals) && animalHp.contains((entity as? EntityLiving)?.maxHealth) @@ -57,9 +62,9 @@ object Trapper { if (matchResult != null) { val colorCode = (matchResult.groups as? MatchNamedGroupCollection)?.get("color")?.value ?: return color = Color(mc.fontRendererObj.getColorCode(colorCode.single())) - } else if ( - event.message.formattedText.startsWith("§r§aKilling the animal rewarded you ") || - event.message.formattedText.startsWith("§r§aYour mob died randomly, you are rewarded ") + } else if (event.message.formattedText.startsWith("§r§aKilling the animal rewarded you ") || event.message.formattedText.startsWith( + "§r§aYour mob died randomly, you are rewarded " + ) ) { color = null } @@ -69,7 +74,7 @@ object Trapper { 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 diff = cooldownTime.takeIf { it >= 0 } ?: return val display = "§a${ceil(diff).roundToInt()}" val resolution = ScaledResolution(mc) val x = resolution.scaledWidth / 2 + 1 @@ -79,6 +84,15 @@ object Trapper { } @SubscribeEvent + fun onTick(event: ClientTickEvent) { + if (SBLocation.area != Area.FarmingIslands || config.trapperCooldown == 0 || event.phase != TickEvent.Phase.START) return + if (cooldownTime in -1.0..0.0 && ticks % 4 == 0 && color == null) { + mc.thePlayer.playSound("note.pling", 1f, 1f) + } + ticks++ + } + + @SubscribeEvent fun onRenderWorld(event: RenderWorldLastEvent) { if (SBLocation.area != Area.FarmingIslands || !config.trapperEsp) return mc.theWorld.loadedEntityList.forEach { @@ -89,12 +103,7 @@ object Trapper { val z = it.lastTickPosZ + (it.posZ - it.lastTickPosZ) * event.partialTicks - renderManager.viewerPosZ val entityHeight = it.entityBoundingBox.maxY - it.entityBoundingBox.minY EntityUtils.drawEntityBox( - it, - color!!, - outline = true, - fill = true, - partialTicks = event.partialTicks, - esp = true + it, color!!, outline = true, fill = true, partialTicks = event.partialTicks, esp = true ) EntityUtils.renderBeaconBeam(x - 0.5, y + entityHeight, z - 0.5, color!!, 1F, event.partialTicks, true) } |