Jump to content

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


Recommended Posts

Posted

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

Posted

Hi, 
Thanks for replying!

Could you provide an example of how exactly the client proxy should be set up for OBJ loading?

 

I know the model is huge, just want to make something render, will fix it later :D 

 

Posted
@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.

 

  • 4 years later...
Posted

Hello,

Hi and I am making a forge 1.12.2 mod and also trying to get a custom model helmet item (I made a joker mask) and exported it to .json format and put it in the ~/namespace/models/item folder. Though, I'm struggling to get the item to render what I want it to be rendered like as I've positioned it in the 'head' window view in blockbench.

How did you render out your model? I checked your code and it looks like no references to the actual model are being made. I'm new to this forge modding stuff (was a fabric modder) and I desperately need some help. Is there a way to standardly render out armor models made using blockbench? any methods that one can use?

My model in JSON:
```json
{ "credit": "Made with Blockbench", "texture_size": [160, 160], "textures": { "0": "ydyrn:items/joker_mask_texture", "particle": "ydyrn:items/joker_mask_texture" }, "elements": [ { "from": [0, 0, 0], "to": [16, 16, 1], "faces": { "north": {"uv": [0, 1.7, 16, 14.2], "texture": "#0"}, "east": {"uv": [0, 4, 0.9, 5.6], "texture": "#0"}, "south": {"uv": [0, 5.8, 1.6, 7.4], "texture": "#0"}, "west": {"uv": [0, 1.9, 1.3, 3.5], "texture": "#0"}, "up": {"uv": [0, 3.4, 1.6, 4.2], "texture": "#0"}, "down": {"uv": [0, 9, 1.6, 9.7], "texture": "#0"} } }, { "from": [15.8, 11, 0.5], "to": [16.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } }, { "from": [0.2, 11, 14.6], "to": [15.8, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"} } }, { "from": [-0.2, 11, 0.5], "to": [0.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } } ], "display": { "thirdperson_righthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "thirdperson_lefthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "firstperson_righthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "firstperson_lefthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "ground": { "rotation": [40, 0, 0], "translation": [0, -2.5, 0], "scale": [0.5, 0.5, 0.5] }, "gui": { "rotation": [0, 180, 0] }, "head": { "translation": [0, 0, 0.25], "scale": [0.82773, 0.73594, 0.9] }, "fixed": { "translation": [0, 0, 8.75] } }, "groups": [ 0, { "name": "straps", "origin": [0, 0, 0], "color": 0, "children": [1, 2, 3] } ] }
```

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.