Jump to content

Change mob model depending on state?


HappleAcks

Recommended Posts

So if I wanted to change a mob model depending on a state (using a method getState() in the entity file).

 

My current render file:

 

 

 

 

@SideOnly(Side.CLIENT)

public class RenderHusser extends RenderLiving {

private static final ResourceLocation EntityTexture = new ResourceLocation("darkmod:textures/mobs/Husser.png");

protected modelrHusser model;

protected modelrHusser2 model2;

 

public RenderrHusser(ModelBase par1ModelBase, float par2) {

super(par1ModelBase, par2);

model = ((modelrHusser)mainModel);

 

}

 

  public void renderrHusser(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9){

  renderrHusser((EntityrHusser)par1EntityLiving, par2, par4, par6, par8, par9);

     

  }

 

@Override

protected ResourceLocation getEntityTexture(Entity entity) {

 

return EntityTexture;

}

 

}

 

 

Link to comment
Share on other sites

Just set model via the entity's state in the renderHusser function.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

You are using the same texture for both model's?  Possible, but seems odd.

 

Explain how you changed the model.  Did you just say model = model2 or such?

 

Did you change it in your constructur for RenderLiving, ect?  You need to look at the classes you are extending and make sure just changing model really changes everything.

 

 

How different is your new model?  Your other option is to have everythign in one model and choose which peices to render.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

You are using the same texture for both model's?  Possible, but seems odd.

 

Explain how you changed the model.  Did you just say model = model2 or such?

 

Did you change it in your constructur for RenderLiving, ect?  You need to look at the classes you are extending and make sure just changing model really changes everything.

 

 

How different is your new model?  Your other option is to have everythign in one model and choose which peices to render.

 

What I did was this:

 

I know the state function works because it is used inside the entity file to change behaviour and that part works fine.

 

 

@SideOnly(Side.CLIENT)

public class RenderHusser extends RenderLiving {

private static final ResourceLocation EntityTexture = new ResourceLocation("darkmod:textures/mobs/Husser.png");

protected modelrHusser model;

protected modelrHusser2 model2;

 

  public RenderrHusser(ModelBase par1ModelBase, float par2) {

      super(par1ModelBase, par2);

 

     

  }

 

      public void renderrHusser(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9){

  *Bind EntityHusser here*

    if (entityhusser.getState()) == 1){

      model = ((modelrHusser)mainModel);

}else{

      model2= ((modelrHusser2)mainModel);

}

        renderrHusser((EntityrHusser)par1EntityLiving, par2, par4, par6, par8, par9);

       

      }

 

  @Override

  protected ResourceLocation getEntityTexture(Entity entity) {

     

      return EntityTexture;

  }

 

}

 

 

Link to comment
Share on other sites

Shouldn't it be:

 

 

if (entityhusser.getState()) == 1){

      model = ((modelrHusser)mainModel);

}else{

      model = ((modelrHusser2)mainModel);

}

 

 

 

Also, you really need to check renderliving to make sure that carries through.

 

Lastly, print to the debug the state.  You said you are sure the state changes because behavior changes.  That is serever(common) side.  This is client.  Did you put a datawatcher to move the state variable down to the client?

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Wait a minute, that is even wrong.  Something like this.

 

 

 

if (entityhusser.getState()) == 1){

      model = new modelrHusser();

}else{

      model = new modelrHusser2();

}

 

 

 

But really, you shouldn't construct a new one each time.  You need to define them up above as different variables and plug them into model as you go.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Wait a minute, that is even wrong.  Something like this.

 

 

 

if (entityhusser.getState()) == 1){

      model = new modelrHusser();

}else{

      model = new modelrHusser2();

}

 

 

 

But really, you shouldn't construct a new one each time.  You need to define them up above as different variables and plug them into model as you go.

I did define them above as variables, at the top in the code I pasted earlier.

Link to comment
Share on other sites

I think the problem is that the rendering happens on the client but the state is probably updated (along with other mob AI and behavior) on the server.  I just ran into this sort of thing myself for an elephant entity I made where I wanted it to rear up when attacked.  The solution is you need to send a custom packet to sync the client.

 

You can see my elephant model processing the state in this Youtube video (near the end you can see the Elephant gets attacked by the tiger and rears up).  Check it out here: 

 

