Jump to content

How to draw GUI button behind the Inventory


billybobpumpkin

Recommended Posts

Can someone help me on this? I have really worked hard to try and find a solution but to no avail.

 

What I want:

helpme2.PNG.6bcca039b138b2e69aab4d9a8a2564ec.PNG

What I have (player inventory):

helpme.PNG.19e906b0e99e53ee442052345736e5b7.PNG

Code, RIP clean code:

Tab class:

public static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
	
	ItemStack renderStack;
	protected RenderItem itemRender;
	
	int guiLeft;
	int guiTop;
	
	int ySize;
	int xSize;
	
	GuiButton currentButton;
	
	public void setCurrentButton(GuiButton button)
	{
		this.currentButton = button;
	}
	
	public GuiButton getButton()
	{
		return this.currentButton;
	}
	
	public void setItem(ItemStack item)
	{
		this.renderStack = item;
	}
	
	public ItemStack getItem()
	{
		return this.renderStack;
	}
	
	public AbstractTab(int buttonId, int x, int y, ItemStack renderStack)
	{
		super(buttonId, x, y, 28, 32, "");
		this.ySize = 136;
        this.xSize = 195;
		this.renderStack = renderStack;
		this.itemRender = FMLClientHandler.instance().getClient().getRenderItem();
		this.guiLeft = (this.width - this.xSize) / 2;
        this.guiTop = (this.height - this.ySize) / 2;
	}

	@Override
	public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
	{
		if(visible)
		{
			drawInventoryTab(mc, mouseX, mouseY, partialTicks);
		}
	}
	
	protected void drawInventoryTab(Minecraft mc, int mouseX, int mouseY, float partialTicks)
    {
		CreativeTabs tab = CreativeTabs.INVENTORY;
		//mc.renderEngine.bindTexture(TEXTURE_LOCATION);
		mc.getTextureManager().bindTexture(TEXTURE_LOCATION);
        boolean flag = true;//tab.getTabIndex() == selectedTabIndex;
        boolean flag1 = tab.isTabInFirstRow();
        int i = 32;
        int j = i * 28;
        int k = 0;
        int l = this.guiLeft + 28 * i;
        int i1 = this.guiTop;
        int j1 = 32;

        if (flag)
        {
            k += 32;
        }

        if (tab.isAlignedRight())
        {
            l = this.guiLeft + this.xSize - 28 * (6 - i);
        }
        else if (i > 0)
        {
            l += i;
        }

        if (flag1)
        {
            i1 = i1 - 28;
        }
        else
        {
            k += 64;
            i1 = i1 + (this.ySize - 4);
        }
        
        //for(AbstractTab abstractTab : RegisterTabs.tabList)
        //{
        	//int p = 0;
        	//int index = (RegisterTabs.tabList.get(0).getId() + 150);
        	RenderHelper.enableGUIStandardItemLighting();
	        GlStateManager.pushMatrix();
	        GlStateManager.disableLighting();
	        GlStateManager.color(1F, 1F, 1F); //Forge: Reset color in case Items change it.
	        GlStateManager.enableBlend(); //Forge: Make sure blend is enabled else tabs show a white border.
	        GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
	        //130, 10, 112, 32, 28, 32
	        for(AbstractTab abstractTab : RegisterTabs.tabList)
	        {
	        	int index = 105 + (abstractTab.getId() * 28);
	        	
	        	if(this.currentButton == abstractTab)
	        	{
	        		this.zLevel = 100f;
	        		this.drawTexturedModalRect(index, 10, 112, 32, 28, 32); //l, i1, j, k, 28, 32
	        	}
	        	else
	        	{
	        		this.zLevel = 0f;
	        		this.drawTexturedModalRect(index, 10, 112, 0, 28, 32);
				}
	        }
	        
	        //this.zLevel = 100.0F;
	        this.itemRender.zLevel = 100.0F;
	        l = l + 6;
	        i1 = i1 + 8 + (flag1 ? 1 : -1);
	        GlStateManager.enableLighting();
	        GlStateManager.enableRescaleNormal();
	        GlStateManager.disableBlend();
	        
	        this.itemRender.renderItemAndEffectIntoGUI(new ItemStack(Blocks.CRAFTING_TABLE), 138, 19);
	        this.itemRender.renderItemOverlays(mc.fontRenderer, new ItemStack(Blocks.CRAFTING_TABLE), 138, 19);
	        
	        this.itemRender.renderItemAndEffectIntoGUI(new ItemStack(ItemInit.WRITTEN_PAPAR), 167, 19);
	        this.itemRender.renderItemOverlays(mc.fontRenderer, new ItemStack(ItemInit.WRITTEN_PAPAR), 167, 19);
	        
	        GlStateManager.disableLighting();
	        this.itemRender.zLevel = 0.0F;
	        //this.zLevel = 0.0F;
	        GlStateManager.popMatrix();
	       // p++;
        //}
    }
	
	public abstract int getId();
	
	public void setSelected(GuiButton s)
	{
		this.currentButton = s;
	}

 

 

