Jump to content

[1.10.2] Getting entities within area


XFactHD

Recommended Posts

I am developing a mod with guns and because of the fire rate of those guns I am using raytracing to hit things instead of a projectile entity. My question now is: If the player's look vec is not axis aligned, are the bounds of the AABB used by World#getEntitiesInAABBexcluding() rotated to the Vec3d used or are they still axis aligned? If they are axis aligned, how can I get the entities the vector hits?

Link to comment
Share on other sites

I am developing a mod with guns and because of the fire rate of those guns I am using raytracing to hit things instead of a projectile entity. My question now is: If the player's look vec is not axis aligned, are the bounds of the AABB used by World#getEntitiesInAABBexcluding() rotated to the Vec3d used or are they still axis aligned? If they are axis aligned, how can I get the entities the vector hits?

I think what you are looking for is a MovingObjectPosition which is basically a vector that holds the hit Block or Entity. World#getEntitiesWithinAABB...() is for splash damage (splash potions or AOE sword swings).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

That method doesn't help me as I do not have a projectile entity. The way this method searches for entities is again with an AABB which I can't use.

So you have a MovingObjectPosition? Then it is as simple as MovingObjectPosition#.entity(Hit) != null then you have an entity. If not you should get one from rayTracing

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Okay, I think you're saying that AABB isn't good for you because you don't like how it is axis aligned. Well I would say that that is most of Minecraft's charm -- that it is blocky and grid based.

 

However, if you're saying you want to affect all entities a certain distance from where the projectile hits, what you can do is first find all entities in an AABB that is big enough to contain the "circle" that represents the range you want to check. Then for all the entities in that list, loop through and calculate the distance (simple trigonometry using sum of squares) between the entity and the center of the weapon effect and then keep those entities that are in range.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I tried something but I would like some feedback if that would even work:

public static ArrayList<Pair<Entity, RayTraceResult>> rayTraceEntities(World world, EntityPlayer source, BlockPos startPos, Vec3d dirVecNormal, int length)
    {
        Vec3d startVec = new Vec3d(startPos.getX(), startPos.getY(), startPos.getZ());
        Vec3d endVec   = startVec.add(dirVecNormal.scale(length)).normalize();

        RayTraceResult result = world.rayTraceBlocks(startVec, endVec, false, true, false);

        AxisAlignedBB bb = new AxisAlignedBB(startVec, result != null ? result.hitVec : endVec);
        List<Entity> entities = world.getEntitiesInAABBexcluding(source, bb, entityPredicate);

        ArrayList<Pair<Entity, RayTraceResult>> entitiesInVector = new ArrayList<Pair<Entity, RayTraceResult>>();
        Vec3d startVecEntitySearch = startVec.normalize();
        Vec3d endVecEntitySearch = result != null ? result.hitVec.normalize() : endVec.normalize();

        for (Entity entity : entities)
        {
            if (!entity.noClip && entity.getCollisionBoundingBox() != null)
            {
                RayTraceResult intercept = entity.getCollisionBoundingBox().calculateIntercept(startVecEntitySearch, endVecEntitySearch);
                if (intercept != null)
                {
                    intercept.hitInfo = isHeadshot(intercept.hitVec, intercept.entityHit);
                    entitiesInVector.add(Pair.of(entity, intercept));
                }
            }
        }

        return entitiesInVector;
    }

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.

Announcements



×
×
  • Create New...

Important Information

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