If you want to see how I used packets for the elephant model state sync, see my tutorial (still sort of draft but should be useful to you) here:  http://jabelarminecraft.blogspot.com/p/packet-handling-for-minecraft-forge-172.html

 

I have other tips about doing entity animations here: http://jabelarminecraft.blogspot.com/p/complex-entity-models-including.html

 

You can also use other packet systems, or the dataWatcher to do this.  But my way seems to work well.

 

Anyway, my point is that I suspect the problem is your state isn't detected by the entity on the client because it is being updated on the server side and not being synced.

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

Link to comment
Share on other sites

I think the problem is that the rendering happens on the client but the state is probably updated (along with other mob AI and behavior) on the server.  I just ran into this sort of thing myself for an elephant entity I made where I wanted it to rear up when attacked.  The solution is you need to send a custom packet to sync the client.

 

You can see my elephant model processing the state in this Youtube video (near the end you can see the Elephant gets attacked by the tiger and rears up).  Check it out here: 

 

If you want to see how I used packets for the elephant model state sync, see my tutorial (still sort of draft but should be useful to you) here:  http://jabelarminecraft.blogspot.com/p/packet-handling-for-minecraft-forge-172.html

 

I have other tips about doing entity animations here: http://jabelarminecraft.blogspot.com/p/complex-entity-models-including.html

 

You can also use other packet systems, or the dataWatcher to do this.  But my way seems to work well.

 

Anyway, my point is that I suspect the problem is your state isn't detected by the entity on the client because it is being updated on the server side and not being synced.

 

This looks very helpful, but it might be a bit much just to make my pet sit. :\

Link to comment
Share on other sites

You defined them, but you didn't initialize them.

 

protected modelrHusser model;

protected modelrHusser2 model2;

In regards to defining it:

 

If you pass model2 to something right now, what did you pass?  Null.  You never initialized it or gave it a value.

 

Down below on the part I pointed out was not right.  You can set teh value in model2 all you want.  Were does livingrender or your code use model2 and model?  Nowhere. 

 

Looking at this you also setup an infinite loop.  You call renderrHusser from renderHusser.  The only thing keeping it from crashing everything is that renderHusser will never get called.

 

I suggest using what jabelar offered and start over.  What you have here isn't going to work.

 

 

 

      public void renderrHusser(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9){

  *Bind EntityHusser here*

    if (entityhusser.getState()) == 1){

      model = ((modelrHusser)mainModel);

}else{

      model2= ((modelrHusser2)mainModel);

}

        renderrHusser((EntityrHusser)par1EntityLiving, par2, par4, par6, par8, par9);

       

      }

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

This looks very helpful, but it might be a bit much just to make my pet sit. :\

 

Yeah, it was a bummer when I realized the same thing -- I just wanted to pass one boolean to my model.  However, since then I've been playing with more complicated animations where I pass other states, counters, and such, and you'll probably want to expand into such things too so probably worth setting it up.

 

However, for quick fix you might be able to use dataWatcher.  It is another method for doing simply syncs of entities.  It has some drawbacks, but only if you're concerned about other people adding mods that interact with your entities and such.

 

My main point is that you need to get the information to the client entity.  There are multiple ways you can try to do that.

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

Link to comment
Share on other sites

This looks very helpful, but it might be a bit much just to make my pet sit. :\

 

Yeah, it was a bummer when I realized the same thing -- I just wanted to pass one boolean to my model.  However, since then I've been playing with more complicated animations where I pass other states, counters, and such, and you'll probably want to expand into such things too so probably worth setting it up.

 

However, for quick fix you might be able to use dataWatcher.  It is another method for doing simply syncs of entities.  It has some drawbacks, but only if you're concerned about other people adding mods that interact with your entities and such.

 

My main point is that you need to get the information to the client entity.  There are multiple ways you can try to do that.

The only problem is, to use a data watcher (and call it) I need to bind the entity, however the render file doesn't have an entity parameter outside the resource location.

Link to comment
Share on other sites

The only problem is, to use a data watcher (and call it) I need to bind the entity, however the render file doesn't have an entity parameter outside the resource location.

 

Oh, you're confused on something that confused me when I first started.  All the logic for changing the model should actually be in your model file and in the model file there is a method you override called render().  That render() method actually gets the entity passed to it.

 

So don't do your logic in the render class, but instead do it in the render() method in your model class.

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.