Jump to content

[1.10.2]GuiContainer: draw texture in foreground of an item in slot


Mark136

Recommended Posts

Hello all,

 

i'm currently busy with creating a custom Crafting table, and i want to show the craftable items in the gui.

i have a gui that shows 4 colums and 5 rows slots and i want to extend it with scrolling(more colums), like in the creative tab.

 

but i have no idea how to begin.

do i need to add a buttom (like guiSlider) or something like that? 

or is it just trying to understand whats in the GuiContainerCreative class?

 

EDIT: done with the scrollbar, i now need to know how to draw a texture in the foreground if an Item in a slot

 

 

 

my Mod: Extended RPG [W.I.P]

Link to comment
Share on other sites

  • 2 weeks later...

yeah! i did it, but now have some other things what i don't understand, i want blacken/fading out a slot, as some conditions are true, this is possible with OpenGL, right?

 

and i want to know how to hide an item in the slot without removing the item from the slot. i mean, it needs to be hidden behind a texture. how do i do that?

drawGuiContainerForegroundLayer only hides that white glow when i hovering with my mouse on the slot.

my Mod: Extended RPG [W.I.P]

Link to comment
Share on other sites

yeah! i did it, but now have some other things what i don't understand, i want blacken/fading out a slot, as some conditions are true, this is possible with OpenGL, right?

 

and i want to know how to hide an item in the slot without removing the item from the slot. i mean, it needs to be hidden behind a texture. how do i do that?

drawGuiContainerForegroundLayer only hides that white glow when i hovering with my mouse on the slot.

You will have to draw something to the screen over it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

i want blacken/fading out a slot, as some conditions are true, this is possible with OpenGL, right?

 

Just draw something else over the top.

I do something similar here:

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/industry/client/gui/GuiContainerFilter.java#L67-L71

It draws a section of the gui texture I already have over the slots (and behind items) any time the TE says that it doesn't have any filters (i.e. your "when some condition is true").  The visual ends up looking like this:

 

width=352 height=320http://vignette1.wikia.nocookie.net/reasonable-realism/images/7/73/Filter_no.png/revision/latest?cb=20150419162009[/img]

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

i don't think you understand what i mean, i also want to draw the texture over the Item in the slot,

 

currently i can make the slot darker but the item in the slot still pushing to the top of everything, giving me a dark slot background. but the item is still in the front.

 

i don't have an idea how to simply draw something over a slot with an item in it.

my Mod: Extended RPG [W.I.P]

Link to comment
Share on other sites

i don't think you understand what i mean

 

Yes I do.

And I don't know if you can draw over the item.  I was telling you how I did something similar.  You would probably need to override drawScreen and possibly replace drawSlot.

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

I think your right Draco18s, DrawItemStack is called after drawGuiContainerForegroundLayer

and drawSlot is private, also DrawItemStack and isMouseOverSlot are private.

 

