Jump to content

1.20.1 Entity Visible Check


sfxprt2

Recommended Posts

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.