Register class:

public static List<AbstractTab> tabList = new ArrayList<AbstractTab>();
	
	private static final Minecraft minecraft = Minecraft.getMinecraft();
	
	private static void addTabToList(List<GuiButton> buttonList)
	{
		for(AbstractTab tab : tabList)
		{
			buttonList.add(tab);
		}
	}
	
	private static void updateTabValues(int cornerX, int cornerY)
	{
		for (int i = 0; i < tabList.size(); i++)
		{
			int id = 2;
			AbstractTab tab = tabList.get(i);
			
			tab.guiLeft = cornerX + (id - 2) * 28;
			tab.guiTop = cornerY - 28;
			tab.setSelected(tabList.get(0));
			id++;
		}
	}
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public static void guiPostInitialize(GuiScreenEvent.InitGuiEvent.Post event)
	{
		tabList.clear();
		tabList.add(new InventoryTab());
		tabList.add(new InventoryQuests());
		
		tabList.get(0).setItem(new ItemStack(Blocks.CRAFTING_TABLE));
		tabList.get(1).setItem(new ItemStack(ItemInit.WRITTEN_PAPAR));
		
		
		if(event.getGui() instanceof GuiInventory)
		{
			GuiInventory guiInventory = (GuiInventory)event.getGui();
			int guiLeft = guiInventory.width - 176 / 2;
			int guiTop = guiInventory.height - 166 / 2;
			
			updateTabValues(guiLeft, guiTop);
			addTabToList(event.getButtonList());
		}
	}
	
	@SubscribeEvent
	public static void guiPostAction(GuiScreenEvent.ActionPerformedEvent.Post event)
	{
		GuiButton button = event.getButton();
		
		if(button instanceof AbstractTab)
		{
			AbstractTab abstractTab = (AbstractTab)button;
			
			switch (abstractTab.getId())
			{
				case 1:
					for (int i = 0; i < tabList.size(); i++)
					{
						tabList.get(i).setCurrentButton(tabList.get(0));
						tabList.get(i).setItem(new ItemStack(Blocks.CRAFTING_TABLE));
					}
					event.getGui().mc.displayGuiScreen(new GuiInventory(event.getGui().mc.player));
					break;
					
				case 2:
					for (int i = 0; i < tabList.size(); i++)
					{
						tabList.get(i).setCurrentButton(tabList.get(1));
						tabList.get(i).setItem(new ItemStack(ItemInit.WRITTEN_PAPAR));
					}
					break;
					
				default:
					break;
			}
		}
	}

 

I know it is extremely messy and some places can be changed but I am only looking for how to draw a tab behind the inventory GUI.

Link to comment
Share on other sites

It depends on the order in which things are drawn, by default.

You can either draw the tab before everything else draws (the feasibility of this depends on where your draw method's called), trim the texture so that it doesn't poke past where it ought to (or the equivalent with u/v changes), or do some funny business with Gui#zLevel. Gui#drawTexturedModalRect() draws at the current zLevel, so you should be able to altar that value (and then reset it) if you're in the right situation (it's protected).

 

Also, if you're using Eclipse, Ctrl+Shift+F is your friend (code formatter). You can set it up in the preferences somewhere.

Edited by SerpentDagger

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

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.