Jump to content

[1.12.2] Render block in GUI


Recommended Posts

I'm trying to render a block in my GUI, but it seems to have no lighting like it normally does in the inventory. Any idea what I need to do?



    private void drawItemStack(ItemStack stack, int x, int y)
        GlStateManager.translate(0.0F, 0.0F, 32.0F);
        GL11.glScalef(4.0F, 4.0F, 0.0F);
        this.zLevel = 200.0F;
        this.itemRender.zLevel = 200.0F;
        net.minecraft.client.gui.FontRenderer font = stack.getItem().getFontRenderer(stack);
        if (font == null) font = fontRenderer;
        this.itemRender.renderItemIntoGUI(stack, x, y);
        this.itemRender.renderItemOverlayIntoGUI(font, stack, x, y, "");
        GL11.glScalef(1.0F, 1.0F, 1.0F);
        this.zLevel = 0.0F;
        this.itemRender.zLevel = 0.0F;



Not sure why this image looks faded, but you can see the difference between the one in the inventory down at the bottom, and the one I'm trying to render up at the top. Also sorry for the extra image at the bottom. Apparently you can't delete an image once you've attached it to the post.





Edited by Daeruin
Link to comment
Share on other sites

Yes, that worked! Although it doesn't quite look the same as in the inventory. The lighting is a bit different. Anyway, thanks for the help. I'm in the dark with this rendering stuff.

Should I be rendering this in the foreground or background layer? When I do it in the foreground, I can no longer see items when I pick them up with the mouse. When I do it in the background, the basket appears clear in the upper left corner of the screen, and all my foreground stuff disappears. I have no idea what's going on with that.


Another weird thing is that now I'm noticing the front left wall of the basket is missing.

Link to comment
Share on other sites

You are most likely messing up some GL state. For example...

27 minutes ago, Daeruin said:

GL11.glScalef(4.0F, 4.0F, 0.0F);


27 minutes ago, Daeruin said:

GL11.glScalef(1.0F, 1.0F, 1.0F);

This is not how GL scaling works. Scaling by 1,1,1 is doing nothing. Think of it as currentScale * passedVector. If you scale by 1 then you are doing currentScale * 1 which is currentScale. In order to scale back use 1 / scaleUsed, in your case this would be 1 / 4 = 0.25.

The rendering layer doesn't matter. It is all done in one method, but the background is rendered first.


13 minutes ago, Daeruin said:

The lighting is a bit different.

Experiment with enable/disable lighting and OpenGlHelper.setLightmapTextureCoords


13 minutes ago, Daeruin said:

Another weird thing is that now I'm noticing the front left wall of the basket is missing.

Experiment with depthtest(GlStateManager.enable/disableDepth). I can't remember of the top of my head whether MC uses depth testing for rendering items or not.

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.

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.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.