diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-10-03 14:14:39 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-10-03 14:14:39 +0200 |
commit | 08f15c1fc11e8c3142c859fdff0c3e80afcab0fe (patch) | |
tree | a5e5522618d1dfd6bdf9b63eef63fd21c7dcb3c3 /src/main/java/at/hannibal2 | |
parent | 075b7c517bb0a4f0c06156d351baba37b9317957 (diff) | |
download | skyhanni-08f15c1fc11e8c3142c859fdff0c3e80afcab0fe.tar.gz skyhanni-08f15c1fc11e8c3142c859fdff0c3e80afcab0fe.tar.bz2 skyhanni-08f15c1fc11e8c3142c859fdff0c3e80afcab0fe.zip |
Warps to the nearest warp point on the hub, if closer to the next burrow.
Diffstat (limited to 'src/main/java/at/hannibal2')
8 files changed, 195 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 351fb628e..21b5bc1d7 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.features.commands.WikiCommand; import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager; import at.hannibal2.skyhanni.features.dungeon.*; import at.hannibal2.skyhanni.features.end.VoidlingExtremistColor; +import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper; import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowHelper; import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowParticleFinder; import at.hannibal2.skyhanni.features.event.diana.SoopyGuessBurrow; @@ -161,6 +162,7 @@ public class SkyHanniMod { registerEvent(new SoopyGuessBurrow()); registerEvent(new GriffinBurrowHelper()); registerEvent(new GriffinBurrowParticleFinder()); + registerEvent(new BurrowWarpHelper()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index d9711dd77..5d94d850c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.ConfigEditor import at.hannibal2.skyhanni.config.commands.SimpleCommand.ProcessCommandRunnable import at.hannibal2.skyhanni.config.core.GuiScreenElementWrapper import at.hannibal2.skyhanni.features.MarkedPlayerManager +import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import at.hannibal2.skyhanni.test.LorenzTest import at.hannibal2.skyhanni.test.command.CopyItemCommand import at.hannibal2.skyhanni.test.command.CopyNearbyEntitiesCommand @@ -35,6 +36,7 @@ object Commands { registerCommand("shmarkplayer") { MarkedPlayerManager.command(it) } registerCommand("togglepacketlog") { LorenzTest.togglePacketLog() } registerCommand("shreloadlisteners") { LorenzTest.reloadListeners() } + registerCommand("shresetburrowwarps") { BurrowWarpHelper.resetDisabledWarps() } } private fun registerCommand(name: String, function: (Array<String>) -> Unit) { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java b/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java index 55ec5d387..f783358c1 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Diana.java @@ -31,4 +31,10 @@ public class Diana { @ConfigAccordionId(id = 0) public boolean burrowSmoothTransition = false; + @Expose + @ConfigOption(name = "Nearest Warp", desc = "Warps to the nearest warp point on the hub, if closer to the next burrow.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean burrowNearestWarp = false; + } diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt index 26e08356b..2e4d13da6 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt @@ -35,7 +35,7 @@ class EntityMovementData { val distance = newLocation.distance(oldLocation) if (distance > 0.01) { entityLocation[entity] = newLocation - EntityMoveEvent(entity, oldLocation, newLocation).postAndCatch() + EntityMoveEvent(entity, oldLocation, newLocation, distance).postAndCatch() } } } diff --git a/src/main/java/at/hannibal2/skyhanni/events/EntityMoveEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/EntityMoveEvent.kt index 405938195..30b440d87 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/EntityMoveEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/EntityMoveEvent.kt @@ -3,4 +3,4 @@ package at.hannibal2.skyhanni.events import at.hannibal2.skyhanni.utils.LorenzVec import net.minecraft.entity.Entity -class EntityMoveEvent(val entity: Entity, val oldLocation: LorenzVec, val newLocation: LorenzVec) : LorenzEvent()
\ No newline at end of file +class EntityMoveEvent(val entity: Entity, val oldLocation: LorenzVec, val newLocation: LorenzVec, val distance: Double) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt new file mode 100644 index 000000000..742fdfe36 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt @@ -0,0 +1,114 @@ +package at.hannibal2.skyhanni.features.event.diana + +import at.hannibal2.skyhanni.data.HypixelData +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.LocationUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.OSUtils.isActive +import net.minecraft.client.Minecraft +import net.minecraft.client.settings.KeyBinding +import net.minecraftforge.fml.client.registry.ClientRegistry +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import org.lwjgl.input.Keyboard + +class BurrowWarpHelper { + + private val keyBinding = KeyBinding( + "Nearest Burrow Warp", + Keyboard.KEY_X, + "SkyHanni" + ) + + private var lastWarpTime = 0L + private var lastWarp: WarpPoint? = null + + init { + ClientRegistry.registerKeyBinding(keyBinding) + } + + @SubscribeEvent + fun onClientTick(event: TickEvent.ClientTickEvent) { + if (keyBinding.isActive()) { + currentWarp?.let { + if (System.currentTimeMillis() > lastWarpTime + 5_000) { + val thePlayer = Minecraft.getMinecraft().thePlayer + thePlayer.sendChatMessage("/warp " + currentWarp?.name) + lastWarp = currentWarp + lastWarpTime = System.currentTimeMillis() + } + } + } + } + + @SubscribeEvent + fun onStatusBar(event: LorenzChatEvent) { + if (!HypixelData.skyblock) return + + if (event.message == "§cYou haven't unlocked this fast travel destination!") { + val time = System.currentTimeMillis() - lastWarpTime + if (time < 1_000) { + lastWarp?.let { + it.enabled = false + LorenzUtils.chat( + "§e[SkyHanni] Detected not having access to warp point §b${it.displayName}§e!\n" + + "§e[SkyHanni] Use §c/shresetburrowwarps §eonce you have activated this travel scroll." + ) + lastWarp = null + currentWarp = null + } + } + } + + } + + companion object { + var currentWarp: WarpPoint? = null + + fun shouldUseWarps(target: LorenzVec) { + val playerLocation = LocationUtils.playerLocation() + val warpPoint = getNearestWarpPoint(target) + + val playerDistance = playerLocation.distance(target) + val warpDistance = warpPoint.distance(target) +// println(" ") +// println("shouldUseWarps") +// println("playerDistance: ${playerDistance.round(1)}") +// println("warpDistance: ${warpDistance.round(1)}") + val difference = playerDistance - warpDistance + currentWarp = if (difference > 10) { + warpPoint + } else { + null + } + } + + private fun getNearestWarpPoint(location: LorenzVec): WarpPoint { + val map = WarpPoint.values().filter { it.enabled }.map { it to it.distance(location) } + return map.toList().sortedBy { (_, value) -> value }.first().first + } + + fun resetDisabledWarps() { + WarpPoint.values().forEach { it.enabled = true } + LorenzUtils.chat("§e[SkyHanni] Reset disabled burrow warps.") + } + } + + enum class WarpPoint( + val displayName: String, + private val location: LorenzVec, + private val extraBlocks: Int, + var enabled: Boolean = true, + ) { + HUB("Hub", LorenzVec(-3, 70, -70), 2), + CASTLE("Castle", LorenzVec(-250, 130, 45), 10), + + // CRYPT("Crypt", LorenzVec(-190, 74, -88), 25), + DA("Dark Auction", LorenzVec(91, 74, 173), 2), + MUSEUM("Museum", LorenzVec(-75, 76, 81), 2), + ; + + fun distance(other: LorenzVec): Double = other.distance(location) + extraBlocks + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt index 493398836..f8a9d5c7f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.features.event.diana import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.EntityMovementData import at.hannibal2.skyhanni.events.BurrowDetectEvent import at.hannibal2.skyhanni.events.BurrowDugEvent +import at.hannibal2.skyhanni.events.EntityMoveEvent import at.hannibal2.skyhanni.events.SoopyGuessBurrowEvent import at.hannibal2.skyhanni.test.GriffinUtils.draw3DLine import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt @@ -11,6 +13,7 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.drawColor import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import net.minecraft.client.Minecraft import net.minecraft.init.Blocks import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.event.world.WorldEvent @@ -22,14 +25,21 @@ class GriffinBurrowHelper { private var particleBurrows = mutableMapOf<LorenzVec, BurrowType>() private var animationLocation: LorenzVec? = null private var lastDug: LorenzVec? = null + private var teleportedLocation: LorenzVec? = null + private var lastGuessTime = 0L @SubscribeEvent fun onSoopyGuessBurrow(event: SoopyGuessBurrowEvent) { - if (SkyHanniMod.feature.diana.burrowsSoopyGuess) { - if (guessLocation == null) { - animationLocation = lastDug ?: LocationUtils.playerLocation() - } + EntityMovementData.addToTrack(Minecraft.getMinecraft().thePlayer) + if (System.currentTimeMillis() > lastGuessTime + 1_000) { + animationLocation = LocationUtils.playerLocation().add(-0.5, -1.0, -0.5) } + lastGuessTime = System.currentTimeMillis() + + if (SkyHanniMod.feature.diana.burrowNearestWarp) { + BurrowWarpHelper.shouldUseWarps(event.guessLocation) + } + guessLocation = event.guessLocation if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { checkRemoveGuess(false) @@ -38,6 +48,7 @@ class GriffinBurrowHelper { @SubscribeEvent fun onBurrowDetect(event: BurrowDetectEvent) { + EntityMovementData.addToTrack(Minecraft.getMinecraft().thePlayer) particleBurrows[event.burrowLocation] = event.type if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { @@ -68,6 +79,15 @@ class GriffinBurrowHelper { } @SubscribeEvent + fun onPlayerMove(event: EntityMoveEvent) { + if (event.distance > 10) { + if (event.entity == Minecraft.getMinecraft().thePlayer) { + teleportedLocation = event.newLocation + } + } + } + + @SubscribeEvent fun onWorldChange(event: WorldEvent.Load) { guessLocation = null animationLocation = null @@ -112,12 +132,7 @@ class GriffinBurrowHelper { } } - if (SkyHanniMod.feature.diana.burrowSmoothTransition) { - animationLocation?.let { - event.drawColor(it, LorenzColor.WHITE) - animationLocation = moveAnimation(it, event) - } - } + sendTip(event) if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { for (burrow in particleBurrows) { @@ -132,9 +147,43 @@ class GriffinBurrowHelper { } } + private fun sendTip(event: RenderWorldLastEvent) { + teleportedLocation?.let { + teleportedLocation = null + + if (BurrowWarpHelper.currentWarp != null) { + BurrowWarpHelper.currentWarp = null + if (SkyHanniMod.feature.diana.burrowNearestWarp) { + animationLocation = it + return + } + } + } + + if (SkyHanniMod.feature.diana.burrowNearestWarp) { + BurrowWarpHelper.currentWarp?.let { warp -> + animationLocation?.let { + event.drawColor(it.add(0.0, 1.0, 0.0), LorenzColor.AQUA) + if (it.distance(LocationUtils.playerLocation()) < 10) { + event.drawString(it.add(0.5, 1.5, 0.5), "§bWarp to " + warp.displayName, true) + } + return + } + } + } + if (SkyHanniMod.feature.diana.burrowSmoothTransition) { + animationLocation?.let { + event.drawColor(it, LorenzColor.WHITE) + animationLocation = moveAnimation(it, event) + } + } + } + private fun moveAnimation(animation: LorenzVec, event: RenderWorldLastEvent): LorenzVec? { val list = mutableListOf<LorenzVec>() - list.addAll(particleBurrows.keys) + if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { + list.addAll(particleBurrows.keys) + } guessLocation?.let { val loc = findBlock(it) if (loc.y > 200) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt index cb87ff2cd..80b0031e9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt @@ -1,5 +1,7 @@ package at.hannibal2.skyhanni.utils +import net.minecraft.client.settings.KeyBinding +import org.lwjgl.input.Keyboard import java.awt.Desktop import java.awt.Toolkit import java.awt.datatransfer.StringSelection @@ -24,4 +26,11 @@ object OSUtils { fun copyToClipboard(text: String) { Toolkit.getDefaultToolkit().systemClipboard.setContents(StringSelection(text), null) } + + fun KeyBinding.isActive() : Boolean { + if (!Keyboard.isCreated()) return false + if (Keyboard.isKeyDown(this.keyCode)) return true + if (this.isKeyDown || this.isPressed) return true + return false + } }
\ No newline at end of file |