Jump to content

[1.12.2] Rendering an OBJ model for an armor piece confusion


babijonas

Recommended Posts

Greetings!

 

I've just recently started tinkering with forge as a means to keep my Java knowledge intact.
Everything was going well until I've decided to create put custom models for armor pieces in the game.

The item (helmet) seems to be completely transparent when putting on.
I haven't made any textures for it as of yet, but as far as I understand, the model should render with pink (missing) textures and only render the mesh if it can't find any textures associated with it. I could be wrong on that front.
I was thinking that this might be related to the JSON files, but so far, their implementation seems alien to me, so I can't say for sure.


Sending over everything that could be related to this issue.
Any suggestions for what I should change would be greatly appreciated even if it's not related to the rendering.

package com.babijonas.demoncraft.Items.armor;

import com.babijonas.demoncraft.Items.models.ModelKnightArmor;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;

import javax.annotation.Nullable;

public class KnightHelmet extends ArmorBase{
    public KnightHelmet(String name, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) {
        super(name, materialIn, renderIndexIn, equipmentSlotIn);

    }
		//Used to get the model for the helmet, Ive created a separate class just for this item, because I've figures I could add effects to it later on.
    @Override
    public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, EntityEquipmentSlot armorSlot, ModelBiped _default){
        if(itemStack!=ItemStack.EMPTY){
            if(itemStack.getItem() instanceof ItemArmor){
                ModelKnightArmor model = new ModelKnightArmor();
                model.bipedHead.showModel = armorSlot == EntityEquipmentSlot.HEAD;
                System.out.print("Called Get Armor Model" + entityLiving.toString() + " " + itemStack.toString() + " " + armorSlot + " " + _default + "\n");
                model.isChild = _default.isChild;
                model.isRiding = _default.isRiding;
                model.isSneak = _default.isSneak;
                model.rightArmPose = _default.rightArmPose;
                model.leftArmPose = _default.leftArmPose;
                return model;
            }
        }
        return null;
    }
}
package com.babijonas.demoncraft.Items.models;

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

public class ModelKnightArmor extends ModelBiped {
//made this class to get the full models for this armor set
    public ModelRenderer knightHelmet;
    //public ModelRender knightChestplate
  	//public ModelRender knightLeggings
   	//public ModelRender knightBoots

    public ModelKnightArmor(){
        this.textureWidth = 128;
        this.textureHeight = 128;

        this.knightHelmet = new ModelRenderer(this, 0, 0);


        this.bipedHead.addChild(knightHelmet);

    }
    @Override
    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);
    }

    public void SetRotateAngle(ModelRenderer modelRenderer, float x, float y, float z){
        modelRenderer.rotateAngleX = x;
        modelRenderer.rotateAngleY = y;
        modelRenderer.rotateAngleZ = z;
    }

}
package com.babijonas.demoncraft.Items.armor;

import com.babijonas.demoncraft.Items.models.ModelKnightArmor;
import com.babijonas.demoncraft.Main;
import com.babijonas.demoncraft.init.ModItems;
import com.babijonas.demoncraft.util.IHasModel;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;

import javax.annotation.Nullable;


public class ArmorBase extends ItemArmor implements IHasModel {

//A base class for Armors, used to render the texture when put on and the item in hand

    public ArmorBase(String name, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) {
        super(materialIn, renderIndexIn, equipmentSlotIn);
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(CreativeTabs.COMBAT);

        ModItems.ITEMS.add(this);
    }

    @Override
    public void registerModels() {
        Main.proxy.registerItemRenderer(this, 0, "inventory");
    }




}



 

Screenshot_75.png

Screenshot_76.png

knight_helmet.mtl knight_helmet.obj knight_helmet.json

Link to comment
Share on other sites

@Mod.EventBusSubscriber(Side.CLIENT)
public class ClientProxy extends CommonProxy {
  ...
    @Override
    public void preInit(FMLPreInitializationEvent e) {
        OBJLoader.INSTANCE.addDomain(MODID);
        super.preInit(e);
    }
  ...
}

Something like this.

 

And don't forget to create blockstate json for your item (it should point to .obj file in "defaults" section):

{
  "forge_marker": 1,
  "defaults":
  {
    "model": "modid:knight_helmet.obj"
  },
  "variants":
  {
    "inventory":[{
      "transform": "forge:default-item"
    }]
  }
}

Something like that.

 

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.