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