Jump to content

[1.7.10] Multi-Entity Mob


dfmsguitar

Recommended Posts

Hello, I'm working on creating a Living Entity that's composed of multiple entity segments.  I've created two Entities, an EntityLeader and an EntitySegment.  inside the EntityLeader, I created an Array of EntitySegment and added a method called spawnBodySegments that initializes the array at MAX_SEGMENTS, then for each segment in that array it creates a new EntitySegment, calls setLocationAndAngles, then spawns it into the world.

 

The problem I'm having is, (I guess) I'm not sure where to call this method (spawnBodySegments).  If I call spawnBodySegments from the Constructor or from entityInit(), then when it uses "this.posX" as the base X position for setLocationAndAngles, at this point this.posX = 0.0.  The same with Y and Z obviously.

 

I tried changing onUpdate to check if(this.body == null) at the start of the function then call spawnBodySegments so that it should theoretically only spawn them when onUpdate is first called with a valid set of coordinates.  This seemed to work sort of (based on printing the positions and adding breakpoints to view the position values), except when I iterate through the body segments in onUpdate and call leader = this.body[i - 1]; this.body[ i ].setPosition(leader.posX - 0.5D, leader.posY, leader.posZ - 0.5D); -- just testing to try to get an understanding of the math I need to implement.  When I call that function, for some strange reason it just keeps changing the position of the EntityLead segment. so even without any AI, with all super functions disabled, whenever I spawn one and let that function do its thing, it just drifts away in the -X and -Z direction and doesn't spawn any visible body segments.

 

I'm sure it's something stupid I'm overlooking, but I've pulled out some hair over this.  Any help would be greatly appreciated.

Link to comment
Share on other sites

this is the code that makes the EntityLeader just drift away (EntityLeader is the class this code is in).

if you comment out this line: 

this.body[i].setPosition(leaderX, leaderY, leaderZ);

he just sits still or follows whatever AI is assigned.

	protected void spawnBodySegments()
   {
     if (!this.worldObj.isRemote)
     {
       if (this.body == null)
       {
         this.body = new EntitySegment[MAX_SEGMENTS];
       }
       for (int i = 0; i < MAX_SEGMENTS; i++)
       {
         if ((this.body[i] == null) || (this.body[i].isDead))
         {
           this.body[i] = new EntitySegment(this, i);
           this.body[i].setLocationAndAngles(this.posX + 0.1D * i, this.posY, this.posZ + 0.1D * i, this.rand.nextFloat() * 360.0F, 0.0F);
           this.worldObj.spawnEntityInWorld(this.body[i]);
         }
       }
     }
   }
 public void onUpdate()
 {
	 super.onUpdate();
	 moveSegments();
 }
   protected void moveSegments()
   {	   
	   if(!this.isDead && this.body == null)
	   {
		   spawnBodySegments();
	   }
	   if(this.body != null)
	   {
		   for (int i = 0; i < MAX_SEGMENTS; i++)
		     {
		       Entity leader;
		       
		       if (i == 0)
		       {
		         leader = this;
		       }
		       else
		       {
		         leader = this.body[i - 1];
		       }

		       double leaderX = leader.posX - 0.5D;
		       double leaderY = leader.posY;
		       double leaderZ = leader.posZ - 0.5D;
		       
		       this.body[i].setPosition(leaderX, leaderY, leaderZ);
}

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.