    001package net.minecraft.client.gui.inventory;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.List;
    006import net.minecraft.client.Minecraft;
    007import net.minecraft.client.gui.GuiScreen;
    008import net.minecraft.client.renderer.OpenGlHelper;
    009import net.minecraft.client.renderer.RenderHelper;
    010import net.minecraft.client.renderer.entity.RenderItem;
    011import net.minecraft.entity.player.InventoryPlayer;
    012import net.minecraft.inventory.Container;
    013import net.minecraft.inventory.Slot;
    014import net.minecraft.item.ItemStack;
    015import net.minecraft.util.MathHelper;
    016import org.lwjgl.input.Keyboard;
    017import org.lwjgl.opengl.GL11;
    018import org.lwjgl.opengl.GL12;
    019
    020@SideOnly(Side.CLIENT)
    021public abstract class GuiContainer extends GuiScreen
    022{
    023    /** Stacks renderer. Icons, stack size, health, etc... */
    024    protected static RenderItem itemRenderer = new RenderItem();
    025
    026    /** The X size of the inventory window in pixels. */
    027    protected int xSize = 176;
    028
    029    /** The Y size of the inventory window in pixels. */
    030    protected int ySize = 166;
    031
    032    /** A list of the players inventory slots. */
    033    public Container inventorySlots;
    034
    035    /**
    036     * Starting X position for the Gui. Inconsistent use for Gui backgrounds.
    037     */
    038    protected int guiLeft;
    039
    040    /**
    041     * Starting Y position for the Gui. Inconsistent use for Gui backgrounds.
    042     */
    043    protected int guiTop;
    044    private Slot theSlot;
    045
    046    /** Used when touchscreen is enabled */
    047    private Slot clickedSlot = null;
    048
    049    /** Used when touchscreen is enabled */
    050    private boolean isRightMouseClick = false;
    051
    052    /** Used when touchscreen is enabled */
    053    private ItemStack draggedStack = null;
    054    private int field_85049_r = 0;
    055    private int field_85048_s = 0;
    056    private Slot returningStackDestSlot = null;
    057    private long returningStackTime = 0L;
    058
    059    /** Used when touchscreen is enabled */
    060    private ItemStack returningStack = null;
    061    private Slot field_92033_y = null;
    062    private long field_92032_z = 0L;
    063
    064    public GuiContainer(Container par1Container)
    065    {
    066        this.inventorySlots = par1Container;
    067    }
    068
    069    /**
    070     * Adds the buttons (and other controls) to the screen in question.
    071     */
    072    public void initGui()
    073    {
    074        super.initGui();
    075        this.mc.thePlayer.openContainer = this.inventorySlots;
    076        this.guiLeft = (this.width - this.xSize) / 2;
    077        this.guiTop = (this.height - this.ySize) / 2;
    078    }
    079
    080    /**
    081     * Draws the screen and all the components in it.
    082     */
    083    public void drawScreen(int par1, int par2, float par3)
    084    {
    085        this.drawDefaultBackground();
    086        int var4 = this.guiLeft;
    087        int var5 = this.guiTop;
    088        this.drawGuiContainerBackgroundLayer(par3, par1, par2);
    089        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    090        RenderHelper.disableStandardItemLighting();
    091        GL11.glDisable(GL11.GL_LIGHTING);
    092        GL11.glDisable(GL11.GL_DEPTH_TEST);
    093        super.drawScreen(par1, par2, par3);
    094        RenderHelper.enableGUIStandardItemLighting();
    095        GL11.glPushMatrix();
    096        GL11.glTranslatef((float)var4, (float)var5, 0.0F);
    097        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    098        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    099        this.theSlot = null;
    100        short var6 = 240;
    101        short var7 = 240;
    102        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var6 / 1.0F, (float)var7 / 1.0F);
    103        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    104        int var9;
    105
    106        for (int var13 = 0; var13 < this.inventorySlots.inventorySlots.size(); ++var13)
    107        {
    108            Slot var14 = (Slot)this.inventorySlots.inventorySlots.get(var13);
    109            this.drawSlotInventory(var14);
    110
    111            if (this.isMouseOverSlot(var14, par1, par2))
    112            {
    113                this.theSlot = var14;
    114                GL11.glDisable(GL11.GL_LIGHTING);
    115                GL11.glDisable(GL11.GL_DEPTH_TEST);
    116                int var8 = var14.xDisplayPosition;
    117                var9 = var14.yDisplayPosition;
    118                this.drawGradientRect(var8, var9, var8 + 16, var9 + 16, -2130706433, -2130706433);
    119                GL11.glEnable(GL11.GL_LIGHTING);
    120                GL11.glEnable(GL11.GL_DEPTH_TEST);
    121            }
    122        }
    123
    124        this.drawGuiContainerForegroundLayer(par1, par2);
    125        InventoryPlayer var15 = this.mc.thePlayer.inventory;
    126        ItemStack var16 = this.draggedStack == null ? var15.getItemStack() : this.draggedStack;
    127
    128        if (var16 != null)
    129        {
    130            byte var18 = 8;
    131            var9 = this.draggedStack == null ? 8 : 16;
    132
    133            if (this.draggedStack != null && this.isRightMouseClick)
    134            {
    135                var16 = var16.copy();
    136                var16.stackSize = MathHelper.ceiling_float_int((float)var16.stackSize / 2.0F);
    137            }
    138
    139            this.drawItemStack(var16, par1 - var4 - var18, par2 - var5 - var9);
    140        }
    141
    142        if (this.returningStack != null)
    143        {
    144            float var17 = (float)(Minecraft.getSystemTime() - this.returningStackTime) / 100.0F;
    145
    146            if (var17 >= 1.0F)
    147            {
    148                var17 = 1.0F;
    149                this.returningStack = null;
    150            }
    151
    152            var9 = this.returningStackDestSlot.xDisplayPosition - this.field_85049_r;
    153            int var10 = this.returningStackDestSlot.yDisplayPosition - this.field_85048_s;
    154            int var11 = this.field_85049_r + (int)((float)var9 * var17);
    155            int var12 = this.field_85048_s + (int)((float)var10 * var17);
    156            this.drawItemStack(this.returningStack, var11, var12);
    157        }
    158
    159        if (var15.getItemStack() == null && this.theSlot != null && this.theSlot.getHasStack())
    160        {
    161            ItemStack var19 = this.theSlot.getStack();
    162            this.drawItemStackTooltip(var19, par1 - var4 + 8, par2 - var5 + 8);
    163        }
    164
    165        GL11.glPopMatrix();
    166        GL11.glEnable(GL11.GL_LIGHTING);
    167        GL11.glEnable(GL11.GL_DEPTH_TEST);
    168        RenderHelper.enableStandardItemLighting();
    169    }
    170
    171    private void drawItemStack(ItemStack par1ItemStack, int par2, int par3)
    172    {
    173        GL11.glTranslatef(0.0F, 0.0F, 32.0F);
    174        this.zLevel = 200.0F;
    175        itemRenderer.zLevel = 200.0F;
    176        itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, par1ItemStack, par2, par3);
    177        itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, par1ItemStack, par2, par3 - (this.draggedStack == null ? 0 : 8));
    178        this.zLevel = 0.0F;
    179        itemRenderer.zLevel = 0.0F;
    180    }
    181
    182    protected void drawItemStackTooltip(ItemStack par1ItemStack, int par2, int par3)
    183    {
    184        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    185        RenderHelper.disableStandardItemLighting();
    186        GL11.glDisable(GL11.GL_LIGHTING);
    187        GL11.glDisable(GL11.GL_DEPTH_TEST);
    188        List var4 = par1ItemStack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
    189
    190        if (!var4.isEmpty())
    191        {
    192            int var5 = 0;
    193            int var6;
    194            int var7;
    195
    196            for (var6 = 0; var6 < var4.size(); ++var6)
    197            {
    198                var7 = this.fontRenderer.getStringWidth((String)var4.get(var6));
    199
    200                if (var7 > var5)
    201                {
    202                    var5 = var7;
    203                }
    204            }
    205
    206            var6 = par2 + 12;
    207            var7 = par3 - 12;
    208            int var9 = 8;
    209
    210            if (var4.size() > 1)
    211            {
    212                var9 += 2 + (var4.size() - 1) * 10;
    213            }
    214
    215            if (this.guiTop + var7 + var9 + 6 > this.height)
    216            {
    217                var7 = this.height - var9 - this.guiTop - 6;
    218            }
    219
    220            this.zLevel = 300.0F;
    221            itemRenderer.zLevel = 300.0F;
    222            int var10 = -267386864;
    223            this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
    224            this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
    225            this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
    226            this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
    227            this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
    228            int var11 = 1347420415;
    229            int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
    230            this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
    231            this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
    232            this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
    233            this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
    234
    235            for (int var13 = 0; var13 < var4.size(); ++var13)
    236            {
    237                String var14 = (String)var4.get(var13);
    238
    239                if (var13 == 0)
    240                {
    241                    var14 = "\u00a7" + Integer.toHexString(par1ItemStack.getRarity().rarityColor) + var14;
    242                }
    243                else
    244                {
    245                    var14 = "\u00a77" + var14;
    246                }
    247
    248                this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
    249
    250                if (var13 == 0)
    251                {
    252                    var7 += 2;
    253                }
    254
    255                var7 += 10;
    256            }
    257
    258            this.zLevel = 0.0F;
    259            itemRenderer.zLevel = 0.0F;
    260        }
    261    }
    262
    263    /**
    264     * Draws the text when mouse is over creative inventory tab. Params: current creative tab to be checked, current
    265     * mouse x position, current mouse y position.
    266     */
    267    protected void drawCreativeTabHoveringText(String par1Str, int par2, int par3)
    268    {
    269        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    270        RenderHelper.disableStandardItemLighting();
    271        GL11.glDisable(GL11.GL_LIGHTING);
    272        GL11.glDisable(GL11.GL_DEPTH_TEST);
    273        int var4 = this.fontRenderer.getStringWidth(par1Str);
    274        int var5 = par2 + 12;
    275        int var6 = par3 - 12;
    276        byte var8 = 8;
    277        this.zLevel = 300.0F;
    278        itemRenderer.zLevel = 300.0F;
    279        int var9 = -267386864;
    280        this.drawGradientRect(var5 - 3, var6 - 4, var5 + var4 + 3, var6 - 3, var9, var9);
    281        this.drawGradientRect(var5 - 3, var6 + var8 + 3, var5 + var4 + 3, var6 + var8 + 4, var9, var9);
    282        this.drawGradientRect(var5 - 3, var6 - 3, var5 + var4 + 3, var6 + var8 + 3, var9, var9);
    283        this.drawGradientRect(var5 - 4, var6 - 3, var5 - 3, var6 + var8 + 3, var9, var9);
    284        this.drawGradientRect(var5 + var4 + 3, var6 - 3, var5 + var4 + 4, var6 + var8 + 3, var9, var9);
    285        int var10 = 1347420415;
    286        int var11 = (var10 & 16711422) >> 1 | var10 & -16777216;
    287        this.drawGradientRect(var5 - 3, var6 - 3 + 1, var5 - 3 + 1, var6 + var8 + 3 - 1, var10, var11);
    288        this.drawGradientRect(var5 + var4 + 2, var6 - 3 + 1, var5 + var4 + 3, var6 + var8 + 3 - 1, var10, var11);
    289        this.drawGradientRect(var5 - 3, var6 - 3, var5 + var4 + 3, var6 - 3 + 1, var10, var10);
    290        this.drawGradientRect(var5 - 3, var6 + var8 + 2, var5 + var4 + 3, var6 + var8 + 3, var11, var11);
    291        this.fontRenderer.drawStringWithShadow(par1Str, var5, var6, -1);
    292        this.zLevel = 0.0F;
    293        itemRenderer.zLevel = 0.0F;
    294        GL11.glEnable(GL11.GL_LIGHTING);
    295        GL11.glEnable(GL11.GL_DEPTH_TEST);
    296        RenderHelper.enableStandardItemLighting();
    297        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    298    }
    299
    300    /**
    301     * Draw the foreground layer for the GuiContainer (everything in front of the items)
    302     */
    303    protected void drawGuiContainerForegroundLayer(int par1, int par2) {}
    304
    305    /**
    306     * Draw the background layer for the GuiContainer (everything behind the items)
    307     */
    308    protected abstract void drawGuiContainerBackgroundLayer(float var1, int var2, int var3);
    309
    310    /**
    311     * Draws an inventory slot
    312     */
    313    protected void drawSlotInventory(Slot par1Slot)
    314    {
    315        int var2 = par1Slot.xDisplayPosition;
    316        int var3 = par1Slot.yDisplayPosition;
    317        ItemStack var4 = par1Slot.getStack();
    318        boolean var5 = par1Slot == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick;
    319
    320        if (par1Slot == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && var4 != null)
    321        {
    322            var4 = var4.copy();
    323            var4.stackSize /= 2;
    324        }
    325
    326        this.zLevel = 100.0F;
    327        itemRenderer.zLevel = 100.0F;
    328
    329        if (var4 == null)
    330        {
    331            int var6 = par1Slot.getBackgroundIconIndex();
    332
    333            if (var6 >= 0)
    334            {
    335                GL11.glDisable(GL11.GL_LIGHTING);
    336                this.mc.renderEngine.bindTexture(this.mc.renderEngine.getTexture(par1Slot.getBackgroundIconTexture()));
    337                this.drawTexturedModalRect(var2, var3, var6 % 16 * 16, var6 / 16 * 16, 16, 16);
    338                GL11.glEnable(GL11.GL_LIGHTING);
    339                var5 = true;
    340            }
    341        }
    342
    343        if (!var5)
    344        {
    345            GL11.glEnable(GL11.GL_DEPTH_TEST);
    346            itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, var4, var2, var3);
    347            itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, var4, var2, var3);
    348        }
    349
    350        itemRenderer.zLevel = 0.0F;
    351        this.zLevel = 0.0F;
    352    }
    353
    354    /**
    355     * Returns the slot at the given coordinates or null if there is none.
    356     */
    357    private Slot getSlotAtPosition(int par1, int par2)
    358    {
    359        for (int var3 = 0; var3 < this.inventorySlots.inventorySlots.size(); ++var3)
    360        {
    361            Slot var4 = (Slot)this.inventorySlots.inventorySlots.get(var3);
    362
    363            if (this.isMouseOverSlot(var4, par1, par2))
    364            {
    365                return var4;
    366            }
    367        }
    368
    369        return null;
    370    }
    371
    372    /**
    373     * Called when the mouse is clicked.
    374     */
    375    protected void mouseClicked(int par1, int par2, int par3)
    376    {
    377        super.mouseClicked(par1, par2, par3);
    378        boolean var4 = par3 == this.mc.gameSettings.keyBindPickBlock.keyCode + 100;
    379
    380        if (par3 == 0 || par3 == 1 || var4)
    381        {
    382            Slot var5 = this.getSlotAtPosition(par1, par2);
    383            int var6 = this.guiLeft;
    384            int var7 = this.guiTop;
    385            boolean var8 = par1 < var6 || par2 < var7 || par1 >= var6 + this.xSize || par2 >= var7 + this.ySize;
    386            int var9 = -1;
    387
    388            if (var5 != null)
    389            {
    390                var9 = var5.slotNumber;
    391            }
    392
    393            if (var8)
    394            {
    395                var9 = -999;
    396            }
    397
    398            if (this.mc.gameSettings.touchscreen && var8 && this.mc.thePlayer.inventory.getItemStack() == null)
    399            {
    400                this.mc.displayGuiScreen((GuiScreen)null);
    401                return;
    402            }
    403
    404            if (var9 != -1)
    405            {
    406                if (this.mc.gameSettings.touchscreen)
    407                {
    408                    if (var5 != null && var5.getHasStack())
    409                    {
    410                        this.clickedSlot = var5;
    411                        this.draggedStack = null;
    412                        this.isRightMouseClick = par3 == 1;
    413                    }
    414                    else
    415                    {
    416                        this.clickedSlot = null;
    417                    }
    418                }
    419                else if (var4)
    420                {
    421                    this.handleMouseClick(var5, var9, par3, 3);
    422                }
    423                else
    424                {
    425                    boolean var10 = var9 != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
    426                    this.handleMouseClick(var5, var9, par3, var10 ? 1 : 0);
    427                }
    428            }
    429        }
    430    }
    431
    432    protected void func_85041_a(int par1, int par2, int par3, long par4)
    433    {
    434        if (this.clickedSlot != null && this.mc.gameSettings.touchscreen)
    435        {
    436            if (par3 == 0 || par3 == 1)
    437            {
    438                Slot var6 = this.getSlotAtPosition(par1, par2);
    439
    440                if (this.draggedStack == null)
    441                {
    442                    if (var6 != this.clickedSlot)
    443                    {
    444                        this.draggedStack = this.clickedSlot.getStack().copy();
    445                    }
    446                }
    447                else if (this.draggedStack.stackSize > 1 && var6 != null && this.func_92031_b(var6))
    448                {
    449                    long var7 = Minecraft.getSystemTime();
    450
    451                    if (this.field_92033_y == var6)
    452                    {
    453                        if (var7 - this.field_92032_z > 500L)
    454                        {
    455                            this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0);
    456                            this.handleMouseClick(var6, var6.slotNumber, 1, 0);
    457                            this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0);
    458                            this.field_92032_z = var7 + 750L;
    459                            --this.draggedStack.stackSize;
    460                        }
    461                    }
    462                    else
    463                    {
    464                        this.field_92033_y = var6;
    465                        this.field_92032_z = var7;
    466                    }
    467                }
    468            }
    469        }
    470    }
    471
    472    /**
    473     * Called when the mouse is moved or a mouse button is released.  Signature: (mouseX, mouseY, which) which==-1 is
    474     * mouseMove, which==0 or which==1 is mouseUp
    475     */
    476    protected void mouseMovedOrUp(int par1, int par2, int par3)
    477    {
    478        if (this.clickedSlot != null && this.mc.gameSettings.touchscreen)
    479        {
    480            if (par3 == 0 || par3 == 1)
    481            {
    482                Slot var4 = this.getSlotAtPosition(par1, par2);
    483                int var5 = this.guiLeft;
    484                int var6 = this.guiTop;
    485                boolean var7 = par1 < var5 || par2 < var6 || par1 >= var5 + this.xSize || par2 >= var6 + this.ySize;
    486                int var8 = -1;
    487
    488                if (var4 != null)
    489                {
    490                    var8 = var4.slotNumber;
    491                }
    492
    493                if (var7)
    494                {
    495                    var8 = -999;
    496                }
    497
    498                if (this.draggedStack == null && var4 != this.clickedSlot)
    499                {
    500                    this.draggedStack = this.clickedSlot.getStack();
    501                }
    502
    503                boolean var9 = this.func_92031_b(var4);
    504
    505                if (var8 != -1 && this.draggedStack != null && var9)
    506                {
    507                    this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, par3, 0);
    508                    this.handleMouseClick(var4, var8, 0, 0);
    509
    510                    if (this.mc.thePlayer.inventory.getItemStack() != null)
    511                    {
    512                        this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, par3, 0);
    513                        this.field_85049_r = par1 - var5;
    514                        this.field_85048_s = par2 - var6;
    515                        this.returningStackDestSlot = this.clickedSlot;
    516                        this.returningStack = this.draggedStack;
    517                        this.returningStackTime = Minecraft.getSystemTime();
    518                    }
    519                    else
    520                    {
    521                        this.returningStack = null;
    522                    }
    523                }
    524                else if (this.draggedStack != null)
    525                {
    526                    this.field_85049_r = par1 - var5;
    527                    this.field_85048_s = par2 - var6;
    528                    this.returningStackDestSlot = this.clickedSlot;
    529                    this.returningStack = this.draggedStack;
    530                    this.returningStackTime = Minecraft.getSystemTime();
    531                }
    532
    533                this.draggedStack = null;
    534                this.clickedSlot = null;
    535            }
    536        }
    537    }
    538
    539    private boolean func_92031_b(Slot par1Slot)
    540    {
    541        boolean var2 = par1Slot == null || !par1Slot.getHasStack();
    542
    543        if (par1Slot != null && par1Slot.getHasStack() && this.draggedStack != null && ItemStack.areItemStackTagsEqual(par1Slot.getStack(), this.draggedStack))
    544        {
    545            var2 |= par1Slot.getStack().stackSize + this.draggedStack.stackSize <= this.draggedStack.getMaxStackSize();
    546        }
    547
    548        return var2;
    549    }
    550
    551    /**
    552     * Returns if the passed mouse position is over the specified slot.
    553     */
    554    private boolean isMouseOverSlot(Slot par1Slot, int par2, int par3)
    555    {
    556        return this.isPointInRegion(par1Slot.xDisplayPosition, par1Slot.yDisplayPosition, 16, 16, par2, par3);
    557    }
    558
    559    /**
    560     * Args: left, top, width, height, pointX, pointY. Note: left, top are local to Gui, pointX, pointY are local to
    561     * screen
    562     */
    563    protected boolean isPointInRegion(int par1, int par2, int par3, int par4, int par5, int par6)
    564    {
    565        int var7 = this.guiLeft;
    566        int var8 = this.guiTop;
    567        par5 -= var7;
    568        par6 -= var8;
    569        return par5 >= par1 - 1 && par5 < par1 + par3 + 1 && par6 >= par2 - 1 && par6 < par2 + par4 + 1;
    570    }
    571
    572    protected void handleMouseClick(Slot par1Slot, int par2, int par3, int par4)
    573    {
    574        if (par1Slot != null)
    575        {
    576            par2 = par1Slot.slotNumber;
    577        }
    578
    579        this.mc.playerController.windowClick(this.inventorySlots.windowId, par2, par3, par4, this.mc.thePlayer);
    580    }
    581
    582    /**
    583     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    584     */
    585    protected void keyTyped(char par1, int par2)
    586    {
    587        if (par2 == 1 || par2 == this.mc.gameSettings.keyBindInventory.keyCode)
    588        {
    589            this.mc.thePlayer.closeScreen();
    590        }
    591
    592        this.checkHotbarKeys(par2);
    593
    594        if (par2 == this.mc.gameSettings.keyBindPickBlock.keyCode && this.theSlot != null && this.theSlot.getHasStack())
    595        {
    596            this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, this.ySize, 3);
    597        }
    598    }
    599
    600    /**
    601     * This function is what controls the hotbar shortcut check when you press a number key when hovering a stack.
    602     */
    603    protected boolean checkHotbarKeys(int par1)
    604    {
    605        if (this.mc.thePlayer.inventory.getItemStack() == null && this.theSlot != null)
    606        {
    607            for (int var2 = 0; var2 < 9; ++var2)
    608            {
    609                if (par1 == 2 + var2)
    610                {
    611                    this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, var2, 2);
    612                    return true;
    613                }
    614            }
    615        }
    616
    617        return false;
    618    }
    619
    620    /**
    621     * Called when the screen is unloaded. Used to disable keyboard repeat events
    622     */
    623    public void onGuiClosed()
    624    {
    625        if (this.mc.thePlayer != null)
    626        {
    627            this.inventorySlots.onCraftGuiClosed(this.mc.thePlayer);
    628        }
    629    }
    630
    631    /**
    632     * Returns true if this GUI should pause the game when it is displayed in single-player
    633     */
    634    public boolean doesGuiPauseGame()
    635    {
    636        return false;
    637    }
    638
    639    /**
    640     * Called from the main game loop to update the screen.
    641     */
    642    public void updateScreen()
    643    {
    644        super.updateScreen();
    645
    646        if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead)
    647        {
    648            this.mc.thePlayer.closeScreen();
    649        }
    650    }
    651}