Jump to content

Recommended Posts

Posted

EDIT: I figured it out, I wasn't getting the AABB correctly and I wasn't positioning it correctly either.

Here's a sample for others that may need this in the future.

AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1))

You can also use .expand to change this size of your box.

 

Original Message:

I'm trying to retrieve a list of entities within a specified area.

 

I've been trying to use a custom AABB with worldObj.getEntitiesWithinAABB(), but I can't seem to get my list to display anything when I send it to the log. I've never used AABB so that's probably my problem. I am attempting to use the following code because of the EntityAILookAtVillager script that makes the Iron Golem look at villagers. It's also repeated in other "AILookAt" scripts.

 

Here's the code I'm tinkering with atm. It's in one of my TileEntity scripts.

//Returns list of entities within AABB
private List<EntityLiving> getEntityInRange(){
	AxisAlignedBB detectionBB = AxisAlignedBB.getBoundingBox(5.0D, 2.0D, 5.0D, 5.0D, 2.0D, 5.0D);
	detectionBB.offset(xCoord, yCoord, zCoord);
	List entitylist = worldObj.getEntitiesWithinAABB(EntityLiving.class, detectionBB);
	if(!entitylist.isEmpty()){
		System.out.println("Found entity(ies): " + Arrays.toString(entitylist.toArray()));
		return entitylist;
	}
	System.out.println("NOTHING DETECTED");
	return null;
}

 

Any help is much appreciated.  --Thanks, Navybofus

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.