Jump to content

[1.8] Get all EntityLiving entities near a pos


ThatBenderGuy

Recommended Posts

So i've tried this:

 

		for(CoordEntry entry: connectedNodes)
	{
		double bnX = baseNodePos.getX();
		double bnY = baseNodePos.getY();
		double bnZ = baseNodePos.getZ();
		double eX = entry.getPos().getX();
		double eY = entry.getPos().getY();
		double eZ = entry.getPos().getZ();

		List entities = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(eX, eY, eZ, bnX, bnY, bnZ));
		if(player != null) player.addChatMessage(new ChatComponentText("Entities: " + entities.size()));
	}

 

but my chat message always says "Entities: 0" even when I'm in range. Fyi the baseNode position and entry position are on the same X axis but have different Z coordinates

 

is there a better way to debug the bounding box that this.worldObj.getEntitiesWithinAABB creates? I think that would help solve my problem

Bumper Cars!

Link to comment
Share on other sites

is there a better way to debug the bounding box that this.worldObj.getEntitiesWithinAABB creates? I think that would help solve my problem

 

I usually put in console or logger statements such as System.out.println() and print out useful info. In this case you could print out the bounds of the bounding box and see it if makes sense considering where it is supposed to be in the world you're playing in.

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

Link to comment
Share on other sites

                    for (EntityLivingBase e:world.getEntities(EntityLivingBase.class, new Predicate<EntityLivingBase>() {

                        @Override
                        public boolean apply(EntityLivingBase input) {
                            return (input.getDistanceToEntity(player) <= DISTANCE);
                        }
                    })) {
                        // Do stuff
                    }

 

It's not super clean or elegant, but it does work.

Just make sure you get the right imports.

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.