001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    
006    import java.util.Arrays;
007    import java.util.List;
008    
009    public class CreativeTabs
010    {
011        public static CreativeTabs[] creativeTabArray = new CreativeTabs[12];
012        public static final CreativeTabs tabBlock = new CreativeTabBlock(0, "buildingBlocks");
013        public static final CreativeTabs tabDecorations = new CreativeTabDeco(1, "decorations");
014        public static final CreativeTabs tabRedstone = new CreativeTabRedstone(2, "redstone");
015        public static final CreativeTabs tabTransport = new CreativeTabTransport(3, "transportation");
016        public static final CreativeTabs tabMisc = new CreativeTabMisc(4, "misc");
017        public static final CreativeTabs tabAllSearch = (new CreativeTabSearch(5, "search")).setBackgroundImageName("search.png");
018        public static final CreativeTabs tabFood = new CreativeTabFood(6, "food");
019        public static final CreativeTabs tabTools = new CreativeTabTools(7, "tools");
020        public static final CreativeTabs tabCombat = new CreativeTabCombat(8, "combat");
021        public static final CreativeTabs tabBrewing = new CreativeTabBrewing(9, "brewing");
022        public static final CreativeTabs tabMaterials = new CreativeTabMaterial(10, "materials");
023        public static final CreativeTabs tabInventory = (new CreativeTabInventory(11, "inventory")).setBackgroundImageName("survival_inv.png").setNoScrollbar().setNoTitle();
024        private final int tabIndex;
025        private final String tabLabel;
026    
027        /** Texture to use. */
028        private String backgroundImageName = "list_items.png";
029        private boolean hasScrollbar = true;
030    
031        /** Whether to draw the title in the foreground of the creative GUI */
032        private boolean drawTitle = true;
033    
034        public CreativeTabs(String label)
035        {
036            this(getNextID(), label);
037        }
038    
039        public CreativeTabs(int par1, String par2Str)
040        {
041            if (par1 >= creativeTabArray.length)
042            {
043                CreativeTabs[] tmp = new CreativeTabs[par1 + 1];
044                for (int x = 0; x < creativeTabArray.length; x++)
045                {
046                    tmp[x] = creativeTabArray[x];
047                }
048                creativeTabArray = tmp;
049            }
050            this.tabIndex = par1;
051            this.tabLabel = par2Str;
052            creativeTabArray[par1] = this;
053            if (par1 == 11)
054            {
055                new CreativeTabs("1");
056                new CreativeTabs("2");
057                new CreativeTabs("3");
058                new CreativeTabs("4");
059            }
060        }
061    
062        @SideOnly(Side.CLIENT)
063        public int getTabIndex()
064        {
065            return this.tabIndex;
066        }
067    
068        public CreativeTabs setBackgroundImageName(String par1Str)
069        {
070            this.backgroundImageName = par1Str;
071            return this;
072        }
073    
074        @SideOnly(Side.CLIENT)
075        public String getTabLabel()
076        {
077            return this.tabLabel;
078        }
079    
080        @SideOnly(Side.CLIENT)
081    
082        /**
083         * Gets the translated Label.
084         */
085        public String getTranslatedTabLabel()
086        {
087            return StringTranslate.getInstance().translateKey("itemGroup." + this.getTabLabel());
088        }
089    
090        @SideOnly(Side.CLIENT)
091        public Item getTabIconItem()
092        {
093            return Item.itemsList[this.getTabIconItemIndex()];
094        }
095    
096        @SideOnly(Side.CLIENT)
097    
098        /**
099         * the itemID for the item to be displayed on the tab
100         */
101        public int getTabIconItemIndex()
102        {
103            return 1;
104        }
105    
106        @SideOnly(Side.CLIENT)
107        public String getBackgroundImageName()
108        {
109            return this.backgroundImageName;
110        }
111    
112        @SideOnly(Side.CLIENT)
113        public boolean drawInForegroundOfTab()
114        {
115            return this.drawTitle;
116        }
117    
118        public CreativeTabs setNoTitle()
119        {
120            this.drawTitle = false;
121            return this;
122        }
123    
124        @SideOnly(Side.CLIENT)
125        public boolean shouldHidePlayerInventory()
126        {
127            return this.hasScrollbar;
128        }
129    
130        public CreativeTabs setNoScrollbar()
131        {
132            this.hasScrollbar = false;
133            return this;
134        }
135    
136        @SideOnly(Side.CLIENT)
137    
138        /**
139         * returns index % 6
140         */
141        public int getTabColumn()
142        {
143            if (tabIndex > 11)
144            {
145                return ((tabIndex - 12) % 10) % 5;
146            }
147            return this.tabIndex % 6;
148        }
149    
150        @SideOnly(Side.CLIENT)
151    
152        /**
153         * returns tabIndex < 6
154         */
155        public boolean isTabInFirstRow()
156        {
157            if (tabIndex > 11)
158            {
159                return ((tabIndex - 12) % 10) < 5;
160            }
161            return this.tabIndex < 6;
162        }
163    
164        @SideOnly(Side.CLIENT)
165    
166        /**
167         * only shows items which have tabToDisplayOn == this
168         */
169        public void displayAllReleventItems(List par1List)
170        {
171            Item[] var2 = Item.itemsList;
172            int var3 = var2.length;
173    
174            for (int var4 = 0; var4 < var3; ++var4)
175            {
176                Item var5 = var2[var4];
177    
178                if (var5 != null && var5.getCreativeTab() == this)
179                {
180                    var5.getSubItems(var5.shiftedIndex, this, par1List);
181                }
182            }
183        }
184    
185        public int getTabPage()
186        {
187            if (tabIndex > 11)
188            {
189                return ((tabIndex - 12) / 10) + 1;
190            }
191            return 0;
192        }
193    
194        public static int getNextID()
195        {
196            return creativeTabArray.length;
197        }
198    
199        /**
200         * Get the ItemStack that will be rendered to the tab.
201         */
202        public ItemStack getIconItemStack()
203        {
204            return new ItemStack(getTabIconItem());
205        }
206    }