    001package net.minecraft.client.gui.inventory;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.ArrayList;
    006import java.util.Iterator;
    007import java.util.List;
    008import net.minecraft.client.gui.GuiButton;
    009import net.minecraft.client.gui.GuiTextField;
    010import net.minecraft.client.gui.achievement.GuiAchievements;
    011import net.minecraft.client.gui.achievement.GuiStats;
    012import net.minecraft.client.renderer.InventoryEffectRenderer;
    013import net.minecraft.client.renderer.RenderHelper;
    014import net.minecraft.client.settings.GameSettings;
    015import net.minecraft.creativetab.CreativeTabs;
    016import net.minecraft.enchantment.Enchantment;
    017import net.minecraft.entity.player.EntityPlayer;
    018import net.minecraft.entity.player.InventoryPlayer;
    019import net.minecraft.inventory.Container;
    020import net.minecraft.inventory.InventoryBasic;
    021import net.minecraft.inventory.Slot;
    022import net.minecraft.item.Item;
    023import net.minecraft.item.ItemStack;
    024import net.minecraft.stats.AchievementList;
    025import net.minecraft.util.StringTranslate;
    026import org.lwjgl.input.Keyboard;
    027import org.lwjgl.input.Mouse;
    028import org.lwjgl.opengl.GL11;
    029import org.lwjgl.opengl.GL12;
    030
    031@SideOnly(Side.CLIENT)
    032public class GuiContainerCreative extends InventoryEffectRenderer
    033{
    034    private static InventoryBasic inventory = new InventoryBasic("tmp", true, 45);
    035
    036    /** Currently selected creative inventory tab index. */
    037    private static int selectedTabIndex = CreativeTabs.tabBlock.getTabIndex();
    038
    039    /** Amount scrolled in Creative mode inventory (0 = top, 1 = bottom) */
    040    private float currentScroll = 0.0F;
    041
    042    /** True if the scrollbar is being dragged */
    043    private boolean isScrolling = false;
    044
    045    /**
    046     * True if the left mouse button was held down last time drawScreen was called.
    047     */
    048    private boolean wasClicking;
    049    private GuiTextField searchField;
    050
    051    /**
    052     * Used to back up the ContainerCreative's inventory slots before filling it with the player's inventory slots for
    053     * the inventory tab.
    054     */
    055    private List backupContainerSlots;
    056    private Slot field_74235_v = null;
    057    private boolean field_74234_w = false;
    058    private CreativeCrafting field_82324_x;
    059    private static int tabPage = 0;
    060    private int maxPages = 0;
    061
    062    public GuiContainerCreative(EntityPlayer par1EntityPlayer)
    063    {
    064        super(new ContainerCreative(par1EntityPlayer));
    065        par1EntityPlayer.openContainer = this.inventorySlots;
    066        this.allowUserInput = true;
    067        par1EntityPlayer.addStat(AchievementList.openInventory, 1);
    068        this.ySize = 136;
    069        this.xSize = 195;
    070    }
    071
    072    /**
    073     * Called from the main game loop to update the screen.
    074     */
    075    public void updateScreen()
    076    {
    077        if (!this.mc.playerController.isInCreativeMode())
    078        {
    079            this.mc.displayGuiScreen(new GuiInventory(this.mc.thePlayer));
    080        }
    081    }
    082
    083    protected void handleMouseClick(Slot par1Slot, int par2, int par3, int par4)
    084    {
    085        this.field_74234_w = true;
    086        boolean flag = par4 == 1;
    087        par4 = par2 == -999 && par4 == 0 ? 4 : par4;
    088        ItemStack itemstack;
    089        InventoryPlayer inventoryplayer;
    090
    091        if (par1Slot == null && selectedTabIndex != CreativeTabs.tabInventory.getTabIndex() && par4 != 5)
    092        {
    093            inventoryplayer = this.mc.thePlayer.inventory;
    094
    095            if (inventoryplayer.getItemStack() != null)
    096            {
    097                if (par3 == 0)
    098                {
    099                    this.mc.thePlayer.dropPlayerItem(inventoryplayer.getItemStack());
    100                    this.mc.playerController.func_78752_a(inventoryplayer.getItemStack());
    101                    inventoryplayer.setItemStack((ItemStack)null);
    102                }
    103
    104                if (par3 == 1)
    105                {
    106                    itemstack = inventoryplayer.getItemStack().splitStack(1);
    107                    this.mc.thePlayer.dropPlayerItem(itemstack);
    108                    this.mc.playerController.func_78752_a(itemstack);
    109
    110                    if (inventoryplayer.getItemStack().stackSize == 0)
    111                    {
    112                        inventoryplayer.setItemStack((ItemStack)null);
    113                    }
    114                }
    115            }
    116        }
    117        else
    118        {
    119            int l;
    120
    121            if (par1Slot == this.field_74235_v && flag)
    122            {
    123                for (l = 0; l < this.mc.thePlayer.inventoryContainer.getInventory().size(); ++l)
    124                {
    125                    this.mc.playerController.sendSlotPacket((ItemStack)null, l);
    126                }
    127            }
    128            else
    129            {
    130                ItemStack itemstack1;
    131
    132                if (selectedTabIndex == CreativeTabs.tabInventory.getTabIndex())
    133                {
    134                    if (par1Slot == this.field_74235_v)
    135                    {
    136                        this.mc.thePlayer.inventory.setItemStack((ItemStack)null);
    137                    }
    138                    else if (par4 == 4 && par1Slot != null && par1Slot.getHasStack())
    139                    {
    140                        itemstack1 = par1Slot.decrStackSize(par3 == 0 ? 1 : par1Slot.getStack().getMaxStackSize());
    141                        this.mc.thePlayer.dropPlayerItem(itemstack1);
    142                        this.mc.playerController.func_78752_a(itemstack1);
    143                    }
    144                    else if (par4 == 4 && this.mc.thePlayer.inventory.getItemStack() != null)
    145                    {
    146                        this.mc.thePlayer.dropPlayerItem(this.mc.thePlayer.inventory.getItemStack());
    147                        this.mc.playerController.func_78752_a(this.mc.thePlayer.inventory.getItemStack());
    148                        this.mc.thePlayer.inventory.setItemStack((ItemStack)null);
    149                    }
    150                    else
    151                    {
    152                        this.mc.thePlayer.inventoryContainer.slotClick(par1Slot == null ? par2 : SlotCreativeInventory.func_75240_a((SlotCreativeInventory)par1Slot).slotNumber, par3, par4, this.mc.thePlayer);
    153                        this.mc.thePlayer.inventoryContainer.detectAndSendChanges();
    154                    }
    155                }
    156                else if (par4 != 5 && par1Slot.inventory == inventory)
    157                {
    158                    inventoryplayer = this.mc.thePlayer.inventory;
    159                    itemstack = inventoryplayer.getItemStack();
    160                    ItemStack itemstack2 = par1Slot.getStack();
    161                    ItemStack itemstack3;
    162
    163                    if (par4 == 2)
    164                    {
    165                        if (itemstack2 != null && par3 >= 0 && par3 < 9)
    166                        {
    167                            itemstack3 = itemstack2.copy();
    168                            itemstack3.stackSize = itemstack3.getMaxStackSize();
    169                            this.mc.thePlayer.inventory.setInventorySlotContents(par3, itemstack3);
    170                            this.mc.thePlayer.inventoryContainer.detectAndSendChanges();
    171                        }
    172
    173                        return;
    174                    }
    175
    176                    if (par4 == 3)
    177                    {
    178                        if (inventoryplayer.getItemStack() == null && par1Slot.getHasStack())
    179                        {
    180                            itemstack3 = par1Slot.getStack().copy();
    181                            itemstack3.stackSize = itemstack3.getMaxStackSize();
    182                            inventoryplayer.setItemStack(itemstack3);
    183                        }
    184
    185                        return;
    186                    }
    187
    188                    if (par4 == 4)
    189                    {
    190                        if (itemstack2 != null)
    191                        {
    192                            itemstack3 = itemstack2.copy();
    193                            itemstack3.stackSize = par3 == 0 ? 1 : itemstack3.getMaxStackSize();
    194                            this.mc.thePlayer.dropPlayerItem(itemstack3);
    195                            this.mc.playerController.func_78752_a(itemstack3);
    196                        }
    197
    198                        return;
    199                    }
    200
    201                    if (itemstack != null && itemstack2 != null && itemstack.isItemEqual(itemstack2) && ItemStack.areItemStackTagsEqual(itemstack, itemstack2)) //Forge: Bugfix, Compare NBT data, allow for deletion of enchanted books, MC-12770
    202                    {
    203                        if (par3 == 0)
    204                        {
    205                            if (flag)
    206                            {
    207                                itemstack.stackSize = itemstack.getMaxStackSize();
    208                            }
    209                            else if (itemstack.stackSize < itemstack.getMaxStackSize())
    210                            {
    211                                ++itemstack.stackSize;
    212                            }
    213                        }
    214                        else if (itemstack.stackSize <= 1)
    215                        {
    216                            inventoryplayer.setItemStack((ItemStack)null);
    217                        }
    218                        else
    219                        {
    220                            --itemstack.stackSize;
    221                        }
    222                    }
    223                    else if (itemstack2 != null && itemstack == null)
    224                    {
    225                        inventoryplayer.setItemStack(ItemStack.copyItemStack(itemstack2));
    226                        itemstack = inventoryplayer.getItemStack();
    227
    228                        if (flag)
    229                        {
    230                            itemstack.stackSize = itemstack.getMaxStackSize();
    231                        }
    232                    }
    233                    else
    234                    {
    235                        inventoryplayer.setItemStack((ItemStack)null);
    236                    }
    237                }
    238                else
    239                {
    240                    this.inventorySlots.slotClick(par1Slot == null ? par2 : par1Slot.slotNumber, par3, par4, this.mc.thePlayer);
    241
    242                    if (Container.func_94532_c(par3) == 2)
    243                    {
    244                        for (l = 0; l < 9; ++l)
    245                        {
    246                            this.mc.playerController.sendSlotPacket(this.inventorySlots.getSlot(45 + l).getStack(), 36 + l);
    247                        }
    248                    }
    249                    else if (par1Slot != null)
    250                    {
    251                        itemstack1 = this.inventorySlots.getSlot(par1Slot.slotNumber).getStack();
    252                        this.mc.playerController.sendSlotPacket(itemstack1, par1Slot.slotNumber - this.inventorySlots.inventorySlots.size() + 9 + 36);
    253                    }
    254                }
    255            }
    256        }
    257    }
    258
    259    /**
    260     * Adds the buttons (and other controls) to the screen in question.
    261     */
    262    public void initGui()
    263    {
    264        if (this.mc.playerController.isInCreativeMode())
    265        {
    266            super.initGui();
    267            this.buttonList.clear();
    268            Keyboard.enableRepeatEvents(true);
    269            this.searchField = new GuiTextField(this.fontRenderer, this.guiLeft + 82, this.guiTop + 6, 89, this.fontRenderer.FONT_HEIGHT);
    270            this.searchField.setMaxStringLength(15);
    271            this.searchField.setEnableBackgroundDrawing(false);
    272            this.searchField.setVisible(false);
    273            this.searchField.setTextColor(16777215);
    274            int i = selectedTabIndex;
    275            selectedTabIndex = -1;
    276            this.setCurrentCreativeTab(CreativeTabs.creativeTabArray[i]);
    277            this.field_82324_x = new CreativeCrafting(this.mc);
    278            this.mc.thePlayer.inventoryContainer.addCraftingToCrafters(this.field_82324_x);
    279            int tabCount = CreativeTabs.creativeTabArray.length;
    280            if (tabCount > 12)
    281            {
    282                buttonList.add(new GuiButton(101, guiLeft,              guiTop - 50, 20, 20, "<"));
    283                buttonList.add(new GuiButton(102, guiLeft + xSize - 20, guiTop - 50, 20, 20, ">"));
    284                maxPages = ((tabCount - 12) / 10) + 1;
    285            }
    286        }
    287        else
    288        {
    289            this.mc.displayGuiScreen(new GuiInventory(this.mc.thePlayer));
    290        }
    291    }
    292
    293    /**
    294     * Called when the screen is unloaded. Used to disable keyboard repeat events
    295     */
    296    public void onGuiClosed()
    297    {
    298        super.onGuiClosed();
    299
    300        if (this.mc.thePlayer != null && this.mc.thePlayer.inventory != null)
    301        {
    302            this.mc.thePlayer.inventoryContainer.removeCraftingFromCrafters(this.field_82324_x);
    303        }
    304
    305        Keyboard.enableRepeatEvents(false);
    306    }
    307
    308    /**
    309     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    310     */
    311    protected void keyTyped(char par1, int par2)
    312    {
    313        if (selectedTabIndex != CreativeTabs.tabAllSearch.getTabIndex())
    314        {
    315            if (GameSettings.isKeyDown(this.mc.gameSettings.keyBindChat))
    316            {
    317                this.setCurrentCreativeTab(CreativeTabs.tabAllSearch);
    318            }
    319            else
    320            {
    321                super.keyTyped(par1, par2);
    322            }
    323        }
    324        else
    325        {
    326            if (this.field_74234_w)
    327            {
    328                this.field_74234_w = false;
    329                this.searchField.setText("");
    330            }
    331
    332            if (!this.checkHotbarKeys(par2))
    333            {
    334                if (this.searchField.textboxKeyTyped(par1, par2))
    335                {
    336                    this.updateCreativeSearch();
    337                }
    338                else
    339                {
    340                    super.keyTyped(par1, par2);
    341                }
    342            }
    343        }
    344    }
    345
    346    private void updateCreativeSearch()
    347    {
    348        ContainerCreative containercreative = (ContainerCreative)this.inventorySlots;
    349        containercreative.itemList.clear();
    350        Item[] aitem = Item.itemsList;
    351        int i = aitem.length;
    352        int j;
    353
    354        for (j = 0; j < i; ++j)
    355        {
    356            Item item = aitem[j];
    357
    358            if (item != null && item.getCreativeTab() != null)
    359            {
    360                item.getSubItems(item.itemID, (CreativeTabs)null, containercreative.itemList);
    361            }
    362        }
    363
    364        Enchantment[] aenchantment = Enchantment.enchantmentsList;
    365        i = aenchantment.length;
    366
    367        for (j = 0; j < i; ++j)
    368        {
    369            Enchantment enchantment = aenchantment[j];
    370
    371            if (enchantment != null && enchantment.type != null)
    372            {
    373                Item.enchantedBook.func_92113_a(enchantment, containercreative.itemList);
    374            }
    375        }
    376
    377        Iterator iterator = containercreative.itemList.iterator();
    378        String s = this.searchField.getText().toLowerCase();
    379
    380        while (iterator.hasNext())
    381        {
    382            ItemStack itemstack = (ItemStack)iterator.next();
    383            boolean flag = false;
    384            Iterator iterator1 = itemstack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips).iterator();
    385
    386            while (true)
    387            {
    388                if (iterator1.hasNext())
    389                {
    390                    String s1 = (String)iterator1.next();
    391
    392                    if (!s1.toLowerCase().contains(s))
    393                    {
    394                        continue;
    395                    }
    396
    397                    flag = true;
    398                }
    399
    400                if (!flag)
    401                {
    402                    iterator.remove();
    403                }
    404
    405                break;
    406            }
    407        }
    408
    409        this.currentScroll = 0.0F;
    410        containercreative.scrollTo(0.0F);
    411    }
    412
    413    /**
    414     * Draw the foreground layer for the GuiContainer (everything in front of the items)
    415     */
    416    protected void drawGuiContainerForegroundLayer(int par1, int par2)
    417    {
    418        CreativeTabs creativetabs = CreativeTabs.creativeTabArray[selectedTabIndex];
    419
    420        if (creativetabs != null && creativetabs.drawInForegroundOfTab())
    421        {
    422            this.fontRenderer.drawString(creativetabs.getTranslatedTabLabel(), 8, 6, 4210752);
    423        }
    424    }
    425
    426    /**
    427     * Called when the mouse is clicked.
    428     */
    429    protected void mouseClicked(int par1, int par2, int par3)
    430    {
    431        if (par3 == 0)
    432        {
    433            int l = par1 - this.guiLeft;
    434            int i1 = par2 - this.guiTop;
    435            CreativeTabs[] acreativetabs = CreativeTabs.creativeTabArray;
    436            int j1 = acreativetabs.length;
    437
    438            for (int k1 = 0; k1 < j1; ++k1)
    439            {
    440                CreativeTabs creativetabs = acreativetabs[k1];
    441
    442                if (this.func_74232_a(creativetabs, l, i1))
    443                {
    444                    return;
    445                }
    446            }
    447        }
    448
    449        super.mouseClicked(par1, par2, par3);
    450    }
    451
    452    /**
    453     * Called when the mouse is moved or a mouse button is released.  Signature: (mouseX, mouseY, which) which==-1 is
    454     * mouseMove, which==0 or which==1 is mouseUp
    455     */
    456    protected void mouseMovedOrUp(int par1, int par2, int par3)
    457    {
    458        if (par3 == 0)
    459        {
    460            int l = par1 - this.guiLeft;
    461            int i1 = par2 - this.guiTop;
    462            CreativeTabs[] acreativetabs = CreativeTabs.creativeTabArray;
    463            int j1 = acreativetabs.length;
    464
    465            for (int k1 = 0; k1 < j1; ++k1)
    466            {
    467                CreativeTabs creativetabs = acreativetabs[k1];
    468
    469                if (creativetabs != null && func_74232_a(creativetabs, l, i1))
    470                {
    471                    this.setCurrentCreativeTab(creativetabs);
    472                    return;
    473                }
    474            }
    475        }
    476
    477        super.mouseMovedOrUp(par1, par2, par3);
    478    }
    479
    480    /**
    481     * returns (if you are not on the inventoryTab) and (the flag isn't set) and( you have more than 1 page of items)
    482     */
    483    private boolean needsScrollBars()
    484    {
    485        if (CreativeTabs.creativeTabArray[selectedTabIndex] == null) return false;
    486        return selectedTabIndex != CreativeTabs.tabInventory.getTabIndex() && CreativeTabs.creativeTabArray[selectedTabIndex].shouldHidePlayerInventory() && ((ContainerCreative)this.inventorySlots).hasMoreThan1PageOfItemsInList();
    487    }
    488
    489    private void setCurrentCreativeTab(CreativeTabs par1CreativeTabs)
    490    {
    491        if (par1CreativeTabs == null)
    492        {
    493            return;
    494        }
    495
    496        int i = selectedTabIndex;
    497        selectedTabIndex = par1CreativeTabs.getTabIndex();
    498        ContainerCreative containercreative = (ContainerCreative)this.inventorySlots;
    499        this.field_94077_p.clear();
    500        containercreative.itemList.clear();
    501        par1CreativeTabs.displayAllReleventItems(containercreative.itemList);
    502
    503        if (par1CreativeTabs == CreativeTabs.tabInventory)
    504        {
    505            Container container = this.mc.thePlayer.inventoryContainer;
    506
    507            if (this.backupContainerSlots == null)
    508            {
    509                this.backupContainerSlots = containercreative.inventorySlots;
    510            }
    511
    512            containercreative.inventorySlots = new ArrayList();
    513
    514            for (int j = 0; j < container.inventorySlots.size(); ++j)
    515            {
    516                SlotCreativeInventory slotcreativeinventory = new SlotCreativeInventory(this, (Slot)container.inventorySlots.get(j), j);
    517                containercreative.inventorySlots.add(slotcreativeinventory);
    518                int k;
    519                int l;
    520                int i1;
    521
    522                if (j >= 5 && j < 9)
    523                {
    524                    k = j - 5;
    525                    l = k / 2;
    526                    i1 = k % 2;
    527                    slotcreativeinventory.xDisplayPosition = 9 + l * 54;
    528                    slotcreativeinventory.yDisplayPosition = 6 + i1 * 27;
    529                }
    530                else if (j >= 0 && j < 5)
    531                {
    532                    slotcreativeinventory.yDisplayPosition = -2000;
    533                    slotcreativeinventory.xDisplayPosition = -2000;
    534                }
    535                else if (j < container.inventorySlots.size())
    536                {
    537                    k = j - 9;
    538                    l = k % 9;
    539                    i1 = k / 9;
    540                    slotcreativeinventory.xDisplayPosition = 9 + l * 18;
    541
    542                    if (j >= 36)
    543                    {
    544                        slotcreativeinventory.yDisplayPosition = 112;
    545                    }
    546                    else
    547                    {
    548                        slotcreativeinventory.yDisplayPosition = 54 + i1 * 18;
    549                    }
    550                }
    551            }
    552
    553            this.field_74235_v = new Slot(inventory, 0, 173, 112);
    554            containercreative.inventorySlots.add(this.field_74235_v);
    555        }
    556        else if (i == CreativeTabs.tabInventory.getTabIndex())
    557        {
    558            containercreative.inventorySlots = this.backupContainerSlots;
    559            this.backupContainerSlots = null;
    560        }
    561
    562        if (this.searchField != null)
    563        {
    564            if (par1CreativeTabs == CreativeTabs.tabAllSearch)
    565            {
    566                this.searchField.setVisible(true);
    567                this.searchField.setCanLoseFocus(false);
    568                this.searchField.setFocused(true);
    569                this.searchField.setText("");
    570                this.updateCreativeSearch();
    571            }
    572            else
    573            {
    574                this.searchField.setVisible(false);
    575                this.searchField.setCanLoseFocus(true);
    576                this.searchField.setFocused(false);
    577            }
    578        }
    579
    580        this.currentScroll = 0.0F;
    581        containercreative.scrollTo(0.0F);
    582    }
    583
    584    /**
    585     * Handles mouse input.
    586     */
    587    public void handleMouseInput()
    588    {
    589        super.handleMouseInput();
    590        int i = Mouse.getEventDWheel();
    591
    592        if (i != 0 && this.needsScrollBars())
    593        {
    594            int j = ((ContainerCreative)this.inventorySlots).itemList.size() / 9 - 5 + 1;
    595
    596            if (i > 0)
    597            {
    598                i = 1;
    599            }
    600
    601            if (i < 0)
    602            {
    603                i = -1;
    604            }
    605
    606            this.currentScroll = (float)((double)this.currentScroll - (double)i / (double)j);
    607
    608            if (this.currentScroll < 0.0F)
    609            {
    610                this.currentScroll = 0.0F;
    611            }
    612
    613            if (this.currentScroll > 1.0F)
    614            {
    615                this.currentScroll = 1.0F;
    616            }
    617
    618            ((ContainerCreative)this.inventorySlots).scrollTo(this.currentScroll);
    619        }
    620    }
    621
    622    /**
    623     * Draws the screen and all the components in it.
    624     */
    625    public void drawScreen(int par1, int par2, float par3)
    626    {
    627        boolean flag = Mouse.isButtonDown(0);
    628        int k = this.guiLeft;
    629        int l = this.guiTop;
    630        int i1 = k + 175;
    631        int j1 = l + 18;
    632        int k1 = i1 + 14;
    633        int l1 = j1 + 112;
    634
    635        if (!this.wasClicking && flag && par1 >= i1 && par2 >= j1 && par1 < k1 && par2 < l1)
    636        {
    637            this.isScrolling = this.needsScrollBars();
    638        }
    639
    640        if (!flag)
    641        {
    642            this.isScrolling = false;
    643        }
    644
    645        this.wasClicking = flag;
    646
    647        if (this.isScrolling)
    648        {
    649            this.currentScroll = ((float)(par2 - j1) - 7.5F) / ((float)(l1 - j1) - 15.0F);
    650
    651            if (this.currentScroll < 0.0F)
    652            {
    653                this.currentScroll = 0.0F;
    654            }
    655
    656            if (this.currentScroll > 1.0F)
    657            {
    658                this.currentScroll = 1.0F;
    659            }
    660
    661            ((ContainerCreative)this.inventorySlots).scrollTo(this.currentScroll);
    662        }
    663
    664        super.drawScreen(par1, par2, par3);
    665        CreativeTabs[] acreativetabs = CreativeTabs.creativeTabArray;
    666        int start = tabPage * 10;
    667        int i2 = Math.min(acreativetabs.length, ((tabPage + 1) * 10) + 2);
    668        if (tabPage != 0) start += 2;
    669        boolean rendered = false;
    670
    671        for (int j2 = start; j2 < i2; ++j2)
    672        {
    673            CreativeTabs creativetabs = acreativetabs[j2];
    674
    675            if (creativetabs != null && renderCreativeInventoryHoveringText(creativetabs, par1, par2))
    676            {
    677                rendered = true;
    678                break;
    679            }
    680        }
    681
    682        if (!rendered && !renderCreativeInventoryHoveringText(CreativeTabs.tabAllSearch, par1, par2))
    683        {
    684            renderCreativeInventoryHoveringText(CreativeTabs.tabInventory, par1, par2);
    685        }
    686
    687        if (this.field_74235_v != null && selectedTabIndex == CreativeTabs.tabInventory.getTabIndex() && this.isPointInRegion(this.field_74235_v.xDisplayPosition, this.field_74235_v.yDisplayPosition, 16, 16, par1, par2))
    688        {
    689            this.drawCreativeTabHoveringText(StringTranslate.getInstance().translateKey("inventory.binSlot"), par1, par2);
    690        }
    691
    692        if (maxPages != 0)
    693        {
    694            String page = String.format("%d / %d", tabPage + 1, maxPages + 1);
    695            int width = fontRenderer.getStringWidth(page);
    696            GL11.glDisable(GL11.GL_LIGHTING);
    697            this.zLevel = 300.0F;
    698            itemRenderer.zLevel = 300.0F;
    699            fontRenderer.drawString(page, guiLeft + (xSize / 2) - (width / 2), guiTop - 44, -1);
    700            this.zLevel = 0.0F;
    701            itemRenderer.zLevel = 0.0F;
    702        }
    703
    704        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    705        GL11.glDisable(GL11.GL_LIGHTING);
    706    }
    707
    708    /**
    709     * Draw the background layer for the GuiContainer (everything behind the items)
    710     */
    711    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    712    {
    713        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    714        RenderHelper.enableGUIStandardItemLighting();
    715        CreativeTabs creativetabs = CreativeTabs.creativeTabArray[selectedTabIndex];
    716        CreativeTabs[] acreativetabs = CreativeTabs.creativeTabArray;
    717        int k = acreativetabs.length;
    718        int l;
    719
    720        int start = tabPage * 10;
    721        k = Math.min(acreativetabs.length, ((tabPage + 1) * 10 + 2));
    722        if (tabPage != 0) start += 2;
    723
    724        for (l = start; l < k; ++l)
    725        {
    726            CreativeTabs creativetabs1 = acreativetabs[l];
    727            this.mc.renderEngine.bindTexture("/gui/allitems.png");
    728
    729            if (creativetabs1 != null && creativetabs1.getTabIndex() != selectedTabIndex)
    730            {
    731                this.renderCreativeTab(creativetabs1);
    732            }
    733        }
    734
    735        if (tabPage != 0)
    736        {
    737            if (creativetabs != CreativeTabs.tabAllSearch)
    738            {
    739                mc.renderEngine.bindTexture("/gui/allitems.png");
    740                renderCreativeTab(CreativeTabs.tabAllSearch);
    741            }
    742            if (creativetabs != CreativeTabs.tabInventory)
    743            {
    744                mc.renderEngine.bindTexture("/gui/allitems.png");
    745                renderCreativeTab(CreativeTabs.tabInventory);
    746            }
    747        }
    748
    749        this.mc.renderEngine.bindTexture("/gui/creative_inv/" + creativetabs.getBackgroundImageName());
    750        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
    751        this.searchField.drawTextBox();
    752        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    753        int i1 = this.guiLeft + 175;
    754        k = this.guiTop + 18;
    755        l = k + 112;
    756        this.mc.renderEngine.bindTexture("/gui/allitems.png");
    757
    758        if (creativetabs.shouldHidePlayerInventory())
    759        {
    760            this.drawTexturedModalRect(i1, k + (int)((float)(l - k - 17) * this.currentScroll), 232 + (this.needsScrollBars() ? 0 : 12), 0, 12, 15);
    761        }
    762
    763        if (creativetabs == null || creativetabs.getTabPage() != tabPage)
    764        {
    765            if (creativetabs != CreativeTabs.tabAllSearch && creativetabs != CreativeTabs.tabInventory)
    766            {
    767                return;
    768            }
    769        }
    770
    771        this.renderCreativeTab(creativetabs);
    772
    773        if (creativetabs == CreativeTabs.tabInventory)
    774        {
    775            GuiInventory.drawPlayerOnGui(this.mc, this.guiLeft + 43, this.guiTop + 45, 20, (float)(this.guiLeft + 43 - par2), (float)(this.guiTop + 45 - 30 - par3));
    776        }
    777    }
    778
    779    protected boolean func_74232_a(CreativeTabs par1CreativeTabs, int par2, int par3)
    780    {
    781        if (par1CreativeTabs.getTabPage() != tabPage)
    782        {
    783            if (par1CreativeTabs != CreativeTabs.tabAllSearch &&
    784                par1CreativeTabs != CreativeTabs.tabInventory)
    785            {
    786                return false;
    787            }
    788        }
    789
    790        int k = par1CreativeTabs.getTabColumn();
    791        int l = 28 * k;
    792        byte b0 = 0;
    793
    794        if (k == 5)
    795        {
    796            l = this.xSize - 28 + 2;
    797        }
    798        else if (k > 0)
    799        {
    800            l += k;
    801        }
    802
    803        int i1;
    804
    805        if (par1CreativeTabs.isTabInFirstRow())
    806        {
    807            i1 = b0 - 32;
    808        }
    809        else
    810        {
    811            i1 = b0 + this.ySize;
    812        }
    813
    814        return par2 >= l && par2 <= l + 28 && par3 >= i1 && par3 <= i1 + 32;
    815    }
    816
    817    /**
    818     * Renders the creative inventory hovering text if mouse is over it. Returns true if did render or false otherwise.
    819     * Params: current creative tab to be checked, current mouse x position, current mouse y position.
    820     */
    821    protected boolean renderCreativeInventoryHoveringText(CreativeTabs par1CreativeTabs, int par2, int par3)
    822    {
    823        int k = par1CreativeTabs.getTabColumn();
    824        int l = 28 * k;
    825        byte b0 = 0;
    826
    827        if (k == 5)
    828        {
    829            l = this.xSize - 28 + 2;
    830        }
    831        else if (k > 0)
    832        {
    833            l += k;
    834        }
    835
    836        int i1;
    837
    838        if (par1CreativeTabs.isTabInFirstRow())
    839        {
    840            i1 = b0 - 32;
    841        }
    842        else
    843        {
    844            i1 = b0 + this.ySize;
    845        }
    846
    847        if (this.isPointInRegion(l + 3, i1 + 3, 23, 27, par2, par3))
    848        {
    849            this.drawCreativeTabHoveringText(par1CreativeTabs.getTranslatedTabLabel(), par2, par3);
    850            return true;
    851        }
    852        else
    853        {
    854            return false;
    855        }
    856    }
    857
    858    /**
    859     * Renders passed creative inventory tab into the screen.
    860     */
    861    protected void renderCreativeTab(CreativeTabs par1CreativeTabs)
    862    {
    863        boolean flag = par1CreativeTabs.getTabIndex() == selectedTabIndex;
    864        boolean flag1 = par1CreativeTabs.isTabInFirstRow();
    865        int i = par1CreativeTabs.getTabColumn();
    866        int j = i * 28;
    867        int k = 0;
    868        int l = this.guiLeft + 28 * i;
    869        int i1 = this.guiTop;
    870        byte b0 = 32;
    871
    872        if (flag)
    873        {
    874            k += 32;
    875        }
    876
    877        if (i == 5)
    878        {
    879            l = this.guiLeft + this.xSize - 28;
    880        }
    881        else if (i > 0)
    882        {
    883            l += i;
    884        }
    885
    886        if (flag1)
    887        {
    888            i1 -= 28;
    889        }
    890        else
    891        {
    892            k += 64;
    893            i1 += this.ySize - 4;
    894        }
    895
    896        GL11.glDisable(GL11.GL_LIGHTING);
    897        this.drawTexturedModalRect(l, i1, j, k, 28, b0);
    898        this.zLevel = 100.0F;
    899        itemRenderer.zLevel = 100.0F;
    900        l += 6;
    901        i1 += 8 + (flag1 ? 1 : -1);
    902        GL11.glEnable(GL11.GL_LIGHTING);
    903        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    904        ItemStack itemstack = par1CreativeTabs.getIconItemStack();
    905        itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, itemstack, l, i1);
    906        itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, itemstack, l, i1);
    907        GL11.glDisable(GL11.GL_LIGHTING);
    908        itemRenderer.zLevel = 0.0F;
    909        this.zLevel = 0.0F;
    910    }
    911
    912    /**
    913     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    914     */
    915    protected void actionPerformed(GuiButton par1GuiButton)
    916    {
    917        if (par1GuiButton.id == 0)
    918        {
    919            this.mc.displayGuiScreen(new GuiAchievements(this.mc.statFileWriter));
    920        }
    921
    922        if (par1GuiButton.id == 1)
    923        {
    924            this.mc.displayGuiScreen(new GuiStats(this, this.mc.statFileWriter));
    925        }
    926
    927        if (par1GuiButton.id == 101)
    928        {
    929            tabPage = Math.max(tabPage - 1, 0);
    930        }
    931        else if (par1GuiButton.id == 102)
    932        {
    933            tabPage = Math.min(tabPage + 1, maxPages);
    934        }
    935    }
    936
    937    public int func_74230_h()
    938    {
    939        return selectedTabIndex;
    940    }
    941
    942    /**
    943     * Returns the creative inventory
    944     */
    945    static InventoryBasic getInventory()
    946    {
    947        return inventory;
    948    }
    949}