    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        }
    054
    055        @SideOnly(Side.CLIENT)
    056        public int getTabIndex()
    057        {
    058            return this.tabIndex;
    059        }
    060
    061        public CreativeTabs setBackgroundImageName(String par1Str)
    062        {
    063            this.backgroundImageName = par1Str;
    064            return this;
    065        }
    066
    067        @SideOnly(Side.CLIENT)
    068        public String getTabLabel()
    069        {
    070            return this.tabLabel;
    071        }
    072
    073        @SideOnly(Side.CLIENT)
    074
    075        /**
    076         * Gets the translated Label.
    077         */
    078        public String getTranslatedTabLabel()
    079        {
    080            return StringTranslate.getInstance().translateKey("itemGroup." + this.getTabLabel());
    081        }
    082
    083        @SideOnly(Side.CLIENT)
    084        public Item getTabIconItem()
    085        {
    086            return Item.itemsList[this.getTabIconItemIndex()];
    087        }
    088
    089        @SideOnly(Side.CLIENT)
    090
    091        /**
    092         * the itemID for the item to be displayed on the tab
    093         */
    094        public int getTabIconItemIndex()
    095        {
    096            return 1;
    097        }
    098
    099        @SideOnly(Side.CLIENT)
    100        public String getBackgroundImageName()
    101        {
    102            return this.backgroundImageName;
    103        }
    104
    105        @SideOnly(Side.CLIENT)
    106        public boolean drawInForegroundOfTab()
    107        {
    108            return this.drawTitle;
    109        }
    110
    111        public CreativeTabs setNoTitle()
    112        {
    113            this.drawTitle = false;
    114            return this;
    115        }
    116
    117        @SideOnly(Side.CLIENT)
    118        public boolean shouldHidePlayerInventory()
    119        {
    120            return this.hasScrollbar;
    121        }
    122
    123        public CreativeTabs setNoScrollbar()
    124        {
    125            this.hasScrollbar = false;
    126            return this;
    127        }
    128
    129        @SideOnly(Side.CLIENT)
    130
    131        /**
    132         * returns index % 6
    133         */
    134        public int getTabColumn()
    135        {
    136            if (tabIndex > 11)
    137            {
    138                return ((tabIndex - 12) % 10) % 5;
    139            }
    140            return this.tabIndex % 6;
    141        }
    142
    143        @SideOnly(Side.CLIENT)
    144
    145        /**
    146         * returns tabIndex < 6
    147         */
    148        public boolean isTabInFirstRow()
    149        {
    150            if (tabIndex > 11)
    151            {
    152                return ((tabIndex - 12) % 10) < 5;
    153            }
    154            return this.tabIndex < 6;
    155        }
    156
    157        @SideOnly(Side.CLIENT)
    158
    159        /**
    160         * only shows items which have tabToDisplayOn == this
    161         */
    162        public void displayAllReleventItems(List par1List)
    163        {
    164            Item[] var2 = Item.itemsList;
    165            int var3 = var2.length;
    166
    167            for (int var4 = 0; var4 < var3; ++var4)
    168            {
    169                Item var5 = var2[var4];
    170
    171                if (var5 == null)
    172                {
    173                    continue;
    174                }
    175
    176                for(CreativeTabs tab : var5.getCreativeTabs())
    177                {
    178                    if (tab == this)
    179                    {
    180                        var5.getSubItems(var5.shiftedIndex, this, par1List);
    181                    }
    182                }
    183            }
    184        }
    185
    186        public int getTabPage()
    187        {
    188            if (tabIndex > 11)
    189            {
    190                return ((tabIndex - 12) / 10) + 1;
    191            }
    192            return 0;
    193        }
    194
    195        public static int getNextID()
    196        {
    197            return creativeTabArray.length;
    198        }
    199
    200        /**
    201         * Get the ItemStack that will be rendered to the tab.
    202         */
    203        public ItemStack getIconItemStack()
    204        {
    205            return new ItemStack(getTabIconItem());
    206        }
    207    }