Jump to content

[SOLVED][1.9] HOW TO CHANGE PLAYER MODEL?


lukas2005

Recommended Posts

@SubscribeEvent to RenderPlayerEvent.Pre and/or Post. Cancel rendering and render your own model.

 

Note: This will require intermediate understanding or Render.class and its sub-classes as well as general to advanced OpenGL knowledge. On a side - also pretty much everything about vanilla rendering systems.

 

What help are you expecting? What model you want to use? What you want to render? What about animations (if you have different model, you need different animations, which you need to also code)? What about rendering vanilla other stuff such as armours and other "layers"?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Currently i only want to render custom model later i will try to make animations and armor but not now

 

EDIT:

 

I writed some code :

 

public class PreRenderEvent

{

    RenderManager manager = Minecraft.getMinecraft().getRenderManager();

 

    @SubscribeEvent

    public void preRenderPlayer(RenderLivingEvent.Pre event)

    {

        if (!(event.getEntity() instanceof EntityPlayer)) return;

        event.setCanceled(true);

 

        System.out.println("I think it works");

       

    }

}

 

And registered it with:

 

MinecraftForge.EVENT_BUS.register(new PreRenderEvent());

 

and now i'm invisible

 

so where i ned to put the render code now?

 

 

Link to comment
Share on other sites

In event :)

 

Pre allows you to cancel everything that happens between Pre and Post. If you cancelled it normal rendering doesn't happen (thus invisible) and you can write (where your println is) your own rendering.

 

Now - as stated before, Entities don't really have models - they have Render classes which basically render entity directly from code (or rather Model classes such as ModelBiped)

To render anything custom - you will do it from code level (GL operations) or you can make GL render some model for you (e.g: wavefront).

 

In any case - again:

This will require intermediate understanding or Render.class and its sub-classes as well as general to advanced OpenGL knowledge. On a side - also pretty much everything about vanilla rendering systems.

 

Notice RenderPlayer and Render#doRender method. Args passed there are entity and positioning x/y/z. You will basically need to do same shit as in Render->RenderLiving->RenderPlayer (I am not in IDE, so idk hierarchy). Other options would be writing class CustomPlayerRender and amke it extend RenderLiving or RenderPlayer. Then simply make instance of it (render classes are singletons, so global static) and use that.

 

After all this talk: Last time I had fun with renders I tried to replace player render in registry, but it didn't work, you can try it yourself.

Make Factory and custom Render class and register it using RenderingRegistry.registerEntityRenderingHandler(EntityPlayer.class, new FactoryCustomPlayer()); Note - I also don't know if it's EntityPlayer or some of its sub, like AbstractClientPlayer maybe - check that. Also note - if this way works, you no longer need events (any).

 

EDIT

Okay, let me clear it up - you either:

 

1. Worth trying:

Make CustomRender extend RenderPlayer and register it in preInit with RenderingRegistry.registerEntityRenderingHandler(EntityPlayer.class, new FactoryCustomPlayer()); where idk if EntityPlayer.class or other sub-class is valid.

 

