Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] Custom Armour Model Rendering


JoieNL
 Share

Recommended Posts

Recently I've gotten into making custom models for my armour sets. I have used this tutorial to guide me. Now, the armour works mostly fine. The only thing that goes wrong is that the armour model does not change according to the entity wearing it. That is, it is always rendered small, the arms always move (even on armour stands) and the armour does not follow the player sneaking, holding an item, guarding with a sword, etc. I do realise that some of these things can be circumvented by changing certain fields in ModelBiped and ModelBase (e.g. isChild, isSneaking), but these fields do not cover every movement. How would I go about making the armour render correctly according to the attributes of the entity wearing it? Thanks in advance for any help!

 

Here are the classes involved for reference:

 

ModelElementalArmourIce.java:

Spoiler

public class ModelElementalArmourIce extends ModelBiped {

    public ModelElementalArmourIce(int slot, float scale) {
        super(scale, 0, 64, 64);

        ModelRenderer icyEyes = new ModelRenderer(this, 0, 32);
        icyEyes.addBox(-11F, -3F, 0F, 22, 8, 0);
        icyEyes.setRotationPoint(0F, -8F, -5.1F);
        icyEyes.setTextureSize(64, 64);
        icyEyes.mirror = true;
        setRotation(icyEyes, 0F, 0F);
        bipedHeadwear.addChild(icyEyes);

        ModelRenderer spike1 = new ModelRenderer(this, 48, 32);
        spike1.addBox(-0.5F, -0.5F, 0F, 1, 1, 4);
        spike1.setRotationPoint(1.5F, 2.5F, 2F);
        spike1.setTextureSize(64, 64);
        setRotation(spike1, 0.2617994F, 0.0872665F);
        bipedBody.addChild(spike1);

        ModelRenderer spike2 = new ModelRenderer(this, 48, 32);
        spike2.addBox(-0.5F, -0.5F, 0F, 1, 1, 4);
        spike2.setRotationPoint(-1.5F, 2.5F, 2F);
        spike2.setTextureSize(64, 64);
        spike2.mirror = true;
        setRotation(spike2, 0.2617994F, -0.0872665F);
        bipedBody.addChild(spike2);

        ModelRenderer spike3 = new ModelRenderer(this, 48, 32);
        spike3.addBox(-0.5F, -0.5F, 0F, 1, 1, 4);
        spike3.setRotationPoint(2F, 6F, 2F);
        spike3.setTextureSize(64, 64);
        setRotation(spike3, 0F, 0.1745329F);
        bipedBody.addChild(spike3);

        ModelRenderer spike4 = new ModelRenderer(this, 48, 32);
        spike4.addBox(-0.5F, -0.5F, 0F, 1, 1, 4);
        spike4.setRotationPoint(-2F, 6F, 2F);
        spike4.setTextureSize(64, 64);
        spike4.mirror = true;
        setRotation(spike4, 0F, -0.1745329F);
        bipedBody.addChild(spike4);

        ModelRenderer spike5 = new ModelRenderer(this, 48, 32);
        spike5.addBox(-0.5F, -0.5F, 0F, 1, 1, 4);
        spike5.setRotationPoint(1.5F, 9.5F, 2F);
        spike5.setTextureSize(64, 64);
        setRotation(spike5, -0.2617994F, 0.0872665F);
        bipedBody.addChild(spike5);

        ModelRenderer spike6 = new ModelRenderer(this, 48, 32);
        spike6.addBox(-0.5F, -0.5F, 0F, 1, 1, 4);
        spike6.setRotationPoint(-1.5F, 9.5F, 2F);
        spike6.setTextureSize(64, 64);
        spike6.mirror = true;
        setRotation(spike6, -0.2617994F, -0.0872665F);
        bipedBody.addChild(spike6);

        ModelRenderer clawRightFront = new ModelRenderer(this, 44, 32);
        clawRightFront.addBox(0F, 0F, -0.5F, 1, 5, 1);
        clawRightFront.setRotationPoint(-3F, 10F, -0.7F);
        clawRightFront.setTextureSize(64, 64);
        clawRightFront.mirror = true;
        setRotation(clawRightFront, 0F, 0F);
        bipedRightArm.addChild(clawRightFront);

        ModelRenderer clawRightBack = new ModelRenderer(this, 44, 32);
        clawRightBack.addBox(0F, 0F, -0.5F, 1, 5, 1);
        clawRightBack.setRotationPoint(-3F, 10F, 0.67F);
        clawRightBack.setTextureSize(64, 64);
        clawRightBack.mirror = true;
        setRotation(clawRightBack, 0F, 0F);
        bipedRightArm.addChild(clawRightBack);

        ModelRenderer clawLeftFront = new ModelRenderer(this, 44, 32);
        clawLeftFront.addBox(-1F, 0F, -0.5F, 1, 5, 1);
        clawLeftFront.setRotationPoint(3F, 10F, -0.7F);
        clawLeftFront.setTextureSize(64, 64);
        setRotation(clawLeftFront, 0F, 0F);
        bipedLeftArm.addChild(clawLeftFront);

        ModelRenderer clawLeftBack = new ModelRenderer(this, 44, 32);
        clawLeftBack.addBox(-1F, 0F, -0.5F, 1, 5, 1);
        clawLeftBack.setRotationPoint(3F, 10F, 0.7F);
        clawLeftBack.setTextureSize(64, 64);
        setRotation(clawLeftBack, 0F, 0F);
        bipedLeftArm.addChild(clawLeftBack);

        switch (slot) {
            case 0:
                bipedHeadwear.showModel = true;
                bipedHead.showModel = true;
                bipedBody.showModel = false;
                bipedLeftArm.showModel = false;
                bipedRightArm.showModel = false;
                bipedLeftLeg.showModel = false;
                bipedRightLeg.showModel = false;
                break;
            case 1:
                bipedHeadwear.showModel = false;
                bipedHead.showModel = false;
                bipedBody.showModel = true;
                bipedLeftArm.showModel = true;
                bipedRightArm.showModel = true;
                bipedLeftLeg.showModel = false;
                bipedRightLeg.showModel = false;
                break;
            case 2:
                bipedHeadwear.showModel = false;
                bipedHead.showModel = false;
                bipedBody.showModel = true;
                bipedLeftArm.showModel = false;
                bipedRightArm.showModel = false;
                bipedLeftLeg.showModel = true;
                bipedRightLeg.showModel = true;

                spike1.showModel = false;
                spike2.showModel = false;
                spike3.showModel = false;
                spike4.showModel = false;
                spike5.showModel = false;
                spike6.showModel = false;
                break;
            case 3:
                bipedHeadwear.showModel = false;
                bipedHead.showModel = false;
                bipedBody.showModel = false;
                bipedLeftArm.showModel = false;
                bipedRightArm.showModel = false;
                bipedLeftLeg.showModel = true;
                bipedRightLeg.showModel = true;
                break;
        }
    }

    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);
        super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    }

    private void setRotation(ModelRenderer model, float x, float y) {
        model.rotateAngleX = x;
        model.rotateAngleY = y;
        model.rotateAngleZ = 0F;
    }
}

 

 

