Jump to content

3D Items? - Not even rendering (no crash)


WilLink

Recommended Posts

So I followed this tutorial: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571595-1-7-2-how-to-code-custom-3d-armor-models-3d?page=6#entry30852686

 

And what I have right now is:

MainClass: (Called zmod) (Actually its called ZMod but i have a variable zmod (public static ZMod zmod;))

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	proxy.registerItemRenderers();
	zmod.items();

}

public static void items()
{
	byrne = new ItemSword(ToolMaterial.EMERALD).setUnlocalizedName("byrne").setTextureName(zmod.Id + ":" + "byrne").setCreativeTab(zTab);
	zmod.registerItems();
}

public static void registerItems()
{
	GameRegistry.registerItem(byrne, "Byrne");
}

ClientProxy:

@Override
public void registerItemRenderers()
{
    MinecraftForgeClient.registerItemRenderer(ZMod.byrne, new ItemRenderer());

}

ItemRenderClass:

package zelda.render;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

public class ItemRenderer implements IItemRenderer {
    //you'll need an instance of your model. you could also add it to the constructor as an argument to be able to reuse this class for
    //every model you add
    ModelByrne swordmodel;
    Minecraft mc = Minecraft.getMinecraft();

    //constructor
    public ItemRenderer() {
        swordmodel = new ModelByrne();
    }


    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
        float scale;
	switch (type) {

        case EQUIPPED: // render in third person
            GL11.glPushMatrix(); //start gl rendering for this section
            mc.renderEngine.bindTexture(new ResourceLocation(
                    "subaraki:weapons/Sword.png"));
            GL11.glRotatef(0F, 1.0f, 0.0f, 0.0f);	   //rotate 0 ° on X axis
            GL11.glRotatef(-5F, 0.0f, 1.0f, 0.0f);	  // rotate -5 ° on Y axis
            GL11.glRotatef(-150F, 0.0f, 0.0f, 1.0f);  // rotate -150 ° on Z axis
            GL11.glTranslatef(-0.8F, 0.6F, -0.1F);    //translate model to fit in the hand of the player
//the entity argument can/could be passed to as null.
            swordmodel.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F,
                    0.0625F);
            GL11.glPopMatrix(); //Stop gl rendering for this section
            break;

        case EQUIPPED_FIRST_PERSON:

//rince and repeat the rendering. adjust axis' and translation as needed
            GL11.glPushMatrix();
            mc.renderEngine.bindTexture(new ResourceLocation(
                    "subaraki:weapons/Sword.png"));
            GL11.glRotatef(0F, 1.0f, 0.0f, 0.0f);
            GL11.glRotatef(-5F, 0.0f, 1.0f, 0.0f);
            GL11.glRotatef(-150F, 0.0f, 0.0f, 1.0f);
            GL11.glTranslatef(-0.8F, 0.9F, -0.1F);
            swordmodel.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F,
                    0.0625F);
            GL11.glPopMatrix();
            break;

        case ENTITY:
            GL11.glPushMatrix();
            scale = 1.5F;
            GL11.glScalef(scale, scale, scale);
            mc.renderEngine.bindTexture(new ResourceLocation(
                    "subaraki:weapons/Sword.png"));
            GL11.glRotatef(90F, 1.0f, 0.0f, 0.0f);
            GL11.glRotatef(0F, 0.0f, 1.0f, 0.0f);
            GL11.glRotatef(45F, 0.0f, 0.0f, 1.0f);
            GL11.glTranslatef(-0.2F, 1F, 0F);
            swordmodel.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F,
                    0.0625F);
            GL11.glPopMatrix();
            break;

        case INVENTORY:
            GL11.glPushMatrix();
            scale = 0.7F;
            GL11.glScalef(scale, scale, scale);
            mc.renderEngine.bindTexture(new ResourceLocation(
                    "zelda:models/ByrneWeapon.png"));

            GL11.glRotatef(200F, 1.0f, 0.0f, 0.0f);
            GL11.glRotatef(-80F, 0.0f, 1.0f, 0.0f);
            GL11.glTranslatef(0.0F, 1.2F, 0F);
//this is a method made by me in my model class to render only the modelparts, without an entity argument, because in your inventory, //the entity is always null.
            swordmodel.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
            GL11.glPopMatrix();
            break;

        default:
            break;
        }
    }
@Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        return true;
    }

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,
            ItemRendererHelper helper) {

        switch (type) {
        case INVENTORY:
            return true;
        default:
            break;
        }
        return false;

    }

}

ModelClass:

package zelda.render;

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

public class ModelByrne extends ModelBase
{
  //fields
    ModelRenderer Metal1;
    ModelRenderer Metal2;
    ModelRenderer Handle;
    ModelRenderer Hand;
    ModelRenderer Finger1;
    ModelRenderer Finger2;
    ModelRenderer Finger3;
    ModelRenderer Finger4;
    ModelRenderer Finger5;
    ModelRenderer Finger6;
    ModelRenderer Finger7;
    ModelRenderer Finger8;
    ModelRenderer Finger9;
    ModelRenderer Finger0;
  
