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