ElementalArmourItem.java:

Spoiler

[unimportant contructors and the like]

@Override
@SideOnly(Side.CLIENT)
public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack stack, int armorSlot) {
  GL11.glPushMatrix();
  GL11.glEnable(GL11.GL_BLEND);
  GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  GL11.glPopMatrix();
  ModelElementalArmourIce model = ClientProxy.getElementalArmourModel(4 - armorSlot);
  return model;
}

 

 

ClientProxy.java:

Spoiler

public class ClientProxy extends CommonProxy {

    private static ModelElementalArmourIce[] elementalArmour;

    [preInit]

    @Override
    public void init(FMLInitializationEvent e) {
        super.init(e);
        elementalArmour = new ModelElementalArmourIce[4];
        elementalArmour[0] = new ModelElementalArmourIce(0, 0.5F);
        elementalArmour[1] = new ModelElementalArmourIce(1, 1.0F);
        elementalArmour[2] = new ModelElementalArmourIce(2, 0.5F);
        elementalArmour[3] = new ModelElementalArmourIce(3, 0.5F);
        [other stuff]
    }

    [postInit]

    public static ModelElementalArmourIce getElementalArmourModel(int slot) {
        return elementalArmour[slot];
    }
}

 

 

Edited by JoieNL
Link to comment
Share on other sites

A few days have passed now and I have made little progress. I have found a way to easily apply most important attributes that the model can have:

@Override
    @SideOnly(Side.CLIENT)
    public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack stack, int armorSlot) {
        [...]
        ModelElementalArmourIce model = ClientProxy.getElementalArmourModel(4 - armorSlot);
        ModelBase defaultModel = RendererLivingEntity.class.cast(Minecraft.getMinecraft().getRenderManager().getEntityRenderObject(entity)).getMainModel();
        model.setModelAttributes(defaultModel);
        return model;
    }

This way of doing things does not look particularly beautiful and I would not be surprised if there was some better way of retrieving an entity's default model.

 

