From 20b1d741db61194c8dd43edb59d82e0c8a9cd3d1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 28 Oct 2023 00:15:55 +0200 Subject: created and used Entity.canBeSeen and LorenzVec.canBeSeen --- src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt | 5 ++++- src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') 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 = 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 + } +} -- cgit