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