Jump to content

[SOLVED] [1.8] Modeling In Java


EverythingGames

Recommended Posts

Hi

I have successfully rendered .JSON models, its just that they don't have the flexibility that the Java coded models have. For example, animating, rendering / de-rendering cuboids within its own code. You can do this in .JSON, you just have to switch models and use IPerspectiveAwareModel. Anyway, how do you render a create a model and render it for an item? I know you must extend ModelBase and use or code your own model there (I mean use as in create it in Techne and use the exported code there). I just need pointed in the right direction:

1.) What is the replacement for the interface IItemRenderer?

2.) How do you attach the model to your item?

3.) Are there any 1.8 tutorials on this that covers items, not blocks or entities?

Thanks for all the help in advance!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

I hope I'm correct on this, I've done a bit of research - What if I created a model for an item in Techne (or some other tool that exports Java code models), registered it on the ModelBakeEvent with a ModelResourceLocation refering to the model, but how exactly is this model attached to the item to invoke the rendering for the item? Is it done just the same as registering a .JSON model? If I create a model class containing the model code, how is it attached to the item? I've tried to go the simple way of .JSON, but I can't UV the local skin to the model (its an item model with an arm attached to it to make it look like the player is actually holding the item, I just can't get the skin to bind to the arm because its .JSON not java code with the bind local skin method). Any further help is greatly appreciated, thanks!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

Hi

 

Using the technique in MBE15 you can create whatever shape model you want - you just have to generate the appropriate list of BakedQuads for rendering.  For example, Forge already has b3d model loader built in which builds (bakes) the list of quads from a parsed B3D file - have a look at the B3DModel and B3DLoader classes, especially B3Dloader.getGeneralQuads.

 

I'm not sure I understand the problem with the binding of the skin, do you mean you want to bind the player's skin to part of your item model?  That will be tricky and I don't think the B3Dloader will help you.

 

I would suggest you render the player's arm separately during one of the render events, using entity-rendering code, and not try to render it as part of the item.

 

-TGG

 

Link to comment
Share on other sites

Thanks, TGG. Yes, I want to draw the player's arm and bind the player's skin to it. The thing is I want to do this while holding my item (this item has a custom model). I've seen people draw quads, then bind the local skin and invoke the rendering when the player holds the item - that is exactly what I need to do. I can do this with .JSON models by making the arm a part of the item with a texture for it - but that's the problem...that's not the player's skin. Basically I just want players to be able to see their personal arm holding the item. With all this, how do I create an arm model, bind the player's skin to it (the part of the texture for the arm), then invoke that rendering when holding my custom item. I don't mind using .JSON modeling for the item, just as long as I can render the arm with it. I hope I wasn't too confusing, I appreciate everyone's help. Thanks!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

Hi

 

I would suggest you create your arm model using techne or MCAnimator or whatever tool you normally use.

Then, during RenderHandEvent, bind the player's texture and draw your model of the arm as you normally would for Entities, i.e. ModelRenderer and such.

 

Vanilla drawing of the player's hand is hard to find because of the obfuscated names, if you start at

ItemRenderer.renderItemInFirstPerson you can dig down through the various layers and following this down you eventually get to  ModelPlayer.func_178725_a or ModelPlayer.func_178102_b which might give you some hints on how to do it.

 

Then just draw the item as a JSON separately. 

 

That way you don't need to mess around with the player's skin texture.  When rendering your items you are stuck with using the blocks/items texture sheet.  You might be able to implement a hacky solution to rebind the texture during a call to ISmartItemModel.handleItemState or similar, but I think it would be fragile.

 

-TGG

 

 

 

 

Link to comment
Share on other sites

I haven't an idea of how to draw the arm and render it when I want to. All these parameters are confusing me from the ModelPlayer class. Could someone tell me in depth how to specifically do this drawing and rendering (I'm sorry about asking this, I dont have experience with rendering models with Java code, and BTW I'm not asking you to write this code for me)? Is it exactly the same as an entity as in drawing and rendering? As you can quite clearly see, I am very confused, I just need some instructions and directing. Thanks again for being patient with a person who's not so good with the modeling and rendering side of things!

 

EDIT: Figured most of it out, but I still need help on a certain point (not the modeling part).

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

I have my model coded and ready to render, just how do I call the render when I am holding my item? I'm sure I must call this method here on the RenderHandEvent correct?:

    @Override
    public void render(Entity par1Entity, float par2Float, float par3Float, float par4Float, float par5Float, float par6Float, float par7Float)
    {
super.render(par1Entity, par2Float, par3Float, par4Float, par5Float, par6Float, par7Float);
this.setRotationAngles(par2Float, par3Float, par4Float, par5Float, par6Float, par7Float, par1Entity);
this.arm.render(par7Float);
    }

 

EDIT: Check the post after.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

Here's an enormous update:

1.) I have completely created the arm model.