Note: This might not work (It didn't last time I tried - for players only, for other entities it works fine).

 

2. Valid approach:

Make CustomRender extend RenderPlayer. Override #doRender to write your rendering code. Make global static field and make instance in mod's init. (Lookup how Factory class makes instances). Use that instance and call #doRender from your event (where you do println).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

So i need to do:

 

public class CustomPlayerRender extends RenderPlayer {

 

public CustomPlayerRender(RenderManager renderManager) {

super(renderManager);

// TODO Auto-generated constructor stub

this.renderModel(model, color, (ItemStack)null);

}

 

}

 

is this right?

 

Link to comment
Share on other sites

Remember that statement about OpenGL and vanilla rendering system knowledge? That had Java included and Java also has Programming included which also has reading included (in this case reading of vanilla source). Why don't you tell me what what you did is supposed to do?

 

You can't just randomly call some method from constructor with non-existent params and expect stuff to do anything and even not crash. So while class such as this can exist, it is not proper approach.

 

EDIT

So my answer to this is basically - learn vanilla rendering system (read code).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Ok i re-created my model in Techne and now i have model in .java

Refresh

 

Do you still have a problem?  If so, what is it?

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. Valid approach:

Make CustomRender extend RenderPlayer. Override #doRender to write your rendering code. Make global static field and make instance in mod's init. (Lookup how Factory class makes instances). Use that instance and call #doRender from your event (where you do println).

 

i followed this and i executed render() function that is in my model class

 

and some weird things sarted to happen:

 

 

but i recognize some of parts of my model

 

My code:

 

CustomPlayerRender Class:

public class CustomPlayerRender extends RenderPlayer {

 

public mycustommodel model;

 

public CustomPlayerRender(RenderManager renderManager) {

super(renderManager);

 

model = new mycustommodel();

 

}

 

 

public void doRender(AbstractClientPlayer e) {

 

model.render(e, 1, 1, e.getAge(), e.cameraYaw, e.cameraPitch, 0.1f);

 

}

 

 

}

 

mycustommodel class:

 

public class mycustommodel extends ModelBiped

{

  //fields

    ModelRenderer LegRight;

    ModelRenderer LegLeft;

    ModelRenderer LegsConnector;

    ModelRenderer Body;

    ModelRenderer Head;

    ModelRenderer ArmRightUp;

    ModelRenderer ArmRightDown;

    ModelRenderer ArmLeftUp;

    ModelRenderer ArmLeftDown;

 

  public ModelMuscleMan()

  {

    textureWidth = 64;

    textureHeight = 64;

   

      LegRight = new ModelRenderer(this, 0, 0);

      LegRight.addBox(0F, 0F, 0F, 4, 12, 4);

      LegRight.setRotationPoint(1F, 12F, 1F);

      LegRight.setTextureSize(64, 64);

      LegRight.mirror = true;

      setRotation(LegRight, 0F, 0F, 0F);

      LegLeft = new ModelRenderer(this, 0, 0);

      LegLeft.addBox(0F, 0F, 0F, 4, 12, 4);

      LegLeft.setRotationPoint(-5F, 12F, 1F);

      LegLeft.setTextureSize(64, 64);

      LegLeft.mirror = true;

      setRotation(LegLeft, 0F, 0F, 0F);

      LegsConnector = new ModelRenderer(this, 16, 0);

      LegsConnector.addBox(0F, 0F, 0F, 10, 4, 11);

      LegsConnector.setRotationPoint(-5F, 9F, -2F);

      LegsConnector.setTextureSize(64, 64);

      LegsConnector.mirror = true;

      setRotation(LegsConnector, 0.3490659F, 0F, 0F);

      Body = new ModelRenderer(this, 0, 41);

      Body.addBox(0F, 0F, 0F, 16, 11, 12);

      Body.setRotationPoint(-8F, -1F, -6F);

      Body.setTextureSize(64, 64);

      Body.mirror = true;

      setRotation(Body, 0.3490659F, 0F, 0F);

      Head = new ModelRenderer(this, 0, 25);

      Head.addBox(0F, 0F, 0F, 8, 8, 8);

      Head.setRotationPoint(-4F, -10F, -6F);

      Head.setTextureSize(64, 64);

      Head.mirror = true;

      setRotation(Head, 0.1396263F, 0F, 0F);

      ArmRightUp = new ModelRenderer(this, 32, 28);

      ArmRightUp.addBox(0F, 0F, 0F, 4, 9, 4);

      ArmRightUp.setRotationPoint(5F, 0F, 0F);

      ArmRightUp.setTextureSize(64, 64);

      ArmRightUp.mirror = true;

      setRotation(ArmRightUp, 0.0349066F, 0F, -0.7330383F);

      ArmRightDown = new ModelRenderer(this, 48, 28);

      ArmRightDown.addBox(0F, 0F, 0F, 4, 9, 4);

      ArmRightDown.setRotationPoint(10F, 3F, 1.5F);

      ArmRightDown.setTextureSize(64, 64);

      ArmRightDown.mirror = true;

      setRotation(ArmRightDown, -0.5948578F, 0F, 0F);

      ArmLeftUp = new ModelRenderer(this, 32, 28);

      ArmLeftUp.addBox(0F, 0F, 0F, 4, 9, 4);

      ArmLeftUp.setRotationPoint(-8F, -2F, 1F);

      ArmLeftUp.setTextureSize(64, 64);

      ArmLeftUp.mirror = true;

      setRotation(ArmLeftUp, 0.0349066F, 0F, 0.7330383F);

      ArmLeftDown = new ModelRenderer(this, 48, 28);

      ArmLeftDown.addBox(0F, 0F, 0F, 4, 9, 4);

      ArmLeftDown.setRotationPoint(-14F, 3F, 1.5F);

      ArmLeftDown.setTextureSize(64, 64);

      ArmLeftDown.mirror = true;

      setRotation(ArmLeftDown, -0.5948606F, 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);

    LegRight.render(f5);

    LegLeft.render(f5);

    LegsConnector.render(f5);

    Body.render(f5);

    Head.render(f5);

    ArmRightUp.render(f5);

    ArmRightDown.render(f5);

    ArmLeftUp.render(f5);

    ArmLeftDown.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);

  }

 

}

 

