-
Notifications
You must be signed in to change notification settings - Fork 755
/
TabRegistry.java
77 lines (66 loc) · 2.07 KB
/
TabRegistry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package tconstruct.client.tabs;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiInventory;
import cpw.mods.fml.client.FMLClientHandler;
public class TabRegistry
{
private static ArrayList<AbstractTab> tabList = new ArrayList<AbstractTab>();
public static void registerTab (AbstractTab tab)
{
tabList.add(tab);
}
public static ArrayList<AbstractTab> getTabList ()
{
return tabList;
}
public static void addTabsToInventory (GuiContainer gui)
{
if (gui.getClass() == GuiInventory.class)
{
//Values are public at runtime.
int cornerX = gui.guiLeft;
int cornerY = gui.guiTop;
gui.buttonList.clear();
updateTabValues(cornerX, cornerY, InventoryTabVanilla.class);
addTabsToList(gui.buttonList);
}
}
private static Minecraft mc = FMLClientHandler.instance().getClient();
public static void openInventoryGui ()
{
GuiInventory inventory = new GuiInventory(mc.thePlayer);
mc.displayGuiScreen(inventory);
TabRegistry.addTabsToInventory(inventory);
}
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);
}
}
}
}