2.) I Have UV Mapped the model to the player's skin's arm.

3.) I Have binded and rendered the arm on the RenderHandEvent

 

Here's what is left to do / what I need help on to complete this and mark the topic solved:

1.) This is going to be hard to describe, so bear with me. First of all, when the arm is rendered, it stays in a specific place, and does not move with the player when looking around. Here's an example - I am looking north. The arm is rendered right in front of me, I can see it. When I turn my head east, the arm does not move with the direction that I am looking, it just stays where it was first rendered and only moves with the player when I walk. How do I fix this? This is all I need to finish this render. If I was to unclear, listen to this - the default player first person arm moves with you when you look around, and doesn't just stay in one place (Kind of like I want the arm to move according to the player's head yaw and pitch. Basically the model moves according to where you are looking like the vanilla first person hand). I hope I'm making some sense, further assistance is greatly appreciated, thanks!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

I think that can easilly be accomllished by adding rotations to the whole model according the players yaw and pitch. Wait... didn't you say that already? Maybe you asked something different from what you meant. Anyways, the rotation can be simply added through the gl_rotateF() method (capitals might be off).

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Link to comment
Share on other sites

Hi

 

N247S is right I think, just use GL11.glRotatef (or    GlStateManager.rotate  )

 

At a quick glance, most of that action for vanilla happens here

 

    public void renderItemInFirstPerson(float p_78440_1_)
    {
        float f1 = 1.0F - (this.prevEquippedProgress + (this.equippedProgress - this.prevEquippedProgress) * p_78440_1_);
        EntityPlayerSP entityplayersp = this.mc.thePlayer;
        float f2 = entityplayersp.getSwingProgress(p_78440_1_);
        float f3 = entityplayersp.prevRotationPitch + (entityplayersp.rotationPitch - entityplayersp.prevRotationPitch) * p_78440_1_;
        float f4 = entityplayersp.prevRotationYaw + (entityplayersp.rotationYaw - entityplayersp.prevRotationYaw) * p_78440_1_;
        this.func_178101_a(f3, f4);
        this.func_178109_a(entityplayersp);
        this.func_178110_a((EntityPlayerSP)entityplayersp, p_78440_1_);

and
    private void func_178101_a(float p_178101_1_, float p_178101_2_)
    {
        GlStateManager.pushMatrix();
        GlStateManager.rotate(p_178101_1_, 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(p_178101_2_, 0.0F, 1.0F, 0.0F);
        RenderHelper.enableStandardItemLighting();
        GlStateManager.popMatrix();
    }

and

    private void func_178110_a(EntityPlayerSP p_178110_1_, float p_178110_2_)
    {
        float f1 = p_178110_1_.prevRenderArmPitch + (p_178110_1_.renderArmPitch - p_178110_1_.prevRenderArmPitch) * p_178110_2_;
        float f2 = p_178110_1_.prevRenderArmYaw + (p_178110_1_.renderArmYaw - p_178110_1_.prevRenderArmYaw) * p_178110_2_;
        GlStateManager.rotate((p_178110_1_.rotationPitch - f1) * 0.1F, 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate((p_178110_1_.rotationYaw - f2) * 0.1F, 0.0F, 1.0F, 0.0F);
    }

 

-TGG

Link to comment
Share on other sites

That goes along the lines of what is needed to be done using pitch and yaw. My model arm is the exact same as vanilla's, for further info. I have written both those obfuscated methods you have shown me, but I don't know what to plug in for those float values. Here's my code:

        private ModelLeftArm modelLeftArm = new ModelLeftArm();

public void rotateModelOne(float par1Float, float par2Float)
{
	GlStateManager.pushMatrix();
	GlStateManager.rotate(par1Float, 1.0F, 0.0F, 0.0F);
	GlStateManager.rotate(par2Float, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
	GlStateManager.popMatrix();
}

public void rotateModelTwo(EntityPlayerSP par1EntityPlayerSP, float par2Float)
{
	float float1 = par1EntityPlayerSP.prevRenderArmPitch + (par1EntityPlayerSP.renderArmPitch - par1EntityPlayerSP.prevRenderArmPitch) * par2Float;
	float float2 = par1EntityPlayerSP.prevRenderArmYaw + (par1EntityPlayerSP.renderArmYaw - par1EntityPlayerSP.prevRenderArmYaw) * par2Float;
	GlStateManager.rotate((par1EntityPlayerSP.rotationPitch - float1) * 0.1F, 1.0F, 0.0F, 0.0F);
	GlStateManager.rotate((par1EntityPlayerSP.rotationYaw - float2) * 0.1F, 0.0F, 1.0F, 0.0F);
}

@SubscribeEvent
public void renderHandEvent(RenderHandEvent par1RenderHandEvent)
{
	GlStateManager.pushMatrix();
	EntityPlayerSP entityplayersp = Minecraft.getMinecraft().thePlayer;
	Minecraft.getMinecraft().getTextureManager().bindTexture(entityplayersp.getLocationSkin());

	this.rotateModelOne(float); //What do I plug in here?
	this.rotateModelTwo(float); //What do I plug in here?

	this.modelLeftArm.render(entityplayersp, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
	GlStateManager.popMatrix();
}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

UPDATE:

I've figured out the float paramters and wrote extra methods, then I rendered it. This did absolutely nothing but fix the lighting. Here's the updated code:

public class ModelRender 
{

private ModelLeftArm modelLeftArm = new ModelLeftArm();

public void rotateModelOne(float par1Float, float par2Float)
{
	GlStateManager.pushMatrix();
	GlStateManager.rotate(par1Float, 1.0F, 0.0F, 0.0F);
	GlStateManager.rotate(par2Float, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
	GlStateManager.popMatrix();
}

public void rotateModelTwo(EntityPlayerSP par1EntityPlayerSP, float par2Float)
{
	float float1 = par1EntityPlayerSP.prevRenderArmPitch + (par1EntityPlayerSP.renderArmPitch - par1EntityPlayerSP.prevRenderArmPitch) * par2Float;
	float float2 = par1EntityPlayerSP.prevRenderArmYaw + (par1EntityPlayerSP.renderArmYaw - par1EntityPlayerSP.prevRenderArmYaw) * par2Float;
	GlStateManager.rotate((par1EntityPlayerSP.rotationPitch - float1) * 0.1F, 1.0F, 0.0F, 0.0F);
	GlStateManager.rotate((par1EntityPlayerSP.rotationYaw - float2) * 0.1F, 0.0F, 1.0F, 0.0F);
}

public void setLightMap(AbstractClientPlayer par1AbstractClientPlayer)
{
	int integer1 = Minecraft.getMinecraft().theWorld.getCombinedLight(new BlockPos(par1AbstractClientPlayer.posX, par1AbstractClientPlayer.posY + (double) par1AbstractClientPlayer.getEyeHeight(), par1AbstractClientPlayer.posZ), 0);
	float float1 = (float)(integer1 & 65535);
	float float2 = (float)(integer1 >> 16);
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, float1, float2);
}

public void renderArmInFirstPerson(float par1Float)
{
	EntityPlayerSP entityplayersp = Minecraft.getMinecraft().thePlayer;
	float f3 = entityplayersp.prevRotationPitch + (entityplayersp.rotationPitch - entityplayersp.prevRotationPitch) * par1Float;
	float f4 = entityplayersp.prevRotationYaw + (entityplayersp.rotationYaw - entityplayersp.prevRotationYaw) * par1Float;
	this.rotateModelOne(f3, f4);
	this.setLightMap(entityplayersp);
	this.rotateModelTwo(entityplayersp, par1Float);
	this.modelLeftArm.render(entityplayersp, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
}

@SubscribeEvent
public void renderHandEvent(RenderHandEvent par1RenderHandEvent)
{
	EntityPlayerSP entityplayersp = Minecraft.getMinecraft().thePlayer;
	Minecraft.getMinecraft().getTextureManager().bindTexture(entityplayersp.getLocationSkin());
	this.renderArmInFirstPerson(par1RenderHandEvent.partialTicks);
}

}

 

We're almost there guys! Further help is much needed and appreciated.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

UPDATE 2:

I feel like I'm reinventing the wheel. I look at all the 1.7.10 mods that just render the arm as a part of the item while still being able to bind the players skin location. They do this in IItemRenderer when 1.8 (seems like nothing supports it and 1.9 is about to come out) doesn't have this feature anymore. Oh well, lets analyze our problem:

 

The reason why it didn't work was because GlStateManager.push / pop matrix was called in a method before it rendered the arm - thats fixed. Here's the real problem - that code does indeed work, the only thing is that the pitch and yaw works 50%. In other words the yaw works (moving the model up and down), but the pitch doesn't. Pitch just rotates the model itself as if the arm was spinning and not actually moving with the player as the player turns. I believed this is caused by the offset / axis (the point in which the model rotates from), and I don't know what is going wrong because the arm is pretty much exactly the same as vanilla in dimmension and offset points. I am thinking we should somehow be able to attach the model to a part of the body so that the model is always in front of the player and moving according to where your looking / moving. I know some people have solved this, more help would be extremely appreciated. Thanks.

 

public class ModelRender 
{

private ModelLeftArm modelLeftArm = new ModelLeftArm();

public void rotateModelOne(float par1Float, float par2Float)
{
	GlStateManager.rotate(par1Float, 1.0F, 0.0F, 0.0F);
	GlStateManager.rotate(par2Float, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
}

public void rotateModelTwo(EntityPlayerSP par1EntityPlayerSP, float par2Float)
{
	float float1 = par1EntityPlayerSP.prevRenderArmPitch + (par1EntityPlayerSP.renderArmPitch - par1EntityPlayerSP.prevRenderArmPitch) * par2Float;
	float float2 = par1EntityPlayerSP.prevRenderArmYaw + (par1EntityPlayerSP.renderArmYaw - par1EntityPlayerSP.prevRenderArmYaw) * par2Float;
	GlStateManager.rotate((par1EntityPlayerSP.rotationPitch - float1) * 0.1F, 1.0F, 0.0F, 0.0F);
	GlStateManager.rotate((par1EntityPlayerSP.rotationYaw - float2) * 0.1F, 0.0F, 1.0F, 0.0F);
}

public void setLightMap(AbstractClientPlayer par1AbstractClientPlayer)
{
	int integer1 = Minecraft.getMinecraft().theWorld.getCombinedLight(new BlockPos(par1AbstractClientPlayer.posX, par1AbstractClientPlayer.posY + (double) par1AbstractClientPlayer.getEyeHeight(), par1AbstractClientPlayer.posZ), 0);
	float float1 = (float)(integer1 & 65535);
	float float2 = (float)(integer1 >> 16);
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, float1, float2);
}

public void renderArmInFirstPerson(float par1Float)
{
	EntityPlayerSP entityplayersp = Minecraft.getMinecraft().thePlayer;
	float f3 = entityplayersp.prevRotationPitch + (entityplayersp.rotationPitch - entityplayersp.prevRotationPitch) * par1Float;
	float f4 = entityplayersp.prevRotationYaw + (entityplayersp.rotationYaw - entityplayersp.prevRotationYaw) * par1Float;
	this.rotateModelOne(f3, f4);
	this.setLightMap(entityplayersp);
	this.rotateModelTwo(entityplayersp, par1Float);
	this.modelLeftArm.render(entityplayersp, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
}

@SubscribeEvent
public void renderHandEvent(RenderHandEvent par1RenderHandEvent)
{
	GlStateManager.pushMatrix();
	EntityPlayerSP entityplayersp = Minecraft.getMinecraft().thePlayer;
	Minecraft.getMinecraft().getTextureManager().bindTexture(entityplayersp.getLocationSkin());
	this.renderArmInFirstPerson(par1RenderHandEvent.partialTicks);
	GlStateManager.popMatrix();
}

}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

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.