and PreRenderEvent class:

public class PreRenderEvent

{

    RenderManager manager = .getMinecraft().getRenderManager();

   

    @SubscribeEvent

    public void preRenderPlayer(RenderLivingEvent.Pre e)

    {

        if (!(e.getEntity() instanceof EntityPlayer)) return;

        e.setCanceled(true);

 

        gymMod.customPlayerRender.doRender((AbstractClientPlayer) e.getEntity());

       

 

    }

   

   

   

}

 

Link to comment
Share on other sites

In that case you don't need to bind it to the model, but tell openGL what texture to use.

 

I'm not sure for 1.9, since, but try: manager.renderEngine.bindTexture(ResourceLocation);

 

Maybe you need to bind back the blockstexture afterwards, If you get wrong textures on everything you must do it ;-).

Link to comment
Share on other sites

Holy shit. You are actually 1st person to actually get something (and show it) out of all the people who asked about replacing player renders. Not that big of an achievement but progress! :P

 

Before I can even begin to analyze anything you give us - answer me this:

You have:

public class mycustommodel extends ModelBiped

Then you have:

public ModelMuscleMan()

... as your constructor. Since it wouldn't really compile I assume you renamed it while pasting or whatever. But just humor me and post updated and cleaner code.

 

Other:

* Please use Java conventions (capital classes and all that stuff).

* Use [.code] [./code] on forum (without dot).

 

 

Now onto more general stuff:

Note: I already told you to study some vanilla!

 

* RenderPlayer extends RenderLiving extends Render.

* Going top-bottom:

1. Look RenderPlayer#doRender - it apples some stuff (quite important GL states). You pretty much need to recreate all required GL states - even if you don't understand what they mean (hold shit, you should), at least take your time and make them actually be what hey are supposed to be.

2. We have this piece of code (mentioned before):

            GlStateManager.enableBlendProfile(GlStateManager.Profile.PLAYER_SKIN);
            super.doRender(entity, x, d0, z, entityYaw, partialTicks);
            GlStateManager.disableBlendProfile(GlStateManager.Profile.PLAYER_SKIN);

Which pretty much sets up states and goes down to RenderLiving which actually sets up EVERYTHING for you and just calls model#render.

3. Boom! If you look well enough you will notice that everything you actually have to do is return different model and different texture in #getMainModel() and #getEntityTexture(...) and/or MAYBE do some other magic - generally speaking. The code as it is now (trust me it is beautiful compared to what I had when I was working with renders), meaning 1.10 (probably similar/same as 1.9) is VERY CLEAR. You just have to follow line by line and recreate same behaviour while on the way inserting your model and your texture calls.

4. No point getting any further with this.

 

Please - spend some time studying.

1.7.10 is no longer supported by forge, you are on your own.

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.