diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-05-09 06:53:45 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 22:53:45 +0200 |
commit | 55c2614cb69551363607cbdb7f42c38eccd3d38e (patch) | |
tree | 3e77f3ddca2a3a271d5a1f9d06f324111ab3d7ec /src/main/java/at/hannibal2/skyhanni/features/misc | |
parent | 7a493ca560b74f1fe995fbe351c79eabaa90d432 (diff) | |
download | skyhanni-55c2614cb69551363607cbdb7f42c38eccd3d38e.tar.gz skyhanni-55c2614cb69551363607cbdb7f42c38eccd3d38e.tar.bz2 skyhanni-55c2614cb69551363607cbdb7f42c38eccd3d38e.zip |
Trevor features and solver (#92)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
3 files changed, 334 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/CurrentMobArea.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/CurrentMobArea.kt new file mode 100644 index 000000000..fcc083bc7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/CurrentMobArea.kt @@ -0,0 +1,14 @@ +package at.hannibal2.skyhanni.features.misc.trevor + +import at.hannibal2.skyhanni.utils.LorenzVec + +enum class CurrentMobArea(val location: String, val coordinates: LorenzVec) { + OASIS("Oasis", LorenzVec(126.0, 77.0, -456.0)), + GORGE("Mushroom Gorge", LorenzVec(300.0, 80.0, -509.0)), + OVERGROWN("Overgrown Mushroom Cave", LorenzVec(242.0, 60.0, -389.0)), + SETTLEMENT("Desert Settlement", LorenzVec(184.0, 86.0, -384.0)), + GLOWING("Glowing Mushroom Cave", LorenzVec(199.0, 50.0, -512.0)), + MOUNTAIN("Desert Mountain", LorenzVec(255.0, 148.0, -518.0)), + FOUND("Mob Location", LorenzVec(0.0, 0.0, 0.0)), + NONE(" ", LorenzVec(0.0, 0.0, 0.0)), +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt new file mode 100644 index 000000000..69a5a0548 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt @@ -0,0 +1,234 @@ +package at.hannibal2.skyhanni.features.misc.trevor + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.ScoreboardData +import at.hannibal2.skyhanni.data.TitleUtils +import at.hannibal2.skyhanni.events.CheckRenderEntityEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.withAlpha +import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer +import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText +import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.gui.inventory.GuiEditSign +import net.minecraft.client.gui.inventory.GuiInventory +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import org.lwjgl.input.Keyboard +import kotlin.concurrent.fixedRateTimer + + +class TrevorFeatures { + private val trapperPattern = + "\\[NPC] Trevor: You can find your (?<rarity>.*) animal near the (?<location>.*).".toPattern() + private val talbotPatternAbove = + "The target is around (?<height>.*) blocks above, at a (?<angle>.*) degrees angle!".toPattern() + private val talbotPatternBelow = + "The target is around (?<height>.*) blocks below, at a (?<angle>.*) degrees angle!".toPattern() + private val locationPattern = "Zone: (?<zone>.*)".toPattern() + private var timeUntilNextReady = 0 + private var trapperReady: Boolean = true + private var currentStatus = TrapperStatus.READY + private var currentLabel = "§2Ready" + private var trapperID: Int = 56 + private var backupTrapperID: Int = 17 + private var timeLastWarped: Long = 0 + + private val config get() = SkyHanniMod.feature.misc.trevorTheTrapper + + init { + fixedRateTimer(name = "skyhanni-update-trapper", period = 1000L) { + if (onFarmingIsland()) { + updateTrapper() + TrevorSolver.findMob() + } + } + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!onFarmingIsland()) return + if (event.message == "§aReturn to the Trapper soon to get a new animal to hunt!") { + TrevorSolver.resetLocation() + if (config.trapperMobDiedMessage) { + TitleUtils.sendTitle("§2Mob Died ", 5_000) + SoundUtils.playBeepSound() + } + trapperReady = true + TrevorSolver.mobLocation = CurrentMobArea.NONE + if (timeUntilNextReady <= 0) { + currentStatus = TrapperStatus.READY + currentLabel = "§2Ready" + } else { + currentStatus = TrapperStatus.WAITING + currentLabel = "§3$timeUntilNextReady seconds left" + } + } + + var matcher = trapperPattern.matcher(event.message.removeColor()) + if (matcher.matches()) { + timeUntilNextReady = 61 + currentStatus = TrapperStatus.ACTIVE + currentLabel = "§cActive Quest" + trapperReady = false + } + + matcher = talbotPatternAbove.matcher(event.message.removeColor()) + if (matcher.matches()) { + val height = matcher.group("height").toInt() + TrevorSolver.findMobHeight(height, true) + } + + matcher = talbotPatternBelow.matcher(event.message.removeColor()) + if (matcher.matches()) { + val height = matcher.group("height").toInt() + TrevorSolver.findMobHeight(height, false) + } + } + + private fun updateTrapper() { + timeUntilNextReady -= 1 + if (trapperReady && timeUntilNextReady > 0) { + currentStatus = TrapperStatus.WAITING + currentLabel = "§3$timeUntilNextReady seconds left" + } + + if (timeUntilNextReady <= 0 && trapperReady) { + if (timeUntilNextReady == 0) { + TitleUtils.sendTitle("§2Trapper Ready ", 3_000) + SoundUtils.playBeepSound() + } + currentStatus = TrapperStatus.READY + currentLabel = "§2Ready" + } + + var found = false + var active = false + val previousLocation = TrevorSolver.mobLocation + for (line in TabListData.getTabList()) { + val formattedLine = line.removeColor().drop(1) + if (formattedLine.startsWith("Time Left: ")) { + trapperReady = false + currentStatus = TrapperStatus.ACTIVE + currentLabel = "§cActive Quest" + active = true + } + + CurrentMobArea.values().firstOrNull { it.location == formattedLine }?.let { + TrevorSolver.mobLocation = it + found = true + } + locationPattern.matchMatcher(formattedLine) { + val zone = group("zone") + TrevorSolver.mobLocation = CurrentMobArea.values().firstOrNull { it.location == zone } + ?: CurrentMobArea.NONE + found = true + } + } + if (!found) TrevorSolver.mobLocation = CurrentMobArea.NONE + if (!active) { + trapperReady = true + } + if (TrevorSolver.mobCoordinates != LorenzVec(0.0, 0.0, 0.0) && active) { + TrevorSolver.mobLocation = previousLocation + } + } + + @SubscribeEvent + fun onRenderWorld(event: RenderWorldLastEvent) { + if (!onFarmingIsland()) return + var entityTrapper = Minecraft.getMinecraft().theWorld.getEntityByID(trapperID) + if (entityTrapper !is EntityLivingBase) entityTrapper = + Minecraft.getMinecraft().theWorld.getEntityByID(backupTrapperID) + if (entityTrapper is EntityLivingBase) { + if (config.trapperTalkCooldown) { + RenderLivingEntityHelper.setEntityColor( + entityTrapper, + currentStatus.color + ) { config.trapperTalkCooldown } + entityTrapper.getLorenzVec().let { + if (it.distanceToPlayer() < 15) { + event.drawString(it.add(0.0, 2.23, 0.0), currentLabel) + } + } + } + } + + if (config.trapperSolver) { + var location = TrevorSolver.mobLocation.coordinates + if (TrevorSolver.mobLocation == CurrentMobArea.NONE) return + if (TrevorSolver.averageHeight != 0.0) { + location = LorenzVec(location.x, TrevorSolver.averageHeight, location.z) + } + if (TrevorSolver.mobLocation == CurrentMobArea.FOUND) { + location = TrevorSolver.mobCoordinates + event.drawWaypointFilled(location.add(0, -2, 0), LorenzColor.GREEN.toColor(), true, true) + event.drawDynamicText(location.add(0, 2, 0), TrevorSolver.mobLocation.location, 1.5) + } else { + event.drawWaypointFilled(location, LorenzColor.GOLD.toColor(), true, true) + event.drawDynamicText(location.add(0, 1, 0), TrevorSolver.mobLocation.location, 1.5) + } + } + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!config.warpToTrapper) return + if (!Keyboard.getEventKeyState()) return + val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() + if (config.keyBindWarpTrapper != key) return + + if (!LorenzUtils.inSkyBlock || LorenzUtils.inDungeons || LorenzUtils.inKuudraFight) return + + Minecraft.getMinecraft().currentScreen?.let { + if (it !is GuiInventory && it !is GuiChest && it !is GuiEditSign) return + } + if (NEUItems.neuHasFocus()) return + + if (System.currentTimeMillis() - timeLastWarped < 3000) return + LorenzUtils.sendCommandToServer("warp trapper") + timeLastWarped = System.currentTimeMillis() + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + fun onCheckRender(event: CheckRenderEntityEvent<*>) { + if (!inTrapperDen()) return + if (!config.trapperTalkCooldown) return + val entity = event.entity + if (entity is EntityArmorStand) { + if (entity.name == "§e§lCLICK") { + event.isCanceled = true + } + } + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + TrevorSolver.resetLocation() + currentStatus = TrapperStatus.READY + currentLabel = "§2Ready" + } + + enum class TrapperStatus(val color: Int) { + READY(LorenzColor.DARK_GREEN.toColor().withAlpha(75)), + WAITING(LorenzColor.DARK_AQUA.toColor().withAlpha(75)), + ACTIVE(LorenzColor.DARK_RED.toColor().withAlpha(75)), + } + + private fun onFarmingIsland() = + LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.THE_FARMING_ISLANDS + + private fun inTrapperDen() = ScoreboardData.sidebarLinesFormatted.contains(" §7⏣ §bTrapper's Den") +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorSolver.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorSolver.kt new file mode 100644 index 000000000..3d6c91417 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorSolver.kt @@ -0,0 +1,86 @@ +package at.hannibal2.skyhanni.features.misc.trevor + +import at.hannibal2.skyhanni.utils.LocationUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.toLorenzVec +import net.minecraft.client.Minecraft +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand + +object TrevorSolver { + private val animalNames = arrayOf("Cow", "Horse", "Sheep", "Pig", "Rabbit", "Chicken") + + private var maxHeight: Double = 0.0 + private var minHeight: Double = 0.0 + private var foundID = -1 + var mobCoordinates = LorenzVec(0.0, 0.0, 0.0) + var mobLocation = CurrentMobArea.NONE + var averageHeight = (minHeight + maxHeight) / 2 + + fun findMobHeight(height: Int, above: Boolean) { + val playerPosition = LocationUtils.playerLocation().round(2) + val mobHeight = if (above) playerPosition.y + height else playerPosition.y - height + if (maxHeight == 0.0) { + + maxHeight = mobHeight + 2.5 + minHeight = mobHeight - 2.5 + } else { + if (mobHeight + 2.5 in minHeight..maxHeight) { + maxHeight = mobHeight + 2.5 + } else if (mobHeight - 2.5 in minHeight..maxHeight) { + minHeight = mobHeight - 2.5 + } else { + maxHeight = mobHeight + 2.5 + minHeight = mobHeight - 2.5 + } + } + averageHeight = (minHeight + maxHeight) / 2 + } + + fun findMob() { + val world = Minecraft.getMinecraft().theWorld ?: return + for (entity in world.getLoadedEntityList()) { + val name = entity.name + // looking at 2 diff entities rn + val entityHealth = if (entity is EntityLivingBase) entity.baseMaxHealth else 0 + if (intArrayOf(100, 500, 1000, 5000, 10000).any { it == entityHealth }) { + if (animalNames.any { it == name }) { + if (LocationUtils.canSee(LocationUtils.playerLocation(), entity.position.toLorenzVec())) { + if (entity.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer)) return + + if (foundID == entity.entityId) { + mobLocation = CurrentMobArea.FOUND + mobCoordinates = entity.position.toLorenzVec() + } else { + foundID = entity.entityId + } + return + } + } + } + + if (entity is EntityArmorStand) { + for (animal in animalNames) { + if (name.contains(animal)) { + if (foundID == entity.entityId) { + mobLocation = CurrentMobArea.FOUND + mobCoordinates = entity.position.toLorenzVec() + } else { + foundID = entity.entityId + } + } + } + } + } + } + + fun resetLocation() { + maxHeight = 0.0 + minHeight = 0.0 + averageHeight = (minHeight + maxHeight) / 2 + foundID = -1 + mobCoordinates = LorenzVec(0.0, 0.0, 0.0) + } + +} |