Jump to content

[SOLVED][1.16.5] rendering item model in container gui


menackni

Recommended Posts

Hello.

 

I am trying to render item in gui like i do it in tileEntityRenderer but it dosent work.

I start digging and experementing, and find that this code work but every thing "excepting ender dragon head" colored red and deephtest only work on full blocks and ender dragon head.

@Override
    public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(ms);
        super.render(ms, mouseX, mouseY, partialTicks);
        this.renderHoveredTooltip(ms, mouseX, mouseY);
        
        Minecraft mc=Minecraft.getInstance();
        ItemRenderer ir=mc.getItemRenderer();
        ItemStack is=container.getInventory().get(0);
        EntityRendererManager er=mc.getRenderManager();
        
        if (!is.isEmpty()){
        	ms.push();
        	
            ms.translate(100, 100, 100);
            ms.rotate(Vector3f.YP.rotationDegrees(3 * (mc.world.getGameTime() % 360 +partialTicks)));
            ms.scale(100, 100, 100);
            
        	IRenderTypeBuffer irtb = mc.getRenderTypeBuffers().getCrumblingBufferSource();
        	
        	ir.renderItem(is, TransformType.GUI, 240, 0, ms, irtb);
        	ir.renderModel(ir.getItemModelWithOverrides(is, mc.world, mc.player), is, 240, 0, ms, irtb.getBuffer(RenderType.getSolid()));
        	
        	ms.pop();
        }
    }

Here some examples:

image.thumb.png.435fe186ed83d980b27471f4fc04df28.png

image.png.73cb1bcb7c33be01f42f2200a60cb371.png

Edited by menackni
Link to comment
Share on other sites

17 minutes ago, ChampionAsh5357 said:

You can look within ContainerScreen to see how ItemStacks are rendered. If this is not the end goal, can you explain in more detail what you are exactly trying to do?

I try draw items like models instead of icons, i already fix deephtest but items still red, i try dig vanilla code and doing like it but it dosent work

@Override
    public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(ms);
        super.render(ms, mouseX, mouseY, partialTicks);
        this.renderHoveredTooltip(ms, mouseX, mouseY);
        
        Minecraft mc=Minecraft.getInstance();
        ItemRenderer ir=mc.getItemRenderer();
        ItemStack is=container.getInventory().get(0);
        
        if (!is.isEmpty()){
        	
        	ms.push();
            ms.translate(100, 100, 100);
            ms.rotate(Vector3f.YP.rotationDegrees(3 * (mc.world.getGameTime() % 360 +partialTicks)));
            ms.scale(100, -100, 100);
            
        	IRenderTypeBuffer.Impl irtb = mc.getRenderTypeBuffers().getCrumblingBufferSource();
        	ir.renderItem(is, TransformType.FIXED, 240, 0, ms, irtb);
        	
        	irtb.finish();
        	ms.pop();
        }
    }

 

Link to comment
Share on other sites

8 minutes ago, menackni said:

I try draw items like models instead of icons, i already fix deephtest but items still red, i try dig vanilla code and doing like it but it dosent work


@Override
    public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(ms);
        super.render(ms, mouseX, mouseY, partialTicks);
        this.renderHoveredTooltip(ms, mouseX, mouseY);
        
        Minecraft mc=Minecraft.getInstance();
        ItemRenderer ir=mc.getItemRenderer();
        ItemStack is=container.getInventory().get(0);
        
        if (!is.isEmpty()){
        	
        	ms.push();
            ms.translate(100, 100, 100);
            ms.rotate(Vector3f.YP.rotationDegrees(3 * (mc.world.getGameTime() % 360 +partialTicks)));
            ms.scale(100, -100, 100);
            
        	IRenderTypeBuffer.Impl irtb = mc.getRenderTypeBuffers().getCrumblingBufferSource();
        	ir.renderItem(is, TransformType.FIXED, 240, 0, ms, irtb);
        	
        	irtb.finish();
        	ms.pop();
        }
    }

 

Also items with enchanted effect cause crash game.

Also also this code work too but dosen draw shadows, enchantments and heads.

ir.renderModel(ir.getItemModelWithOverrides(is, mc.world, mc.player), is, 240, 0, ms, irtb.getBuffer(RenderType.getCutout()));
irtb.finish();

 

Edited by menackni
Link to comment
Share on other sites

1 hour ago, menackni said:

I try draw items like models instead of icons, i already fix deephtest but items still red, i try dig vanilla code and doing like it but it dosent work

The items are models and not icons. They have been rotated, translated, and scaled to that position to be drawn. You still have yet to answer what is the end goal here and why it should be done.

Link to comment
Share on other sites

2 minutes ago, ChampionAsh5357 said:

The items are models and not icons. They have been rotated, translated, and scaled to that position to be drawn. You still have yet to answer what is the end goal here and why it should be done.

I realise that items not icons, but result of renderItemAndEffectIntoGUI(ItemStack, mouseX, mouseY) "look like icon" they work perfectly but cant rotate or scale items with methots that i know.

With renderItem(ItemStack, TransformType, x, y, matrixStack, IRenderTypeBuffer) i can transform items how i want, but for some reasons it color everything red except heads and crash game when i try to put enchanted items.

 

My goal is to make gui where i can rotate and transform items.

Link to comment
Share on other sites

8 minutes ago, ChampionAsh5357 said:

Just remake the method then to take in a preexisting MatrixStack and then modify that as needed. The method does call renderItem after a bit of prework.

Do you mean make like that?  code bolowe render nothing

@Override
    public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(ms);
        super.render(ms, mouseX, mouseY, partialTicks);
        this.renderHoveredTooltip(ms, mouseX, mouseY);
        
        Minecraft mc=Minecraft.getInstance();
        ItemRenderer ir=mc.getItemRenderer();
        ItemStack is=container.getInventory().get(0).copy();
        
        if (!is.isEmpty()){
        	ms.push();
            ms.translate(10, 10, 10);
            ms.rotate(Vector3f.YP.rotationDegrees(3 * (mc.world.getGameTime() % 360 +partialTicks)));
            ms.scale(100, -100, 100);
            IRenderTypeBuffer.Impl irtb =  mc.getRenderTypeBuffers().getCrumblingBufferSource();
            ir.renderItem(is, TransformType.GUI, 240, 0, ms, irtb);
        	ms.pop();
        }
    }

 

Link to comment
Share on other sites

1 hour ago, ChampionAsh5357 said:

That doesn't remake the method. Look at how renderItemAndEffectIntoGUI is defined and rewrite it to take some MatrixStack to define the rotation and/or scale to render.

I try it before but seems i did something wrong, thanks you give this method second chance.

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.



×
×
  • Create New...

Important Information

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