Modding 1.4.7: Basic Mob Part 9: Model Rendering

In this tutorial I will show you how to finish up your mob. A part of this code is done in the ClientProxy. This is the file I will start with.


package tutorial;

import net.minecraftforge.client.MinecraftForgeClient;

public class ClientProxyTutorial extends CommonProxyTutorial
{
@Override
public void registerRenderThings()
{
MinecraftForgeClient.preloadTexture(“/tutorialblocks.png”);
}
}


In the last tutorial you have created and exported a Model java file and a texture.png file for your mob. The first thing you need to do is place that texture in your Minecraft.jar (inside of the jars folder in MCP).
Now the next thing you will have to do is get that Model file and drag it into your package.
When you do that it should give you a file like this.


// Date: 12-1-2013 14:46:55
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// – ZeuX






package net.minecraft.src;

public class ModelModel extends ModelBase
{
  //fields
    ModelRenderer Legleft;
    ModelRenderer Legright;
    ModelRenderer Body;
    ModelRenderer Head;
  
  public ModelModel()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Legleft = new ModelRenderer(this, 11, 21);
      Legleft.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legleft.setRotationPoint(2F, 18F, 0F);
      Legleft.setTextureSize(64, 32);
      Legleft.mirror = true;
      setRotation(Legleft, 0F, 0F, 0F);
      Legright = new ModelRenderer(this, 29, 21);
      Legright.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legright.setRotationPoint(-2F, 18F, 0F);
      Legright.setTextureSize(64, 32);
      Legright.mirror = true;
      setRotation(Legright, 0F, 0F, 0F);
      Body = new ModelRenderer(this, 14, 10);
      Body.addBox(-3.5F, -3F, -2F, 7, 6, 4);
      Body.setRotationPoint(0F, 15.16667F, 0F);
      Body.setTextureSize(64, 32);
      Body.mirror = true;
      setRotation(Body, 0F, 0F, 0F);
      Head = new ModelRenderer(this, 17, 3);
      Head.addBox(-1.5F, -3F, -1.5F, 3, 3, 3);
      Head.setRotationPoint(0F, 12F, 0F);
      Head.setTextureSize(64, 32);
      Head.mirror = true;
      setRotation(Head, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5);
    Legleft.render(f5);
    Legright.render(f5);
    Body.render(f5);
    Head.render(f5);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5);
  }

}


It will also be full of errors. To fix that you first have to change the package to where the file is in. Then hover your mouse over the class name and select change type to ‘yourfilename’. Now press Ctrl, Shift, O and all the errors except for one should be gone.
To fix the last error you will have to change a bit more. You have to remove the setRotationAngles method you have right now and paste in this one.


public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)
  {
    super.setRotationAngles(par1, par2, par3, par4, par5, par6, par7Entity);
  }


Now you will get a new error in the render method. To fix that one you have to change the parameters in the method to this.


public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7)


Once again you will get new errors, but these are the last ones you will have to fix. The first thing you have to do is change the f5 behind all the parts inside of the render method into par7. Another thing you need to do is  change the first two lines in the render method into these two.


super.render(par1Entity, par2, par3, par4, par5, par6, par7);
setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);


Now all the errors should be gone. The file should now look something like this.


package tutorial;

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelTutorial extends ModelBase
{
  //fields
    ModelRenderer Legleft;
    ModelRenderer Legright;
    ModelRenderer Body;
    ModelRenderer Head;
  
  public ModelTutorial()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Legleft = new ModelRenderer(this, 11, 21);
      Legleft.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legleft.setRotationPoint(2F, 18F, 0F);
      Legleft.setTextureSize(64, 32);
      Legleft.mirror = true;
      setRotation(Legleft, 0F, 0F, 0F);
      Legright = new ModelRenderer(this, 29, 21);
      Legright.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legright.setRotationPoint(-2F, 18F, 0F);
      Legright.setTextureSize(64, 32);
      Legright.mirror = true;
      setRotation(Legright, 0F, 0F, 0F);
      Body = new ModelRenderer(this, 14, 10);
      Body.addBox(-3.5F, -3F, -2F, 7, 6, 4);
      Body.setRotationPoint(0F, 15.16667F, 0F);
      Body.setTextureSize(64, 32);
      Body.mirror = true;
      setRotation(Body, 0F, 0F, 0F);
      Head = new ModelRenderer(this, 17, 3);
      Head.addBox(-1.5F, -3F, -1.5F, 3, 3, 3);
      Head.setRotationPoint(0F, 12F, 0F);
      Head.setTextureSize(64, 32);
      Head.mirror = true;
      setRotation(Head, 0F, 0F, 0F);
  }
  
  public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7)
  {
    super.render(par1Entity, par2, par3, par4, par5, par6, par7);
    setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
    Legleft.render(par7);
    Legright.render(par7);
    Body.render(par7);
    Head.render(par7);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  
  public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)
  {
    super.setRotationAngles(par1, par2, par3, par4, par5, par6, par7Entity);
  }
}


The next part of the code is done inside of the ClientProxy. In there you will have to add one line of code to make sure your mob renders properly. The line looks like this.


RenderingRegistry.registerEntityRenderingHandler(EntityTutorial.class, new RenderTutorial(new ModelTutorial(), 0.3F));


So the first parameter is your mob.class. The second parameter is the Render file. In there you add the Model file and a float variable. The number you add there will control the size of the shadow below the mob. If you make it higher the shadow will be a lot bigger.
The ClientProxy should now look like this.


package tutorial;

import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraftforge.client.MinecraftForgeClient;

public class ClientProxyTutorial extends CommonProxyTutorial
{
@Override
public void registerRenderThings()
{
MinecraftForgeClient.preloadTexture(“/tutorialblocks.png”);
RenderingRegistry.registerEntityRenderingHandler(EntityTutorial.class, new RenderTutorial(new ModelTutorial(), 0.3F));
}
}


Now when you enter the game you will see the mob having the model you have created in Techne.
In the next tutorial I will show you how to create animations for your mob.

The source code will be available at the end of the last tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">