Jump to content

[1.7.10] Adding a horse entity to a custom entity's fields


shultzy

Recommended Posts

I want my custom wagon entity to add an instance of EntityAnimal and add it to a field like an array or list for my custom entity and have the passive entity move while the wagon is moving. When getEntitiesWithinAABB is called, it's not returning any entities in the list, I am fairly new to entity processing. I am using similar code found in the method interactFirst of the EntityLeashKnot class. Here is the source code:

/**
* First layer of player interaction
*/
public boolean interactFirst(EntityPlayer playerEntity)
{
double minMaxAABB = 7.0D;

// Get list of all entities leashed by player
List leashedList = this.worldObj.getEntitiesWithinAABB(
EntityAnimal.class,
AxisAlignedBB.getBoundingBox((double) this.posX - minMaxAABB, (double) this.posY
- minMaxAABB, (double) this.posZ - minMaxAABB, (double) this.posX
- minMaxAABB, (double) this.posY + minMaxAABB, (double) this.posZ
+ minMaxAABB));

// if there are up to 2 entities leashed anchor them to the wagon
if (leashedList != null && leashedList.size() <= 2)
{
	System.out.println("Returned list of leashed entities on interaction with wagon entity");
	Iterator iterator = leashedList.iterator();

	while (iterator.hasNext())
	{
		EntityAnimal entity = (EntityAnimal) iterator.next();

		if (entity.getLeashed() && entity.getLeashedToEntity() == playerEntity)
		{
			// break leash from player
			entity.clearLeashed(true, true);

			// add entity to wagon
			this.entityHorses.add(entity);

			// DEBUG: to know the correct entities are referenced
			System.out.println(this.entityHorses.isEmpty());
		}
	}

}
return true;
}

Link to comment
Share on other sites

You made a typo in your bounding box:

AxisAlignedBB.getBoundingBox((double) this.posX - minMaxAABB, (double) this.posY

- minMaxAABB, (double) this.posZ - minMaxAABB, (double) this.posX

- minMaxAABB, (double) this.posY + minMaxAABB, (double) this.posZ

+ minMaxAABB));

 

The second posX should be +minMaxAABB not -minMaxAABB.

 

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

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.