Posted March 10, 20241 yr Is there a method which checks to see if an entity can be seen? For example, if an entity is in the camera's view frustum and is not behind a wall or object return true.
March 14, 20241 yr I don't think there's a simple entity.canBeSee() function per say, but you have some options. You could do what the Enderman class does here EnderMan.class boolean isLookingAtMe(Player p_32535_) { ItemStack itemstack = (ItemStack)p_32535_.getInventory().armor.get(3); if (ForgeHooks.shouldSuppressEnderManAnger(this, p_32535_, itemstack)) { return false; } else { Vec3 vec3 = p_32535_.getViewVector(1.0F).normalize(); Vec3 vec31 = new Vec3(this.getX() - p_32535_.getX(), this.getEyeY() - p_32535_.getEyeY(), this.getZ() - p_32535_.getZ()); double d0 = vec31.length(); vec31 = vec31.normalize(); double d1 = vec3.dot(vec31); return d1 > 1.0 - 0.025 / d0 ? p_32535_.hasLineOfSight(this) : false; } } Maybe tho, this will fit your needs? `player.hasLineOfSight(entity)` Alternatively you could do a raycast either using level.clip(...) or your own implementation using AABB's. A little more complicated but you have more control and tinkering power if needed
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.