diff options
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/features')
-rw-r--r-- | src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt | 5 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/features/misc/Trapper.kt | 44 |
2 files changed, 41 insertions, 8 deletions
diff --git a/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt b/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt index f1cd74f..d2790b4 100644 --- a/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt +++ b/src/main/kotlin/com/ambientaddons/features/dungeon/AutoBuyChest.kt @@ -37,10 +37,11 @@ object AutoBuyChest { fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { if (SBLocation.area != Area.Dungeon || rewardChest == null) return if (event.slotId == BUY_SLOT_INDEX) { - hasOpenedChest = true - if (rewardChest == RewardChest.Wood) { + if (rewardChest == RewardChest.Wood && hasOpenedChest) { UChat.chat("§cBlocked purchase! You already opened a chest this run.".withModPrefix()) event.isCanceled = true + } else { + hasOpenedChest = true } } else if (event.slotId == KISMET_SLOT_INDEX) { if (config.blockLowReroll && rewardChest != RewardChest.Bedrock && (rewardChest != RewardChest.Obsidian || SBLocation.dungeonFloor.toString() != "M4")) { 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 §(?<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) + 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 + 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) { @@ -47,6 +66,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 mc.theWorld.loadedEntityList.forEach { |