Of course, my problem still stands. I have experimented some more with the armour, and have been able to pinpoint several issues that all relate to the entity wearing the armour.

- On armour stands, the helmet's front always faces south and the arms move (idle animation).

- For entities that have their arms sticking forward (e.g. zombies, skeletons), the armour's arms simply hang downwards.

- Zombie villagers also have their heads sticking out the top of the helmet.

 

I will persist in trying to find a solution. I hope someone may be able to help me out.

Link to comment
Share on other sites

Why are you casting that way? 

(ModelBase)foo is sufficient. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Right, that was just a thing I left there for no reason. The casting is to RendererLivingEntity by the way, not ModelBase. Here's the preferred thing:

ModelBase defaultModel = ((RendererLivingEntity) Minecraft.getMinecraft().getRenderManager().getEntityRenderObject(entity)).getMainModel();

The weird cast was there because I was getting confused with both RendererLiving and Render being generic classes.

 

Anyway, this is kind of besides the point of the thread, and I still haven't made any progress on the topic.

Edited by JoieNL
Link to comment
Share on other sites

36 minutes ago, JoieNL said:

Right, that was just a thing I left there for no reason. The casting is to RendererLivingEntity by the way, not ModelBase.

you are correct, I'm on a tablet right now, so things are tricky. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

I thought maybe another mod's code might help me out. I know Twilight Forest has some custom armour models and luckily for me the source code is on GitHub. I will look into things a bit more and report my findings.

Edited by JoieNL
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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • im trying to run a modern rlcraft server but it wont even start. this is the log C:\Users\soto5\Downloads\Modern+RLCraft+Server+Pack-1.12.2-1.5.2\Modern RLCraft Server Pack-1.12.2-1.5.1>java -Xmx4096M -Xms4096M -jar forge.jar nogui A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.base/java.lang.reflect.Method.invoke(Method.java:567)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')         at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34)         at net.minecraft.launchwrapper.Launch.main(Launch.java:28)         ... 6 more    
    • Is there a way to "override" an entity's texture to something else without creating a "dummy" item when using ThrownItemRenderer? I tried creating a Renderer that extends it with a ResourceLocation override but this does not change the entity's 2D texture. Any help would be appreciated. Render class: public class BulletEntityRenderer extends ThrownItemRenderer { private static final ResourceLocation TEXTURE = new ResourceLocation(ExampleMod.MOD_ID, "textures/entity/bullet.png"); public BulletEntityRenderer(EntityRendererProvider.Context context) { super(context); } @Override public ResourceLocation getTextureLocation(Entity entity) { return TEXTURE; } } Render registry: public class ModRender { public static void registerRender() { EntityRenderers.register(ExampleMod.BULLET, BulletEntityRenderer::new); } } Entity class: public class BulletEntity extends ThrowableItemProjectile { private float damage = 12.0F; private int pierceLevel = 0; private int ticksAlive = 0; private final int lifespan = 60; public BulletEntity(EntityType<BulletEntity> type, Level world) { super(type, world); } public BulletEntity(Player player, Level world, float damage, int pierceLevel) { super(ExampleMod.BULLET, player, world); this.damage = damage; this.pierceLevel = pierceLevel; this.setNoGravity(true); } public DamageSource causeBulletDamage(BulletEntity bullet, Entity attacker) { return (new IndirectEntityDamageSource("bullet", bullet, attacker)).setProjectile(); } public void tick() { super.tick(); Vec3 vec3d = this.getDeltaMovement(); double d1 = vec3d.x; double d2 = vec3d.y; double d0 = vec3d.z; if (this.isInWater()) { this.level.addParticle(ParticleTypes.BUBBLE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } else { this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } if (ticksAlive > lifespan) { this.discard(); } ticksAlive++; } @Override protected void onHitEntity(EntityHitResult hitResult) { LivingEntity target = (LivingEntity) hitResult.getEntity(); Entity shooter = getOwner(); double armor = target.getArmorValue() * (1 - (0.2 * pierceLevel)); double toughness = target.getAttribute(Attributes.ARMOR_TOUGHNESS).getValue(); float finalDamage = (float) (damage * (1 - (Math.min(20, Math.max((armor / 5), armor - ((4 * damage) / (toughness + 8))))) / 25)); target.hurt(causeBulletDamage(this, shooter).bypassArmor(), finalDamage); } @Override public Item getDefaultItem() { return ModItems.BULLET; } }
    • Which version of Forge did you use? Post debug log
    • delete this client config file
    • Latest minecraft most viewed youtube video! Here's the link : https://shrinke.me/SCMUI
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.