  public ModelByrne()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Metal1 = new ModelRenderer(this, 27, 0);
      Metal1.addBox(0F, 0F, 0F, 8, 7, 2);
      Metal1.setRotationPoint(-4F, 13F, -8F);
      Metal1.setTextureSize(64, 32);
      Metal1.mirror = true;
      setRotation(Metal1, 0F, 0F, 0F);
      Metal2 = new ModelRenderer(this, 27, 10);
      Metal2.addBox(0F, 0F, 0F, 7, 6, 2);
      Metal2.setRotationPoint(-3.5F, 13.5F, 0F);
      Metal2.setTextureSize(64, 32);
      Metal2.mirror = true;
      setRotation(Metal2, 0F, 0F, 0F);
      Handle = new ModelRenderer(this, 0, 0);
      Handle.addBox(0F, 0F, 0F, 6, 5, 6);
      Handle.setRotationPoint(-3F, 14F, -6F);
      Handle.setTextureSize(64, 32);
      Handle.mirror = true;
      setRotation(Handle, 0F, 0F, 0F);
      Hand = new ModelRenderer(this, 0, 13);
      Hand.addBox(0F, 0F, 0F, 5, 4, 4);
      Hand.setRotationPoint(-2.5F, 14.5F, 2F);
      Hand.setTextureSize(64, 32);
      Hand.mirror = true;
      setRotation(Hand, 0F, 0F, 0F);
      Finger1 = new ModelRenderer(this, 50, 0);
      Finger1.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger1.setRotationPoint(-2.2F, 15.8F, 8F);
      Finger1.setTextureSize(64, 32);
      Finger1.mirror = true;
      setRotation(Finger1, -0.5651149F, 0F, 0F);
      Finger2 = new ModelRenderer(this, 50, 0);
      Finger2.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger2.setRotationPoint(-2.2F, 15.8F, 6F);
      Finger2.setTextureSize(64, 32);
      Finger2.mirror = true;
      setRotation(Finger2, 0F, 0F, 0F);
      Finger3 = new ModelRenderer(this, 50, 0);
      Finger3.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger3.setRotationPoint(2F, 15.8F, 4F);
      Finger3.setTextureSize(64, 32);
      Finger3.mirror = true;
      setRotation(Finger3, 0F, 0.3490659F, 0F);
      Finger4 = new ModelRenderer(this, 50, 0);
      Finger4.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger4.setRotationPoint(1.1F, 15.7F, 8F);
      Finger4.setTextureSize(64, 32);
      Finger4.mirror = true;
      setRotation(Finger4, -0.5651149F, 0F, 0F);
      Finger5 = new ModelRenderer(this, 50, 0);
      Finger5.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger5.setRotationPoint(-1.1F, 15.6F, 6F);
      Finger5.setTextureSize(64, 32);
      Finger5.mirror = true;
      setRotation(Finger5, 0F, 0F, 0F);
      Finger6 = new ModelRenderer(this, 50, 0);
      Finger6.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger6.setRotationPoint(-1.1F, 15.6F, 8F);
      Finger6.setTextureSize(64, 32);
      Finger6.mirror = true;
      setRotation(Finger6, -0.5651149F, 0F, 0F);
      Finger7 = new ModelRenderer(this, 50, 0);
      Finger7.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger7.setRotationPoint(0F, 15.5F, 8F);
      Finger7.setTextureSize(64, 32);
      Finger7.mirror = true;
      setRotation(Finger7, -0.5651149F, 0F, 0F);
      Finger8 = new ModelRenderer(this, 50, 0);
      Finger8.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger8.setRotationPoint(1.1F, 15.7F, 6F);
      Finger8.setTextureSize(64, 32);
      Finger8.mirror = true;
      setRotation(Finger8, 0F, 0F, 0F);
      Finger9 = new ModelRenderer(this, 50, 0);
      Finger9.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger9.setRotationPoint(2.7F, 15.8F, 5.9F);
      Finger9.setTextureSize(64, 32);
      Finger9.mirror = true;
      setRotation(Finger9, -0.5651149F, 0.3490659F, 0F);
      Finger0 = new ModelRenderer(this, 50, 0);
      Finger0.addBox(0F, 0F, 0F, 1, 1, 2);
      Finger0.setRotationPoint(0F, 15.5F, 6F);
      Finger0.setTextureSize(64, 32);
      Finger0.mirror = true;
      setRotation(Finger0, 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, entity);
    Metal1.render(f5);
    Metal2.render(f5);
    Handle.render(f5);
    Hand.render(f5);
    Finger1.render(f5);
    Finger2.render(f5);
    Finger3.render(f5);
    Finger4.render(f5);
    Finger5.render(f5);
    Finger6.render(f5);
    Finger7.render(f5);
    Finger8.render(f5);
    Finger9.render(f5);
    Finger0.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, Entity entity)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  }

}

 

When I select the Item in my hotbar it just displays as a normal item... No 3D Model in hand?

Any help?

 

EDIT: There are no shown errors.

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.