Jump to content

Make GuiScreen.buttonList public


Cakestory

Recommended Posts

Hi,

mods like Tinkers Construct and Galacticraft add custom Inventory Tabs (like the ones in creative) to the players survival inventory. Making all these differnt mod tabs compatible with each other takes a lot of time for the mod authors or is not even possible if the one or more of the mods is not open source. If it is open source it takes a long time to look through the other modders code.

 

It would be awesome if Forge could provide an easy way to add Tabs to the survival inventory in order to solve this problem.

 

 

I solved the problem by using Java reflection, but it would be really useful if you could make GuiScreen.buttonList a public field.

 

 

Link to comment
Share on other sites

I know what he's talking about, I want him to think about his proposal more and come back with something more fleshed out about how it would be done.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

The only thing that Forge could do to ease the process would be to make GuiScreen.buttonList public.

 

That would be really helpful. I had a more detailed look at TinkersConstruct´s TabRegistry class and that is the code they use to add their Tab buttons to the inventory screen (called when the inventory key is used):

 

public static void addTabsToInventory (GuiContainer gui)
    {
        if (gui.getClass() == GuiInventory.class)
        {
            // Values are public at runtime.
            int cornerX = gui.xSize;
            int cornerY = gui.guiTop;
            gui.buttonList.clear();

            updateTabValues(cornerX, cornerY, InventoryTabVanilla.class);
            addTabsToList(gui.buttonList);
        }
    }

public static void updateTabValues (int cornerX, int cornerY, Class<?> selectedButton)
    {
        int count = 2;
        for (int i = 0; i < tabList.size(); i++)
        {
            AbstractTab t = tabList.get(i);

            if (t.shouldAddToList())
            {
                t.id = count;
                t.xPosition = cornerX + (count - 2) * 28;
                t.yPosition = cornerY - 28;
                t.enabled = !t.getClass().equals(selectedButton);
                count++;
            }
        }
    }

    public static void addTabsToList (List buttonList)
    {
        for (AbstractTab tab : tabList)
        {
            if (tab.shouldAddToList())
            {
                buttonList.add(tab);
            }
        }
    }

 

Here is the full class:

https://github.com/SlimeKnights/TinkersConstruct/blob/master/src/main/java/tconstruct/client/tabs/TabRegistry.java

 

As the comment says the values are all public at runtime. I must admit that I am just coding Java for a year now and have no direct idea on how this is handled at runtime, but as

GuiInventory.xSize
GuiInventory.ySize
GuiInventory.guiTop
GuiInventory.guiBottom
GuiInventory.buttonList

are not public fields there is no direct way to use them (without working around it).

 

I would like to suggest making these fields "public" unless you see a problem in doing this. (I don´t know if there is a reason they are not public yet?)

   

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.