Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ package at.hannibal2.skyhanni.config.commands.brigadier.arguments

import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RegexUtils.findMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.mojang.brigadier.LiteralMessage
import com.mojang.brigadier.StringReader
import com.mojang.brigadier.arguments.ArgumentType
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType
import net.minecraft.commands.arguments.coordinates.Vec3Argument
import net.minecraft.world.phys.Vec3

sealed class LorenzVecArgumentType : ArgumentType<LorenzVec> {
/**
* Fabric-compatible alternative to [Vec3Argument] that does not depend on server state.
*/
sealed class Vec3ArgumentType : ArgumentType<Vec3> {

protected abstract fun toVec(x: kotlin.Double, y: kotlin.Double, z: kotlin.Double): LorenzVec

override fun parse(reader: StringReader): LorenzVec {
override fun parse(reader: StringReader): Vec3 {
val input = if (reader.canRead() && reader.peek() == '"') reader.readQuotedString()
else consumeMatch(reader)

return parseCoords(input)
}

Expand All @@ -33,48 +36,44 @@ sealed class LorenzVecArgumentType : ArgumentType<LorenzVec> {
throw invalidCoordinates.createWithContext(reader)
}

private fun parseCoords(input: String): LorenzVec {
private fun parseCoords(input: String): Vec3 {
val playerPos = LocationUtils.playerLocation()
for (pattern in patterns) {
pattern.matchMatcher(input) {
val x = if (group("x") == "~") playerPos.x else group("x").toDouble()
val y = if (group("y") == "~") playerPos.y else group("y").toDouble()
val z = if (group("z") == "~") playerPos.z else group("z").toDouble()
return toVec(x, y, z)
return Vec3(x, y, z)
}
}
throw invalidCoordinates.create()
}


data object Int : LorenzVecArgumentType() {
override fun toVec(x: kotlin.Double, y: kotlin.Double, z: kotlin.Double) =
LorenzVec(x.toInt(), y.toInt(), z.toInt())

override fun getExamples(): Collection<String> = listOf("1 2 3", "-4 0 5", "~ 64 ~", "1:2:3", "LorenzVec(1, 2, 3)")
data object Int : Vec3ArgumentType() {
override fun getExamples(): Collection<String> =
listOf("1 2 3", "-4 0 5", "~ 64 ~", "1:2:3", "Vec3(1, 2, 3)")
}

data object Double : LorenzVecArgumentType() {
override fun toVec(x: kotlin.Double, y: kotlin.Double, z: kotlin.Double) = LorenzVec(x, y, z)

data object Double : Vec3ArgumentType() {
override fun getExamples(): Collection<String> =
listOf("1.0 2.5 -3", "0.0 0.0 0.0", "-1.7 ~ ~", "-78.8:68.0:-28.7", "LorenzVec(-91.7, 70.0, 29.3)")
listOf("1.0 2.5 -3", "0.0 0.0 0.0", "-1.7 ~ ~", "-78.8:68.0:-28.7", "Vec3(-91.7, 70.0, 29.3)")
}

@SkyHanniModule
companion object {

private val patternGroup = RepoPattern.group("commands.brigadier.arguments.lorenzvec")
private val patternGroup = RepoPattern.group("commands.brigadier.arguments.vec3")

/**
* REGEX-TEST: LorenzVec(-91.7, 70.0, 29.3)
* REGEX-TEST: LorenzVec(1, 2, 3)
* REGEX-TEST: LorenzVec(0.0, 0.0, 0.0)
* REGEX-TEST: LorenzVec(-78.8, 68.0, -28.7)
* REGEX-TEST: Vec3(-91.7, 70.0, 29.3)
* REGEX-TEST: Vec3(1, 2, 3)
* REGEX-TEST: Vec3(0.0, 0.0, 0.0)
* REGEX-TEST: Vec3(-78.8, 68.0, -28.7)
*/
private val lorenzVecPattern by patternGroup.pattern(
"lorenz",
"""LorenzVec\((?<x>-?\d+(?:\.\d+)?),\s*(?<y>-?\d+(?:\.\d+)?),\s*(?<z>-?\d+(?:\.\d+)?)\)""",
private val vec3Pattern by patternGroup.pattern(
"vec3",
"""Vec3\((?<x>-?\d+(?:\.\d+)?),\s*(?<y>-?\d+(?:\.\d+)?),\s*(?<z>-?\d+(?:\.\d+)?)\)""",
)

/**
Expand All @@ -101,14 +100,15 @@ sealed class LorenzVecArgumentType : ArgumentType<LorenzVec> {
"""(?<x>~|-?\d+(?:\.\d+)?)\s+(?<y>~|-?\d+(?:\.\d+)?)\s+(?<z>~|-?\d+(?:\.\d+)?)""",
)

private val patterns = listOf(lorenzVecPattern, colonPattern, spacePattern)
private val patterns = listOf(vec3Pattern, colonPattern, spacePattern)

private val invalidCoordinates = SimpleCommandExceptionType(LiteralMessage("Invalid coordinates"))
private val invalidCoordinates =
SimpleCommandExceptionType(LiteralMessage("Invalid coordinates"))

/** Only accepts integers as input */
fun int(): LorenzVecArgumentType = Int
fun int(): Vec3ArgumentType = Int

/** Accepts any number as input */
fun double(): LorenzVecArgumentType = Double
fun double(): Vec3ArgumentType = Double
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.config.commands.brigadier.BrigadierArguments
import at.hannibal2.skyhanni.config.commands.brigadier.BrigadierUtils
import at.hannibal2.skyhanni.config.commands.brigadier.arguments.LorenzVecArgumentType
import at.hannibal2.skyhanni.config.commands.brigadier.arguments.Vec3ArgumentType
import at.hannibal2.skyhanni.data.IslandGraphs
import at.hannibal2.skyhanni.data.IslandGraphs.pathFind
import at.hannibal2.skyhanni.data.model.graph.GraphNode
Expand All @@ -15,12 +15,14 @@ import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.GraphUtils
import at.hannibal2.skyhanni.utils.NumberUtil.roundTo
import at.hannibal2.skyhanni.utils.SkyBlockUtils
import at.hannibal2.skyhanni.utils.VectorUtils.toLocalFormat
import at.hannibal2.skyhanni.utils.chat.TextHelper
import at.hannibal2.skyhanni.utils.chat.TextHelper.asComponent
import at.hannibal2.skyhanni.utils.chat.TextHelper.onClick
import at.hannibal2.skyhanni.utils.chat.TextHelper.send
import at.hannibal2.skyhanni.utils.collection.CollectionUtils.sorted
import at.hannibal2.skyhanni.utils.compat.hover
import at.hannibal2.skyhanni.utils.toLorenzVec

@SkyHanniModule
object NavigationHelper {
Expand Down Expand Up @@ -129,8 +131,8 @@ object NavigationHelper {
event.registerBrigadier("shnavigate") {
description = "Using path finder to go to locations"
aliases = listOf("shnav")
argCallback("coords", LorenzVecArgumentType.double()) { location ->
pathFind(location.add(-1, -1, -1), "Custom Goal", condition = { true })
argCallback("coords", Vec3ArgumentType.double()) { location ->
pathFind(location.add(-1.0).toLorenzVec(), "Custom Goal", condition = { true })
ChatUtils.chat("Started Navigating to custom goal at §f${location.toLocalFormat()}", messageId = messageId)
}
argCallback("search", BrigadierArguments.greedyString(), BrigadierUtils.dynamicSuggestionProvider { getNames() }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import at.hannibal2.skyhanni.test.graph.GraphEditor
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.LorenzVec.Companion.toLorenzVec
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.ParkourHelper
import at.hannibal2.skyhanni.utils.PlayerUtils
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockUtils
import at.hannibal2.skyhanni.utils.render.WorldRenderUtils.drawFilledBoundingBox
import at.hannibal2.skyhanni.utils.render.WorldRenderUtils.expandBlock
import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.client.Minecraft
import kotlin.time.Duration.Companion.milliseconds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.config.commands.brigadier.arguments.LorenzVecArgumentType
import at.hannibal2.skyhanni.config.commands.brigadier.arguments.Vec3ArgumentType
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.data.HypixelData
import at.hannibal2.skyhanni.data.IslandGraphs
Expand Down Expand Up @@ -47,7 +47,6 @@ import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NeuInternalName
import at.hannibal2.skyhanni.utils.NeuItems.getItemStack
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.roundTo
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
Expand All @@ -64,6 +63,7 @@ import at.hannibal2.skyhanni.utils.render.WorldRenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.addLine
import at.hannibal2.skyhanni.utils.system.PlatformUtils
import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.client.gui.components.debug.DebugScreenDisplayer
import net.minecraft.client.gui.components.debug.DebugScreenEntries
import net.minecraft.client.gui.components.debug.DebugScreenEntry
Expand Down Expand Up @@ -565,11 +565,11 @@ object SkyHanniDebugsAndTests {
event.registerBrigadier("shtestwaypoint") {
description = "Set a waypoint on that location"
category = CommandCategory.DEVELOPER_TEST
arg("waypoint", LorenzVecArgumentType.double()) { vec ->
arg("waypoint", Vec3ArgumentType.double()) { vec ->
literalCallback("pathfind") {
waypoint(getArg(vec), true)
waypoint(getArg(vec).toLorenzVec(), true)
}
callback { waypoint(getArg(vec)) }
callback { waypoint(getArg(vec).toLorenzVec()) }

}
simpleCallback { waypoint() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import at.hannibal2.skyhanni.test.graph.GraphEditor.isEnabled
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.LorenzVec.Companion.toLorenzVec
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.coroutines.CoroutineConfig
import at.hannibal2.skyhanni.utils.toLorenzVec

@SkyHanniModule
object GraphParkour {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.utils.compat.MinecraftCompat
import net.minecraft.core.Direction
import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.atan2
Expand Down Expand Up @@ -337,15 +338,15 @@ object LocationUtils {
return location
}

fun AABB.calculateEdges(): Set<Pair<LorenzVec, LorenzVec>> {
val bottomLeftFront = LorenzVec(minX, minY, minZ)
val bottomLeftBack = LorenzVec(minX, minY, maxZ)
val topLeftFront = LorenzVec(minX, maxY, minZ)
val topLeftBack = LorenzVec(minX, maxY, maxZ)
val bottomRightFront = LorenzVec(maxX, minY, minZ)
val bottomRightBack = LorenzVec(maxX, minY, maxZ)
val topRightFront = LorenzVec(maxX, maxY, minZ)
val topRightBack = LorenzVec(maxX, maxY, maxZ)
fun AABB.calculateEdges(): Set<Pair<Vec3, Vec3>> {
val bottomLeftFront = Vec3(minX, minY, minZ)
val bottomLeftBack = Vec3(minX, minY, maxZ)
val topLeftFront = Vec3(minX, maxY, minZ)
val topLeftBack = Vec3(minX, maxY, maxZ)
val bottomRightFront = Vec3(maxX, minY, minZ)
val bottomRightBack = Vec3(maxX, minY, maxZ)
val topRightFront = Vec3(maxX, maxY, minZ)
val topRightBack = Vec3(maxX, maxY, maxZ)

return setOf(
// Bottom face
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@file:Suppress("Deprecation")

package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.utils.LocationUtils.calculateEdges
import at.hannibal2.skyhanni.utils.NumberUtil.roundTo
import at.hannibal2.skyhanni.utils.VectorUtils.edges
import com.google.gson.annotations.Expose
import net.minecraft.core.BlockPos
import net.minecraft.core.Rotations
Expand All @@ -22,13 +24,14 @@ import kotlin.math.round
import kotlin.math.sin
import kotlin.math.sqrt

@Suppress("TooManyFunctions", "MemberVisibilityCanBePrivate")
@Deprecated("Use Vec3 and VectorUtils instead.", ReplaceWith("Vec3(this)"))
@Suppress("TooManyFunctions")
data class LorenzVec(
val x: Double,
val y: Double,
val z: Double,
) {
val edges by lazy { boundingToOffset(1.0, 1.0, 1.0).inflate(0.0001, 0.0001, 0.0001).calculateEdges() }
val edges: Set<Pair<LorenzVec, LorenzVec>> by lazy { toVec3().edges.toLorenzVecPairs() }

constructor() : this(0.0, 0.0, 0.0)

Expand Down Expand Up @@ -279,16 +282,16 @@ data class LorenzVec(
return LorenzVec(x, y, z)
}

fun List<Double>.toLorenzVec(): LorenzVec {
if (size != 3) error("Can not transform a list of size $size to LorenzVec")

return LorenzVec(this[0], this[1], this[2])
}

val expandVector = LorenzVec(0.0020000000949949026, 0.0020000000949949026, 0.0020000000949949026)
}
}

fun List<Double>.toLorenzVec(): LorenzVec {
if (size != 3) error("Can not transform a list of size $size to LorenzVec")

return LorenzVec(this[0], this[1], this[2])
}

fun BlockPos.toLorenzVec(): LorenzVec = LorenzVec(x, y, z)

fun Entity.getLorenzVec(): LorenzVec = position().toLorenzVec()
Expand Down Expand Up @@ -330,3 +333,6 @@ fun Array<Double>.toLorenzVec(): LorenzVec {
fun AABB.expand(vec: LorenzVec): AABB = inflate(vec.x, vec.y, vec.z)

fun AABB.expand(amount: Double): AABB = inflate(amount, amount, amount)

fun Set<Pair<Vec3, Vec3>>.toLorenzVecPairs(): Set<Pair<LorenzVec, LorenzVec>> =
mapTo(mutableSetOf()) { (a, b) -> a.toLorenzVec() to b.toLorenzVec() }
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.utils.LorenzVec.Companion.toLorenzVec
import kotlin.math.pow

class PolynomialFitter(private val degree: Int) {
Expand Down
Loading
Loading