so there is'nt no other way  :'( 

 

then I have a lot of work to do.  :-\

my Mod: Extended RPG [W.I.P]

Link to comment
Share on other sites

i see some z values in drawItemStack : zLevel and ItemRender.zLevel.

and some translate stuff what sets the z index to 32:

private void drawItemStack(ItemStack stack, int x, int y, String altText)
    {
        GlStateManager.translate(0.0F, 0.0F, 32.0F);
        this.zLevel = 200.0F;
        this.itemRender.zLevel = 200.0F;
        net.minecraft.client.gui.FontRenderer font = null;
        if (stack != null) font = stack.getItem().getFontRenderer(stack);
        if (font == null) font = fontRendererObj;
        this.itemRender.renderItemAndEffectIntoGUI(stack, x, y);
        this.itemRender.renderItemOverlayIntoGUI(font, stack, x, y - (this.draggedStack == null ? 0 : , altText);
        this.zLevel = 0.0F;
        this.itemRender.zLevel = 0.0F;
    }

 

and here some code of the minecraft GuiContainer#drawScreen :

 

 public void drawScreen(int mouseX, int mouseY, float partialTicks)
    {
        this.drawDefaultBackground();
        int i = this.guiLeft;
        int j = this.guiTop;
        this.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
        GlStateManager.disableRescaleNormal();
        RenderHelper.disableStandardItemLighting();
        GlStateManager.disableLighting();
        GlStateManager.disableDepth();
        super.drawScreen(mouseX, mouseY, partialTicks);
        RenderHelper.enableGUIStandardItemLighting();
        GlStateManager.pushMatrix();
        GlStateManager.translate((float)i, (float)j, 0.0F);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.enableRescaleNormal();
        this.theSlot = null;
        int k = 240;
        int l = 240;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

        for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
        {
            Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
            this.drawSlot(slot);

            if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canBeHovered())
            {
                this.theSlot = slot;
                GlStateManager.disableLighting();
                GlStateManager.disableDepth();
                int j1 = slot.xDisplayPosition;
                int k1 = slot.yDisplayPosition;
                GlStateManager.colorMask(true, true, true, false);
                this.drawGradientRect(j1, k1, j1 + 16, k1 + 16, -2130706433, -2130706433);
                GlStateManager.colorMask(true, true, true, true);
                GlStateManager.enableLighting();
                GlStateManager.enableDepth();
            }
        }

        RenderHelper.disableStandardItemLighting();
        this.drawGuiContainerForegroundLayer(mouseX, mouseY);
        RenderHelper.enableGUIStandardItemLighting();
        InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;
        ItemStack itemstack = this.draggedStack == null ? inventoryplayer.getItemStack() : this.draggedStack;

        if (itemstack != null)
        {
            int j2 = 8;
            int k2 = this.draggedStack == null ? 8 : 16;
            String s = null;

            if (this.draggedStack != null && this.isRightMouseClick)
            {
                itemstack = itemstack.copy();
                itemstack.stackSize = MathHelper.ceiling_float_int((float)itemstack.stackSize / 2.0F);
            }
            else if (this.dragSplitting && this.dragSplittingSlots.size() > 1)
            {
                itemstack = itemstack.copy();
                itemstack.stackSize = this.dragSplittingRemnant;

                if (itemstack.stackSize == 0)
                {
                    s = "" + TextFormatting.YELLOW + "0";
                }
            }

            this.drawItemStack(itemstack, mouseX - i - 8, mouseY - j - k2, s);
        }

        if (this.returningStack != null)
        {
            float f = (float)(Minecraft.getSystemTime() - this.returningStackTime) / 100.0F;

            if (f >= 1.0F)
            {
                f = 1.0F;
                this.returningStack = null;
            }

            int l2 = this.returningStackDestSlot.xDisplayPosition - this.touchUpX;
            int i3 = this.returningStackDestSlot.yDisplayPosition - this.touchUpY;
            int l1 = this.touchUpX + (int)((float)l2 * f);
            int i2 = this.touchUpY + (int)((float)i3 * f);
            this.drawItemStack(this.returningStack, l1, i2, (String)null);
        }

        GlStateManager.popMatrix();

        if (inventoryplayer.getItemStack() == null && this.theSlot != null && this.theSlot.getHasStack())
        {
            ItemStack itemstack1 = this.theSlot.getStack();
            this.renderToolTip(itemstack1, mouseX, mouseY);
        }

        GlStateManager.enableLighting();
        GlStateManager.enableDepth();
        RenderHelper.enableStandardItemLighting();
    }

 

are the z values responsible for that the Items are always in front?

my Mod: Extended RPG [W.I.P]

Link to comment
Share on other sites

are the z values responsible for that the Items are always in front?

 

I am working off of 1.7.10 but perhaps this will still offer some relevance.  I ran into an issue with overlays with an inventory container, I wanted to overlay a progress indicator over the item stack, I ran into some issues but I resolved by turning off depth test:

 

            GL11.glDisable(GL11.GL_LIGHTING);
            GL11.glDisable(GL11.GL_DEPTH_TEST);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glColorMask(true, true, true, false);

            mc.renderEngine.bindTexture(dialog);

            // Draw progress overlay
         
            GL11.glEnable(GL11.GL_DEPTH_TEST);
            GL11.glEnable(GL11.GL_LIGHTING);

 

As for hiding your item, it seems to me that you could accomplish that by enabling a blend function before the item stack is rendered with source GL_ZERO and destination GL_DST_COLOR and then disable the blend function after the item stack is rendered.

Link to comment
Share on other sites

I think your right Draco18s, DrawItemStack is called after drawGuiContainerForegroundLayer

and drawSlot is private, also DrawItemStack and isMouseOverSlot are private.

 

so there is'nt no other way  :'( 

 

then I have a lot of work to do.  :-\

Draw ItemStack is indeed called after drawContainerForeground, but drawSlots is called before drawContainerForeground so all you need to do is change the zLevel field in your gui before and then after you draw your texture/image aver the slots.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.