aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-10-28 00:15:55 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-10-28 00:15:55 +0200
commit20b1d741db61194c8dd43edb59d82e0c8a9cd3d1 (patch)
tree003e046602202411daedea3dcf56dbcb1f77c4be /src/main/java/at/hannibal2/skyhanni/utils
parent28918c18394210daa121d929d3bfbb48e22a2536 (diff)
downloadskyhanni-20b1d741db61194c8dd43edb59d82e0c8a9cd3d1.tar.gz
skyhanni-20b1d741db61194c8dd43edb59d82e0c8a9cd3d1.tar.bz2
skyhanni-20b1d741db61194c8dd43edb59d82e0c8a9cd3d1.zip
created and used Entity.canBeSeen and LorenzVec.canBeSeen
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt11
2 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
index f9e8ddb86..0e31c45bb 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture
+import at.hannibal2.skyhanni.utils.LocationUtils.canBeSeen
import at.hannibal2.skyhanni.utils.LocationUtils.distanceTo
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
import net.minecraft.block.state.IBlockState
@@ -152,4 +153,6 @@ object EntityUtils {
fun getAllEntities(): Sequence<Entity> = Minecraft.getMinecraft()?.theWorld?.loadedEntityList?.let {
if (Minecraft.getMinecraft().isCallingFromMinecraftThread) it else it.toMutableList()
}?.asSequence() ?: emptySequence()
-} \ No newline at end of file
+
+ fun Entity.canBeSeen(radius: Double = 150.0) = getLorenzVec().add(0.0, 0.5, 0.0).canBeSeen(radius)
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
index 99b95f734..fafb41c96 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
@@ -31,4 +31,13 @@ object LocationUtils {
fun AxisAlignedBB.isVecInside(vec: LorenzVec) = isVecInside(vec.toVec3())
fun AxisAlignedBB.isPlayerInside() = isVecInside(playerLocation())
-} \ No newline at end of file
+
+ fun LorenzVec.canBeSeen(radius: Double = 150.0): Boolean {
+ val a = playerEyeLocation()
+ val b = this
+ val noBlocks = canSee(a, b)
+ val notTooFar = a.distance(b) < radius
+ val inFov = true // TODO add Frustum "Frustum().isBoundingBoxInFrustum(entity.entityBoundingBox)"
+ return noBlocks && notTooFar && inFov
+ }
+}