aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-10-11 19:01:42 +0200
committerGitHub <noreply@github.com>2024-10-11 19:01:42 +0200
commit9a2286ac3070e1ba0023445dc8243e618989e86e (patch)
tree6c4ad95a8df2ce6fff17e5ea96f8df09c4e5ea07 /src/main/java/at/hannibal2/skyhanni/utils
parent8c54be95700b224c2f93b549465dbe06bf3bbe86 (diff)
downloadskyhanni-9a2286ac3070e1ba0023445dc8243e618989e86e.tar.gz
skyhanni-9a2286ac3070e1ba0023445dc8243e618989e86e.tar.bz2
skyhanni-9a2286ac3070e1ba0023445dc8243e618989e86e.zip
Backend: LorenzVec up/down and drawLineToEye (#2056)
Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt32
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt9
5 files changed, 34 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
index 281b744d6..59799ff3d 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
@@ -63,7 +63,7 @@ object EntityUtils {
fun EntityLivingBase.getAllNameTagsInRadiusWith(
contains: String,
radius: Double = 3.0,
- ): List<EntityArmorStand> = getArmorStandsInRadius(getLorenzVec().add(y = 3), radius).filter {
+ ): List<EntityArmorStand> = getArmorStandsInRadius(getLorenzVec().up(3), radius).filter {
it.getNameAsString().contains(contains)
}
@@ -84,7 +84,7 @@ object EntityUtils {
inaccuracy: Double = 1.6,
debugWrongEntity: Boolean = false,
): List<EntityArmorStand> {
- val center = getLorenzVec().add(y = y)
+ val center = getLorenzVec().up(y)
return getArmorStandsInRadius(center, inaccuracy).filter {
val result = it.getNameAsString().contains(contains)
if (debugWrongEntity && !result) {
@@ -188,7 +188,7 @@ object EntityUtils {
if (Minecraft.getMinecraft().isCallingFromMinecraftThread) it else it.toMutableList()
}?.asSequence()?.filterNotNull() ?: emptySequence()
- fun Entity.canBeSeen(radius: Double = 150.0) = getLorenzVec().add(y = 0.5).canBeSeen(radius)
+ fun Entity.canBeSeen(radius: Double = 150.0) = getLorenzVec().up(0.5).canBeSeen(radius)
fun getEntityByID(entityId: Int) = Minecraft.getMinecraft()?.thePlayer?.entityWorld?.getEntityByID(entityId)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
index 34aa3f22f..d2394624c 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
@@ -35,7 +35,7 @@ object LocationUtils {
fun playerEyeLocation(): LorenzVec {
val player = Minecraft.getMinecraft().thePlayer
val vec = player.getLorenzVec()
- return vec.add(y = player.getEyeHeight().toDouble())
+ return vec.up(player.getEyeHeight().toDouble())
}
fun AxisAlignedBB.isInside(vec: LorenzVec) = isVecInside(vec.toVec3())
@@ -53,7 +53,7 @@ object LocationUtils {
fun LorenzVec.canBeSeen(yOffsetRange: IntRange, radius: Double = 150.0): Boolean =
yOffsetRange.any { offset ->
- this.add(y = offset).canBeSeen(radius)
+ up(offset).canBeSeen(radius)
}
fun AxisAlignedBB.minBox() = LorenzVec(minX, minY, minZ)
@@ -99,7 +99,7 @@ object LocationUtils {
fun AxisAlignedBB.getCenter() = getEdgeLengths() * 0.5 + minBox()
- fun AxisAlignedBB.getTopCenter() = getCenter().add(y = (maxY - minY) / 2)
+ fun AxisAlignedBB.getTopCenter() = getCenter().up((maxY - minY) / 2)
fun AxisAlignedBB.clampTo(other: AxisAlignedBB): AxisAlignedBB {
val minX = max(this.minX, other.minX)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
index 6769210ef..ee8473111 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
@@ -42,7 +42,7 @@ data class LorenzVec(
fun distance(x: Double, y: Double, z: Double): Double = distance(LorenzVec(x, y, z))
- fun distanceChebyshevIgnoreY(other: LorenzVec) = max(abs(this.x - other.x), abs(this.z - other.z))
+ fun distanceChebyshevIgnoreY(other: LorenzVec) = max(abs(x - other.x), abs(z - other.z))
fun distanceSq(other: LorenzVec): Double {
val dx = other.x - x
@@ -86,11 +86,11 @@ data class LorenzVec(
fun dotProduct(other: LorenzVec): Double = (x * other.x) + (y * other.y) + (z * other.z)
- fun angleAsCos(other: LorenzVec) = this.normalize().dotProduct(other.normalize())
+ fun angleAsCos(other: LorenzVec) = normalize().dotProduct(other.normalize())
- fun angleInRad(other: LorenzVec) = acos(this.angleAsCos(other))
+ fun angleInRad(other: LorenzVec) = acos(angleAsCos(other))
- fun angleInDeg(other: LorenzVec) = Math.toDegrees(this.angleInRad(other))
+ fun angleInDeg(other: LorenzVec) = Math.toDegrees(angleInRad(other))
@Deprecated("Use operator fun plus instead", ReplaceWith("this + other"))
fun add(other: LorenzVec) = LorenzVec(x + other.x, y + other.y, z + other.z)
@@ -125,7 +125,7 @@ data class LorenzVec(
fun toCleanString(separator: String = ", "): String = listOf(x, y, z).joinToString(separator)
fun lengthSquared(): Double = x * x + y * y + z * z
- fun length(): Double = sqrt(this.lengthSquared())
+ fun length(): Double = sqrt(lengthSquared())
fun isNormalized(tolerance: Double = 0.01) = (lengthSquared() - 1.0).absoluteValue < tolerance
@@ -165,13 +165,15 @@ data class LorenzVec(
return LorenzVec(x, y, z)
}
+ fun blockCenter() = roundLocationToBlock().add(0.5, 0.5, 0.5)
+
fun slope(other: LorenzVec, factor: Double) = this + (other - this).scale(factor)
// TODO better name. dont confuse with roundTo()
fun roundLocation(): LorenzVec {
- val x = if (this.x < 0) x.toInt() - 1 else x.toInt()
+ val x = if (x < 0) x.toInt() - 1 else x.toInt()
val y = y.toInt() - 1
- val z = if (this.z < 0) z.toInt() - 1 else z.toInt()
+ val z = if (z < 0) z.toInt() - 1 else z.toInt()
return LorenzVec(x, y, z)
}
@@ -186,14 +188,16 @@ data class LorenzVec(
fun axisAlignedTo(other: LorenzVec) = AxisAlignedBB(x, y, z, other.x, other.y, other.z)
- fun up(offset: Double): LorenzVec = copy(y = y + offset)
+ fun up(offset: Number = 1): LorenzVec = copy(y = y + offset.toDouble())
+
+ fun down(offset: Number = 1): LorenzVec = copy(y = y - offset.toDouble())
fun interpolate(other: LorenzVec, factor: Double): LorenzVec {
require(factor in 0.0..1.0) { "Percentage must be between 0 and 1: $factor" }
- val x = (1 - factor) * this.x + factor * other.x
- val y = (1 - factor) * this.y + factor * other.y
- val z = (1 - factor) * this.z + factor * other.z
+ val x = (1 - factor) * x + factor * other.x
+ val y = (1 - factor) * y + factor * other.y
+ val z = (1 - factor) * z + factor * other.z
return LorenzVec(x, y, z)
}
@@ -244,7 +248,7 @@ data class LorenzVec(
return LorenzVec(x, y, z)
}
- fun getBlockBelowPlayer() = LocationUtils.playerLocation().roundLocationToBlock().add(y = -1.0)
+ fun getBlockBelowPlayer() = LocationUtils.playerLocation().roundLocationToBlock().down()
val expandVector = LorenzVec(0.0020000000949949026, 0.0020000000949949026, 0.0020000000949949026)
}
@@ -268,6 +272,6 @@ fun Array<Double>.toLorenzVec(): LorenzVec {
fun RenderUtils.translate(vec: LorenzVec) = GlStateManager.translate(vec.x, vec.y, vec.z)
-fun AxisAlignedBB.expand(vec: LorenzVec): AxisAlignedBB = this.expand(vec.x, vec.y, vec.z)
+fun AxisAlignedBB.expand(vec: LorenzVec): AxisAlignedBB = expand(vec.x, vec.y, vec.z)
-fun AxisAlignedBB.expand(amount: Double): AxisAlignedBB = this.expand(amount, amount, amount)
+fun AxisAlignedBB.expand(amount: Double): AxisAlignedBB = expand(amount, amount, amount)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
index 4fccbed68..f6d52b7fc 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
@@ -122,7 +122,7 @@ class ParkourHelper(
if (outline) event.outlineTopFace(aabb, 2, Color.BLACK, depth)
}
if (SkyHanniMod.feature.dev.waypoint.showPlatformNumber && !isMovingPlatform) {
- event.drawString(location.offsetCenter().add(y = 1), "§a§l$index", seeThroughBlocks = true)
+ event.drawString(location.offsetCenter().up(1), "§a§l$index", seeThroughBlocks = true)
}
}
} catch (e: Throwable) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 39f251340..14241f314 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -1100,6 +1100,15 @@ object RenderUtils {
return exactLocation(player) + add
}
+ fun LorenzRenderWorldEvent.exactPlayerEyeLocation(player: Entity): LorenzVec {
+ val add = if (player.isSneaking) LorenzVec(0.0, 1.54, 0.0) else LorenzVec(0.0, 1.62, 0.0)
+ return exactLocation(player) + add
+ }
+
+ fun LorenzRenderWorldEvent.drawLineToEye(location: LorenzVec, color: Color, lineWidth: Int, depth: Boolean) {
+ draw3DLine(exactPlayerEyeLocation(), location, color, lineWidth, depth)
+ }
+
fun exactLocation(entity: Entity, partialTicks: Float): LorenzVec {
if (entity.isDead) return entity.getLorenzVec()
val x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks