| 1 | package net.minecraft.creativetab;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.block.BlockDoublePlant;
|
| 5 | import net.minecraft.enchantment.Enchantment;
|
| 6 | import net.minecraft.enchantment.EnchantmentData;
|
| 7 | import net.minecraft.enchantment.EnumEnchantmentType;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.init.Items;
|
| 10 | import net.minecraft.item.Item;
|
| 11 | import net.minecraft.item.ItemStack;
|
| 12 |
|
| 13 | public abstract class CreativeTabs
|
| 14 | {
|
| 15 | public static final CreativeTabs[] creativeTabArray = new CreativeTabs[12];
|
| 16 | public static final CreativeTabs tabBlock = new CreativeTabs(0, "buildingBlocks")
|
| 17 | {
|
| 18 | public Item getTabIconItem()
|
| 19 | {
|
| 20 | return Item.getItemFromBlock(Blocks.brick_block);
|
| 21 | }
|
| 22 | };
|
| 23 | public static final CreativeTabs tabDecorations = new CreativeTabs(1, "decorations")
|
| 24 | {
|
| 25 | public Item getTabIconItem()
|
| 26 | {
|
| 27 | return Item.getItemFromBlock(Blocks.double_plant);
|
| 28 | }
|
| 29 | public int getIconItemDamage()
|
| 30 | {
|
| 31 | return BlockDoublePlant.EnumPlantType.PAEONIA.getMeta();
|
| 32 | }
|
| 33 | };
|
| 34 | public static final CreativeTabs tabRedstone = new CreativeTabs(2, "redstone")
|
| 35 | {
|
| 36 | public Item getTabIconItem()
|
| 37 | {
|
| 38 | return Items.redstone;
|
| 39 | }
|
| 40 | };
|
| 41 | public static final CreativeTabs tabTransport = new CreativeTabs(3, "transportation")
|
| 42 | {
|
| 43 | public Item getTabIconItem()
|
| 44 | {
|
| 45 | return Item.getItemFromBlock(Blocks.golden_rail);
|
| 46 | }
|
| 47 | };
|
| 48 | public static final CreativeTabs tabMisc = (new CreativeTabs(4, "misc")
|
| 49 | {
|
| 50 | public Item getTabIconItem()
|
| 51 | {
|
| 52 | return Items.lava_bucket;
|
| 53 | }
|
| 54 | }).setRelevantEnchantmentTypes(new EnumEnchantmentType[] {EnumEnchantmentType.ALL});
|
| 55 | public static final CreativeTabs tabAllSearch = (new CreativeTabs(5, "search")
|
| 56 | {
|
| 57 | public Item getTabIconItem()
|
| 58 | {
|
| 59 | return Items.compass;
|
| 60 | }
|
| 61 | }).setBackgroundImageName("item_search.png");
|
| 62 | public static final CreativeTabs tabFood = new CreativeTabs(6, "food")
|
| 63 | {
|
| 64 | public Item getTabIconItem()
|
| 65 | {
|
| 66 | return Items.apple;
|
| 67 | }
|
| 68 | };
|
| 69 | public static final CreativeTabs tabTools = (new CreativeTabs(7, "tools")
|
| 70 | {
|
| 71 | public Item getTabIconItem()
|
| 72 | {
|
| 73 | return Items.iron_axe;
|
| 74 | }
|
| 75 | }).setRelevantEnchantmentTypes(new EnumEnchantmentType[] {EnumEnchantmentType.DIGGER, EnumEnchantmentType.FISHING_ROD, EnumEnchantmentType.BREAKABLE});
|
| 76 | public static final CreativeTabs tabCombat = (new CreativeTabs(8, "combat")
|
| 77 | {
|
| 78 | public Item getTabIconItem()
|
| 79 | {
|
| 80 | return Items.golden_sword;
|
| 81 | }
|
| 82 | }).setRelevantEnchantmentTypes(new EnumEnchantmentType[] {EnumEnchantmentType.ARMOR, EnumEnchantmentType.ARMOR_FEET, EnumEnchantmentType.ARMOR_HEAD, EnumEnchantmentType.ARMOR_LEGS, EnumEnchantmentType.ARMOR_TORSO, EnumEnchantmentType.BOW, EnumEnchantmentType.WEAPON});
|
| 83 | public static final CreativeTabs tabBrewing = new CreativeTabs(9, "brewing")
|
| 84 | {
|
| 85 | public Item getTabIconItem()
|
| 86 | {
|
| 87 | return Items.potionitem;
|
| 88 | }
|
| 89 | };
|
| 90 | public static final CreativeTabs tabMaterials = new CreativeTabs(10, "materials")
|
| 91 | {
|
| 92 | public Item getTabIconItem()
|
| 93 | {
|
| 94 | return Items.stick;
|
| 95 | }
|
| 96 | };
|
| 97 | public static final CreativeTabs tabInventory = (new CreativeTabs(11, "inventory")
|
| 98 | {
|
| 99 | public Item getTabIconItem()
|
| 100 | {
|
| 101 | return Item.getItemFromBlock(Blocks.chest);
|
| 102 | }
|
| 103 | }).setBackgroundImageName("inventory.png").setNoScrollbar().setNoTitle();
|
| 104 | private final int tabIndex;
|
| 105 | private final String tabLabel;
|
| 106 |
|
| 107 | /** Texture to use. */
|
| 108 | private String theTexture = "items.png";
|
| 109 | private boolean hasScrollbar = true;
|
| 110 |
|
| 111 | /** Whether to draw the title in the foreground of the creative GUI */
|
| 112 | private boolean drawTitle = true;
|
| 113 | private EnumEnchantmentType[] enchantmentTypes;
|
| 114 | private ItemStack iconItemStack;
|
| 115 |
|
| 116 | public CreativeTabs(int index, String label)
|
| 117 | {
|
| 118 | this.tabIndex = index;
|
| 119 | this.tabLabel = label;
|
| 120 | creativeTabArray[index] = this;
|
| 121 | }
|
| 122 |
|
| 123 | public int getTabIndex()
|
| 124 | {
|
| 125 | return this.tabIndex;
|
| 126 | }
|
| 127 |
|
| 128 | public String getTabLabel()
|
| 129 | {
|
| 130 | return this.tabLabel;
|
| 131 | }
|
| 132 |
|
| 133 | /**
|
| 134 | * Gets the translated Label.
|
| 135 | */
|
| 136 | public String getTranslatedTabLabel()
|
| 137 | {
|
| 138 | return "itemGroup." + this.getTabLabel();
|
| 139 | }
|
| 140 |
|
| 141 | public ItemStack getIconItemStack()
|
| 142 | {
|
| 143 | if (this.iconItemStack == null)
|
| 144 | {
|
| 145 | this.iconItemStack = new ItemStack(this.getTabIconItem(), 1, this.getIconItemDamage());
|
| 146 | }
|
| 147 |
|
| 148 | return this.iconItemStack;
|
| 149 | }
|
| 150 |
|
| 151 | public abstract Item getTabIconItem();
|
| 152 |
|
| 153 | public int getIconItemDamage()
|
| 154 | {
|
| 155 | return 0;
|
| 156 | }
|
| 157 |
|
| 158 | public String getBackgroundImageName()
|
| 159 | {
|
| 160 | return this.theTexture;
|
| 161 | }
|
| 162 |
|
| 163 | public CreativeTabs setBackgroundImageName(String texture)
|
| 164 | {
|
| 165 | this.theTexture = texture;
|
| 166 | return this;
|
| 167 | }
|
| 168 |
|
| 169 | public boolean drawInForegroundOfTab()
|
| 170 | {
|
| 171 | return this.drawTitle;
|
| 172 | }
|
| 173 |
|
| 174 | public CreativeTabs setNoTitle()
|
| 175 | {
|
| 176 | this.drawTitle = false;
|
| 177 | return this;
|
| 178 | }
|
| 179 |
|
| 180 | public boolean shouldHidePlayerInventory()
|
| 181 | {
|
| 182 | return this.hasScrollbar;
|
| 183 | }
|
| 184 |
|
| 185 | public CreativeTabs setNoScrollbar()
|
| 186 | {
|
| 187 | this.hasScrollbar = false;
|
| 188 | return this;
|
| 189 | }
|
| 190 |
|
| 191 | /**
|
| 192 | * returns index % 6
|
| 193 | */
|
| 194 | public int getTabColumn()
|
| 195 | {
|
| 196 | return this.tabIndex % 6;
|
| 197 | }
|
| 198 |
|
| 199 | /**
|
| 200 | * returns tabIndex < 6
|
| 201 | */
|
| 202 | public boolean isTabInFirstRow()
|
| 203 | {
|
| 204 | return this.tabIndex < 6;
|
| 205 | }
|
| 206 |
|
| 207 | /**
|
| 208 | * Returns the enchantment types relevant to this tab
|
| 209 | */
|
| 210 | public EnumEnchantmentType[] getRelevantEnchantmentTypes()
|
| 211 | {
|
| 212 | return this.enchantmentTypes;
|
| 213 | }
|
| 214 |
|
| 215 | /**
|
| 216 | * Sets the enchantment types for populating this tab with enchanting books
|
| 217 | */
|
| 218 | public CreativeTabs setRelevantEnchantmentTypes(EnumEnchantmentType... types)
|
| 219 | {
|
| 220 | this.enchantmentTypes = types;
|
| 221 | return this;
|
| 222 | }
|
| 223 |
|
| 224 | public boolean hasRelevantEnchantmentType(EnumEnchantmentType enchantmentType)
|
| 225 | {
|
| 226 | if (this.enchantmentTypes == null)
|
| 227 | {
|
| 228 | return false;
|
| 229 | }
|
| 230 | else
|
| 231 | {
|
| 232 | for (EnumEnchantmentType enumenchantmenttype : this.enchantmentTypes)
|
| 233 | {
|
| 234 | if (enumenchantmenttype == enchantmentType)
|
| 235 | {
|
| 236 | return true;
|
| 237 | }
|
| 238 | }
|
| 239 |
|
| 240 | return false;
|
| 241 | }
|
| 242 | }
|
| 243 |
|
| 244 | /**
|
| 245 | * only shows items which have tabToDisplayOn == this
|
| 246 | */
|
| 247 | public void displayAllReleventItems(List<ItemStack> p_78018_1_)
|
| 248 | {
|
| 249 | for (Item item : Item.itemRegistry)
|
| 250 | {
|
| 251 | if (item != null && item.getCreativeTab() == this)
|
| 252 | {
|
| 253 | item.getSubItems(item, this, p_78018_1_);
|
| 254 | }
|
| 255 | }
|
| 256 |
|
| 257 | if (this.getRelevantEnchantmentTypes() != null)
|
| 258 | {
|
| 259 | this.addEnchantmentBooksToList(p_78018_1_, this.getRelevantEnchantmentTypes());
|
| 260 | }
|
| 261 | }
|
| 262 |
|
| 263 | /**
|
| 264 | * Adds the enchantment books from the supplied EnumEnchantmentType to the given list.
|
| 265 | */
|
| 266 | public void addEnchantmentBooksToList(List<ItemStack> itemList, EnumEnchantmentType... enchantmentType)
|
| 267 | {
|
| 268 | for (Enchantment enchantment : Enchantment.enchantmentsBookList)
|
| 269 | {
|
| 270 | if (enchantment != null && enchantment.type != null)
|
| 271 | {
|
| 272 | boolean flag = false;
|
| 273 |
|
| 274 | for (int i = 0; i < enchantmentType.length && !flag; ++i)
|
| 275 | {
|
| 276 | if (enchantment.type == enchantmentType[i])
|
| 277 | {
|
| 278 | flag = true;
|
| 279 | }
|
| 280 | }
|
| 281 |
|
| 282 | if (flag)
|
| 283 | {
|
| 284 | itemList.add(Items.enchanted_book.getEnchantedItemStack(new EnchantmentData(enchantment, enchantment.getMaxLevel())));
|
| 285 | }
|
| 286 | }
|
| 287 | }
|
| 288 | }
|
| 289 | }
|
| 290 |
|