Jump to content

Recommended Posts

Posted

Every once in a while I reappear with an issue I can't solve which then is solved within merely 3 posts. I hope this is one of those. :|

 

Anyway, my issue is that despite using Vanilla code under some circumstances Minecraft will render a "background" for my custom item. The background appears to be an approximately 10 times larger version of the rendered item. The conditions for this misbehavior are simple: if the first non-empty inventory slot is a non-block item, the background will be rendered. If, for example, I "pick up" the item, i.e. click it once in order to move it to a different slot, the background quickly disappears.

 

Here's some relevant code.

@Override
public void render( ItemRenderType type, ItemStack itemStack, Object... data ) {
IIcon icon = MiscHelper.getItemIcon("stick"); // Just trust me on this one. It gets the IIcon correctly as you can see in the screenshot...

// Inventory coordinates go from 0d to 16d in both x and y coordinates. Plus we don't need to render the sides, just the image.
if( type == ItemRenderType.INVENTORY ) {
	renderItemInInventory(Tessellator.instance, icon);
}
// Everything else goes from 0d to 1d.
else {
	renderItemIn2D(Tessellator.instance, icon, 0.0625d);
}
}

protected void renderItemInInventory( Tessellator tess, IIcon icon ) {
// This call increases the scale for the first two methods here.
//	GL11.glScalef(16f, 16f, 16f);

// Doesn't fucking matter if I use this...
//	renderItemIn2D(tess, icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.0625d);

// Or this...
//	ItemRenderer.renderItemIn2D(tess, icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), (float)0.0625f);

// Or even my own algorithm to render the item in the inventory.
renderItemInInventory(tess, icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV());

// They all end up with an unwanted background under certain circumstances.
}

protected void renderItemInInventory( Tessellator tess, double u1, double v1, double u2, double v2 ) {
tess.startDrawingQuads();
if( baseColor != -1 ) tess.setColorOpaque_I(baseColor);
tess.addVertexWithUV( 0d,  0d, 0d, u1, v1);
tess.addVertexWithUV( 0d, 16d, 0d, u1, v2);
tess.addVertexWithUV(16d, 16d, 0d, u2, v2);
tess.addVertexWithUV(16d,  0d, 0d, u2, v1);
tess.draw();
}

 

My code should differ in no way when only calling ItemRenderer.renderItemIn2D since that is ultimately what happens in the Vanilla ItemRenderer:

 

            texturemanager.bindTexture(texturemanager.getResourceLocation(p_78443_2_.getItemSpriteNumber()));
            TextureUtil.func_152777_a(false, false, 1.0F);
            Tessellator tessellator = Tessellator.instance;
            float f = iicon.getMinU();
            float f1 = iicon.getMaxU();
            float f2 = iicon.getMinV();
            float f3 = iicon.getMaxV();
            float f4 = 0.0F;
            float f5 = 0.3F;
            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            GL11.glTranslatef(-f4, -f5, 0.0F);
            float f6 = 1.5F;
            GL11.glScalef(f6, f6, f6);
            GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
            GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
            GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);

            // Code before and after this call is part of the ForgeHooksClient which actually calls the custom ItemRenderer.render method.
            renderItemIn2D(tessellator, f1, f2, f, f3, iicon.getIconWidth(), iicon.getIconHeight(), 0.0625F);

            if (p_78443_2_.hasEffect(p_78443_3_))
            {
                GL11.glDepthFunc(GL11.GL_EQUAL);
                GL11.glDisable(GL11.GL_LIGHTING);
                texturemanager.bindTexture(RES_ITEM_GLINT);
                GL11.glEnable(GL11.GL_BLEND);
                OpenGlHelper.glBlendFunc(768, 1, 1, 0);
                float f7 = 0.76F;
                GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
                GL11.glMatrixMode(GL11.GL_TEXTURE);
                GL11.glPushMatrix();
                float f8 = 0.125F;
                GL11.glScalef(f8, f8, f8);
                float f9 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
                GL11.glTranslatef(f9, 0.0F, 0.0F);
                GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
                renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
                GL11.glPopMatrix();
                GL11.glPushMatrix();
                GL11.glScalef(f8, f8, f8);
                f9 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
                GL11.glTranslatef(-f9, 0.0F, 0.0F);
                GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
                renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
                GL11.glPopMatrix();
                GL11.glMatrixMode(GL11.GL_MODELVIEW);
                GL11.glDisable(GL11.GL_BLEND);
                GL11.glEnable(GL11.GL_LIGHTING);
                GL11.glDepthFunc(GL11.GL_LEQUAL);
            }

            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
            texturemanager.bindTexture(texturemanager.getResourceLocation(p_78443_2_.getItemSpriteNumber()));
            TextureUtil.func_147945_b();

 

 

Does anybody have an idea why this happens..? I could probably work this out without a custom ItemRenderer. After digging around somewhat in the code I found out that you can return a color from the ItemStack. Yet I really want to find out how and why this happens.

 

Sincerely ~

 

Screenshot of the bug:

VOnBbL3.png

Posted

Hi

 

I reckon it might be an OpenGL render setting carrying over from the last thing that got drawn.  Alpha test is a typical suspect, there are others.

 

I wrote a small tool that I've used in the past to check what the OpenGL settings are; it's not complete, but dumpAllIsEnabled() works and has showed up problems for me before- dump for a good render, dump for a bad render, and spot the difference.  It might be worth a go.

 

https://github.com/TheGreyGhost/SpeedyTools/blob/master/src/speedytools/common/utilities/OpenGLdebugging.java

 

-TGG

 

Posted

Thank God!

 

Thanks to you and your tool I finally found the error. It indeed was the lack of Alpha Testing. Now that I set the flag OpenGL renders the intended background of the hotbar / inventory. This issue made me mad the last 4 days... Once again my issue could be solved within 3 posts, counting mine as well.

 

Cheers!

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.