GuiContainer .java

net.minecraft.client.gui.inventory.GuiContainer (class, 767 lines): members: returningStackDestSlot, currentDragTargetSlot, dragSplittingRemnant, xSize.

net.minecraft.client.gui.inventoryclass767 linesclientextends GuiScreen27.5 KB

API Surface (13)

void initGui()
void drawScreen(int mouseX, int mouseY, float partialTicks)
void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
void mouseClicked(int mouseX, int mouseY, int mouseButton)
void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick)
void mouseReleased(int mouseX, int mouseY, int state)
boolean isPointInRegion(int left, int top, int right, int bottom, int pointX, int pointY)
void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType)
void keyTyped(char typedChar, int keyCode)
boolean checkHotbarKeys(int keyCode)
void onGuiClosed()
boolean doesGuiPauseGame()
void updateScreen()

Fields & Constants (28)

inventoryBackground
xSize
ySize
inventorySlots
guiLeft
guiTop
theSlot
clickedSlot
isRightMouseClick
draggedStack
touchUpX
touchUpY
returningStackDestSlot
returningStackTime
returningStack
currentDragTargetSlot
dragItemDropDelay
dragSplittingSlots
dragSplitting
dragSplittingLimit
dragSplittingButton
ignoreMouseUp
dragSplittingRemnant
lastClickTime
lastClickSlot

…and 3 more (see full source).

String literals (1)

"textures/gui/container/inventory.png"

Full Source

GuiContainer.java767 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui.inventory;
2
3
import com.google.common.collect.Sets;
4
import java.io.IOException;
5
import java.util.Set;
6
import net.minecraft.client.Minecraft;
7
import net.minecraft.client.gui.GuiScreen;
8
import net.minecraft.client.renderer.GlStateManager;
9
import net.minecraft.client.renderer.OpenGlHelper;
10
import net.minecraft.client.renderer.RenderHelper;
11
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
12
import net.minecraft.client.renderer.texture.TextureMap;
13
import net.minecraft.entity.player.InventoryPlayer;
14
import net.minecraft.inventory.Container;
15
import net.minecraft.inventory.Slot;
16
import net.minecraft.item.ItemStack;
17
import net.minecraft.util.EnumChatFormatting;
18
import net.minecraft.util.MathHelper;
19
import net.minecraft.util.ResourceLocation;
20
import org.lwjgl.input.Keyboard;
21
22
public abstract class GuiContainer extends GuiScreen
23
{
24
    /** The location of the inventory background texture */
25
    protected static final ResourceLocation inventoryBackground = new ResourceLocation("textures/gui/container/inventory.png");
26
27
    /** The X size of the inventory window in pixels. */
28
    protected int xSize = 176;
29
30
    /** The Y size of the inventory window in pixels. */
31
    protected int ySize = 166;
32
33
    /** A list of the players inventory slots */
34
    public Container inventorySlots;
35
36
    /**
37
     * Starting X position for the Gui. Inconsistent use for Gui backgrounds.
38
     */
39
    protected int guiLeft;
40
41
    /**
42
     * Starting Y position for the Gui. Inconsistent use for Gui backgrounds.
43
     */
44
    protected int guiTop;
45
46
    /** holds the slot currently hovered */
47
    private Slot theSlot;
48
49
    /** Used when touchscreen is enabled. */
50
    private Slot clickedSlot;
51
52
    /** Used when touchscreen is enabled. */
53
    private boolean isRightMouseClick;
54
55
    /** Used when touchscreen is enabled */
56
    private ItemStack draggedStack;
57
    private int touchUpX;
58
    private int touchUpY;
59
    private Slot returningStackDestSlot;
60
    private long returningStackTime;
61
62
    /** Used when touchscreen is enabled */
63
    private ItemStack returningStack;
64
    private Slot currentDragTargetSlot;
65
    private long dragItemDropDelay;
66
    protected final Set<Slot> dragSplittingSlots = Sets.<Slot>newHashSet();
67
    protected boolean dragSplitting;
68
    private int dragSplittingLimit;
69
    private int dragSplittingButton;
70
    private boolean ignoreMouseUp;
71
    private int dragSplittingRemnant;
72
    private long lastClickTime;
73
    private Slot lastClickSlot;
74
    private int lastClickButton;
75
    private boolean doubleClick;
76
    private ItemStack shiftClickedSlot;
77
78
    public GuiContainer(Container inventorySlotsIn)
79
    {
80
        this.inventorySlots = inventorySlotsIn;
81
        this.ignoreMouseUp = true;
82
    }
83
84
    /**
85
     * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
86
     * window resizes, the buttonList is cleared beforehand.
87
     */
88
    public void initGui()
89
    {
90
        super.initGui();
91
        this.mc.thePlayer.openContainer = this.inventorySlots;
92
        this.guiLeft = (this.width - this.xSize) / 2;
93
        this.guiTop = (this.height - this.ySize) / 2;
94
    }
95
96
    /**
97
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
98
     */
99
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
100
    {
101
        this.drawDefaultBackground();
102
        int i = this.guiLeft;
103
        int j = this.guiTop;
104
        this.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
105
        GlStateManager.disableRescaleNormal();
106
        RenderHelper.disableStandardItemLighting();
107
        GlStateManager.disableLighting();
108
        GlStateManager.disableDepth();
109
        super.drawScreen(mouseX, mouseY, partialTicks);
110
        RenderHelper.enableGUIStandardItemLighting();
111
        GlStateManager.pushMatrix();
112
        GlStateManager.translate((float)i, (float)j, 0.0F);
113
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
114
        GlStateManager.enableRescaleNormal();
115
        this.theSlot = null;
116
        int k = 240;
117
        int l = 240;
118
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)k / 1.0F, (float)l / 1.0F);
119
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
120
121
        for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
122
        {
123
            Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
124
            this.drawSlot(slot);
125
126
            if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canBeHovered())
127
            {
128
                this.theSlot = slot;
129
                GlStateManager.disableLighting();
130
                GlStateManager.disableDepth();
131
                int j1 = slot.xDisplayPosition;
132
                int k1 = slot.yDisplayPosition;
133
                GlStateManager.colorMask(true, true, true, false);
134
                this.drawGradientRect(j1, k1, j1 + 16, k1 + 16, -2130706433, -2130706433);
135
                GlStateManager.colorMask(true, true, true, true);
136
                GlStateManager.enableLighting();
137
                GlStateManager.enableDepth();
138
            }
139
        }
140
141
        RenderHelper.disableStandardItemLighting();
142
        this.drawGuiContainerForegroundLayer(mouseX, mouseY);
143
        RenderHelper.enableGUIStandardItemLighting();
144
        InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;
145
        ItemStack itemstack = this.draggedStack == null ? inventoryplayer.getItemStack() : this.draggedStack;
146
147
        if (itemstack != null)
148
        {
149
            int j2 = 8;
150
            int k2 = this.draggedStack == null ? 8 : 16;
151
            String s = null;
152
153
            if (this.draggedStack != null && this.isRightMouseClick)
154
            {
155
                itemstack = itemstack.copy();
156
                itemstack.stackSize = MathHelper.ceiling_float_int((float)itemstack.stackSize / 2.0F);
157
            }
158
            else if (this.dragSplitting && this.dragSplittingSlots.size() > 1)
159
            {
160
                itemstack = itemstack.copy();
161
                itemstack.stackSize = this.dragSplittingRemnant;
162
163
                if (itemstack.stackSize == 0)
164
                {
165
                    s = "" + EnumChatFormatting.YELLOW + "0";
166
                }
167
            }
168
169
            this.drawItemStack(itemstack, mouseX - i - j2, mouseY - j - k2, s);
170
        }
171
172
        if (this.returningStack != null)
173
        {
174
            float f = (float)(Minecraft.getSystemTime() - this.returningStackTime) / 100.0F;
175
176
            if (f >= 1.0F)
177
            {
178
                f = 1.0F;
179
                this.returningStack = null;
180
            }
181
182
            int l2 = this.returningStackDestSlot.xDisplayPosition - this.touchUpX;
183
            int i3 = this.returningStackDestSlot.yDisplayPosition - this.touchUpY;
184
            int l1 = this.touchUpX + (int)((float)l2 * f);
185
            int i2 = this.touchUpY + (int)((float)i3 * f);
186
            this.drawItemStack(this.returningStack, l1, i2, (String)null);
187
        }
188
189
        GlStateManager.popMatrix();
190
191
        if (inventoryplayer.getItemStack() == null && this.theSlot != null && this.theSlot.getHasStack())
192
        {
193
            ItemStack itemstack1 = this.theSlot.getStack();
194
            this.renderToolTip(itemstack1, mouseX, mouseY);
195
        }
196
197
        GlStateManager.enableLighting();
198
        GlStateManager.enableDepth();
199
        RenderHelper.enableStandardItemLighting();
200
    }
201
202
    /**
203
     * Render an ItemStack. Args : stack, x, y, format
204
     */
205
    private void drawItemStack(ItemStack stack, int x, int y, String altText)
206
    {
207
        GlStateManager.translate(0.0F, 0.0F, 32.0F);
208
        this.zLevel = 200.0F;
209
        this.itemRender.zLevel = 200.0F;
210
        this.itemRender.renderItemAndEffectIntoGUI(stack, x, y);
211
        this.itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, stack, x, y - (this.draggedStack == null ? 0 : 8), altText);
212
        this.zLevel = 0.0F;
213
        this.itemRender.zLevel = 0.0F;
214
    }
215
216
    /**
217
     * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
218
     */
219
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
220
    {
221
    }
222
223
    /**
224
     * Args : renderPartialTicks, mouseX, mouseY
225
     */
226
    protected abstract void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY);
227
228
    private void drawSlot(Slot slotIn)
229
    {
230
        int i = slotIn.xDisplayPosition;
231
        int j = slotIn.yDisplayPosition;
232
        ItemStack itemstack = slotIn.getStack();
233
        boolean flag = false;
234
        boolean flag1 = slotIn == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick;
235
        ItemStack itemstack1 = this.mc.thePlayer.inventory.getItemStack();
236
        String s = null;
237
238
        if (slotIn == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null)
239
        {
240
            itemstack = itemstack.copy();
241
            itemstack.stackSize /= 2;
242
        }
243
        else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null)
244
        {
245
            if (this.dragSplittingSlots.size() == 1)
246
            {
247
                return;
248
            }
249
250
            if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn))
251
            {
252
                itemstack = itemstack1.copy();
253
                flag = true;
254
                Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize);
255
256
                if (itemstack.stackSize > itemstack.getMaxStackSize())
257
                {
258
                    s = EnumChatFormatting.YELLOW + "" + itemstack.getMaxStackSize();
259
                    itemstack.stackSize = itemstack.getMaxStackSize();
260
                }
261
262
                if (itemstack.stackSize > slotIn.getItemStackLimit(itemstack))
263
                {
264
                    s = EnumChatFormatting.YELLOW + "" + slotIn.getItemStackLimit(itemstack);
265
                    itemstack.stackSize = slotIn.getItemStackLimit(itemstack);
266
                }
267
            }
268
            else
269
            {
270
                this.dragSplittingSlots.remove(slotIn);
271
                this.updateDragSplitting();
272
            }
273
        }
274
275
        this.zLevel = 100.0F;
276
        this.itemRender.zLevel = 100.0F;
277
278
        if (itemstack == null)
279
        {
280
            String s1 = slotIn.getSlotTexture();
281
282
            if (s1 != null)
283
            {
284
                TextureAtlasSprite textureatlassprite = this.mc.getTextureMapBlocks().getAtlasSprite(s1);
285
                GlStateManager.disableLighting();
286
                this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
287
                this.drawTexturedModalRect(i, j, textureatlassprite, 16, 16);
288
                GlStateManager.enableLighting();
289
                flag1 = true;
290
            }
291
        }
292
293
        if (!flag1)
294
        {
295
            if (flag)
296
            {
297
                drawRect(i, j, i + 16, j + 16, -2130706433);
298
            }
299
300
            GlStateManager.enableDepth();
301
            this.itemRender.renderItemAndEffectIntoGUI(itemstack, i, j);
302
            this.itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, itemstack, i, j, s);
303
        }
304
305
        this.itemRender.zLevel = 0.0F;
306
        this.zLevel = 0.0F;
307
    }
308
309
    private void updateDragSplitting()
310
    {
311
        ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
312
313
        if (itemstack != null && this.dragSplitting)
314
        {
315
            this.dragSplittingRemnant = itemstack.stackSize;
316
317
            for (Slot slot : this.dragSplittingSlots)
318
            {
319
                ItemStack itemstack1 = itemstack.copy();
320
                int i = slot.getStack() == null ? 0 : slot.getStack().stackSize;
321
                Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i);
322
323
                if (itemstack1.stackSize > itemstack1.getMaxStackSize())
324
                {
325
                    itemstack1.stackSize = itemstack1.getMaxStackSize();
326
                }
327
328
                if (itemstack1.stackSize > slot.getItemStackLimit(itemstack1))
329
                {
330
                    itemstack1.stackSize = slot.getItemStackLimit(itemstack1);
331
                }
332
333
                this.dragSplittingRemnant -= itemstack1.stackSize - i;
334
            }
335
        }
336
    }
337
338
    /**
339
     * Returns the slot at the given coordinates or null if there is none.
340
     */
341
    private Slot getSlotAtPosition(int x, int y)
342
    {
343
        for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i)
344
        {
345
            Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i);
346
347
            if (this.isMouseOverSlot(slot, x, y))
348
            {
349
                return slot;
350
            }
351
        }
352
353
        return null;
354
    }
355
356
    /**
357
     * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
358
     */
359
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
360
    {
361
        super.mouseClicked(mouseX, mouseY, mouseButton);
362
        boolean flag = mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100;
363
        Slot slot = this.getSlotAtPosition(mouseX, mouseY);
364
        long i = Minecraft.getSystemTime();
365
        this.doubleClick = this.lastClickSlot == slot && i - this.lastClickTime < 250L && this.lastClickButton == mouseButton;
366
        this.ignoreMouseUp = false;
367
368
        if (mouseButton == 0 || mouseButton == 1 || flag)
369
        {
370
            int j = this.guiLeft;
371
            int k = this.guiTop;
372
            boolean flag1 = mouseX < j || mouseY < k || mouseX >= j + this.xSize || mouseY >= k + this.ySize;
373
            int l = -1;
374
375
            if (slot != null)
376
            {
377
                l = slot.slotNumber;
378
            }
379
380
            if (flag1)
381
            {
382
                l = -999;
383
            }
384
385
            if (this.mc.gameSettings.touchscreen && flag1 && this.mc.thePlayer.inventory.getItemStack() == null)
386
            {
387
                this.mc.displayGuiScreen((GuiScreen)null);
388
                return;
389
            }
390
391
            if (l != -1)
392
            {
393
                if (this.mc.gameSettings.touchscreen)
394
                {
395
                    if (slot != null && slot.getHasStack())
396
                    {
397
                        this.clickedSlot = slot;
398
                        this.draggedStack = null;
399
                        this.isRightMouseClick = mouseButton == 1;
400
                    }
401
                    else
402
                    {
403
                        this.clickedSlot = null;
404
                    }
405
                }
406
                else if (!this.dragSplitting)
407
                {
408
                    if (this.mc.thePlayer.inventory.getItemStack() == null)
409
                    {
410
                        if (mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100)
411
                        {
412
                            this.handleMouseClick(slot, l, mouseButton, 3);
413
                        }
414
                        else
415
                        {
416
                            boolean flag2 = l != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
417
                            int i1 = 0;
418
419
                            if (flag2)
420
                            {
421
                                this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
422
                                i1 = 1;
423
                            }
424
                            else if (l == -999)
425
                            {
426
                                i1 = 4;
427
                            }
428
429
                            this.handleMouseClick(slot, l, mouseButton, i1);
430
                        }
431
432
                        this.ignoreMouseUp = true;
433
                    }
434
                    else
435
                    {
436
                        this.dragSplitting = true;
437
                        this.dragSplittingButton = mouseButton;
438
                        this.dragSplittingSlots.clear();
439
440
                        if (mouseButton == 0)
441
                        {
442
                            this.dragSplittingLimit = 0;
443
                        }
444
                        else if (mouseButton == 1)
445
                        {
446
                            this.dragSplittingLimit = 1;
447
                        }
448
                        else if (mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100)
449
                        {
450
                            this.dragSplittingLimit = 2;
451
                        }
452
                    }
453
                }
454
            }
455
        }
456
457
        this.lastClickSlot = slot;
458
        this.lastClickTime = i;
459
        this.lastClickButton = mouseButton;
460
    }
461
462
    /**
463
     * Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY,
464
     * lastButtonClicked & timeSinceMouseClick.
465
     */
466
    protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick)
467
    {
468
        Slot slot = this.getSlotAtPosition(mouseX, mouseY);
469
        ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
470
471
        if (this.clickedSlot != null && this.mc.gameSettings.touchscreen)
472
        {
473
            if (clickedMouseButton == 0 || clickedMouseButton == 1)
474
            {
475
                if (this.draggedStack == null)
476
                {
477
                    if (slot != this.clickedSlot && this.clickedSlot.getStack() != null)
478
                    {
479
                        this.draggedStack = this.clickedSlot.getStack().copy();
480
                    }
481
                }
482
                else if (this.draggedStack.stackSize > 1 && slot != null && Container.canAddItemToSlot(slot, this.draggedStack, false))
483
                {
484
                    long i = Minecraft.getSystemTime();
485
486
                    if (this.currentDragTargetSlot == slot)
487
                    {
488
                        if (i - this.dragItemDropDelay > 500L)
489
                        {
490
                            this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0);
491
                            this.handleMouseClick(slot, slot.slotNumber, 1, 0);
492
                            this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0);
493
                            this.dragItemDropDelay = i + 750L;
494
                            --this.draggedStack.stackSize;
495
                        }
496
                    }
497
                    else
498
                    {
499
                        this.currentDragTargetSlot = slot;
500
                        this.dragItemDropDelay = i;
501
                    }
502
                }
503
            }
504
        }
505
        else if (this.dragSplitting && slot != null && itemstack != null && itemstack.stackSize > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot))
506
        {
507
            this.dragSplittingSlots.add(slot);
508
            this.updateDragSplitting();
509
        }
510
    }
511
512
    /**
513
     * Called when a mouse button is released.  Args : mouseX, mouseY, releaseButton
514
     */
515
    protected void mouseReleased(int mouseX, int mouseY, int state)
516
    {
517
        Slot slot = this.getSlotAtPosition(mouseX, mouseY);
518
        int i = this.guiLeft;
519
        int j = this.guiTop;
520
        boolean flag = mouseX < i || mouseY < j || mouseX >= i + this.xSize || mouseY >= j + this.ySize;
521
        int k = -1;
522
523
        if (slot != null)
524
        {
525
            k = slot.slotNumber;
526
        }
527
528
        if (flag)
529
        {
530
            k = -999;
531
        }
532
533
        if (this.doubleClick && slot != null && state == 0 && this.inventorySlots.canMergeSlot((ItemStack)null, slot))
534
        {
535
            if (isShiftKeyDown())
536
            {
537
                if (slot != null && slot.inventory != null && this.shiftClickedSlot != null)
538
                {
539
                    for (Slot slot2 : this.inventorySlots.inventorySlots)
540
                    {
541
                        if (slot2 != null && slot2.canTakeStack(this.mc.thePlayer) && slot2.getHasStack() && slot2.inventory == slot.inventory && Container.canAddItemToSlot(slot2, this.shiftClickedSlot, true))
542
                        {
543
                            this.handleMouseClick(slot2, slot2.slotNumber, state, 1);
544
                        }
545
                    }
546
                }
547
            }
548
            else
549
            {
550
                this.handleMouseClick(slot, k, state, 6);
551
            }
552
553
            this.doubleClick = false;
554
            this.lastClickTime = 0L;
555
        }
556
        else
557
        {
558
            if (this.dragSplitting && this.dragSplittingButton != state)
559
            {
560
                this.dragSplitting = false;
561
                this.dragSplittingSlots.clear();
562
                this.ignoreMouseUp = true;
563
                return;
564
            }
565
566
            if (this.ignoreMouseUp)
567
            {
568
                this.ignoreMouseUp = false;
569
                return;
570
            }
571
572
            if (this.clickedSlot != null && this.mc.gameSettings.touchscreen)
573
            {
574
                if (state == 0 || state == 1)
575
                {
576
                    if (this.draggedStack == null && slot != this.clickedSlot)
577
                    {
578
                        this.draggedStack = this.clickedSlot.getStack();
579
                    }
580
581
                    boolean flag2 = Container.canAddItemToSlot(slot, this.draggedStack, false);
582
583
                    if (k != -1 && this.draggedStack != null && flag2)
584
                    {
585
                        this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, 0);
586
                        this.handleMouseClick(slot, k, 0, 0);
587
588
                        if (this.mc.thePlayer.inventory.getItemStack() != null)
589
                        {
590
                            this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, 0);
591
                            this.touchUpX = mouseX - i;
592
                            this.touchUpY = mouseY - j;
593
                            this.returningStackDestSlot = this.clickedSlot;
594
                            this.returningStack = this.draggedStack;
595
                            this.returningStackTime = Minecraft.getSystemTime();
596
                        }
597
                        else
598
                        {
599
                            this.returningStack = null;
600
                        }
601
                    }
602
                    else if (this.draggedStack != null)
603
                    {
604
                        this.touchUpX = mouseX - i;
605
                        this.touchUpY = mouseY - j;
606
                        this.returningStackDestSlot = this.clickedSlot;
607
                        this.returningStack = this.draggedStack;
608
                        this.returningStackTime = Minecraft.getSystemTime();
609
                    }
610
611
                    this.draggedStack = null;
612
                    this.clickedSlot = null;
613
                }
614
            }
615
            else if (this.dragSplitting && !this.dragSplittingSlots.isEmpty())
616
            {
617
                this.handleMouseClick((Slot)null, -999, Container.func_94534_d(0, this.dragSplittingLimit), 5);
618
619
                for (Slot slot1 : this.dragSplittingSlots)
620
                {
621
                    this.handleMouseClick(slot1, slot1.slotNumber, Container.func_94534_d(1, this.dragSplittingLimit), 5);
622
                }
623
624
                this.handleMouseClick((Slot)null, -999, Container.func_94534_d(2, this.dragSplittingLimit), 5);
625
            }
626
            else if (this.mc.thePlayer.inventory.getItemStack() != null)
627
            {
628
                if (state == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100)
629
                {
630
                    this.handleMouseClick(slot, k, state, 3);
631
                }
632
                else
633
                {
634
                    boolean flag1 = k != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
635
636
                    if (flag1)
637
                    {
638
                        this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
639
                    }
640
641
                    this.handleMouseClick(slot, k, state, flag1 ? 1 : 0);
642
                }
643
            }
644
        }
645
646
        if (this.mc.thePlayer.inventory.getItemStack() == null)
647
        {
648
            this.lastClickTime = 0L;
649
        }
650
651
        this.dragSplitting = false;
652
    }
653
654
    /**
655
     * Returns if the passed mouse position is over the specified slot. Args : slot, mouseX, mouseY
656
     */
657
    private boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY)
658
    {
659
        return this.isPointInRegion(slotIn.xDisplayPosition, slotIn.yDisplayPosition, 16, 16, mouseX, mouseY);
660
    }
661
662
    /**
663
     * Test if the 2D point is in a rectangle (relative to the GUI). Args : rectX, rectY, rectWidth, rectHeight, pointX,
664
     * pointY
665
     */
666
    protected boolean isPointInRegion(int left, int top, int right, int bottom, int pointX, int pointY)
667
    {
668
        int i = this.guiLeft;
669
        int j = this.guiTop;
670
        pointX = pointX - i;
671
        pointY = pointY - j;
672
        return pointX >= left - 1 && pointX < left + right + 1 && pointY >= top - 1 && pointY < top + bottom + 1;
673
    }
674
675
    /**
676
     * Called when the mouse is clicked over a slot or outside the gui.
677
     */
678
    protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType)
679
    {
680
        if (slotIn != null)
681
        {
682
            slotId = slotIn.slotNumber;
683
        }
684
685
        this.mc.playerController.windowClick(this.inventorySlots.windowId, slotId, clickedButton, clickType, this.mc.thePlayer);
686
    }
687
688
    /**
689
     * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
690
     * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
691
     */
692
    protected void keyTyped(char typedChar, int keyCode) throws IOException
693
    {
694
        if (keyCode == 1 || keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode())
695
        {
696
            this.mc.thePlayer.closeScreen();
697
        }
698
699
        this.checkHotbarKeys(keyCode);
700
701
        if (this.theSlot != null && this.theSlot.getHasStack())
702
        {
703
            if (keyCode == this.mc.gameSettings.keyBindPickBlock.getKeyCode())
704
            {
705
                this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, 0, 3);
706
            }
707
            else if (keyCode == this.mc.gameSettings.keyBindDrop.getKeyCode())
708
            {
709
                this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, isCtrlKeyDown() ? 1 : 0, 4);
710
            }
711
        }
712
    }
713
714
    /**
715
     * This function is what controls the hotbar shortcut check when you press a number key when hovering a stack. Args
716
     * : keyCode, Returns true if a Hotbar key is pressed, else false
717
     */
718
    protected boolean checkHotbarKeys(int keyCode)
719
    {
720
        if (this.mc.thePlayer.inventory.getItemStack() == null && this.theSlot != null)
721
        {
722
            for (int i = 0; i < 9; ++i)
723
            {
724
                if (keyCode == this.mc.gameSettings.keyBindsHotbar[i].getKeyCode())
725
                {
726
                    this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, i, 2);
727
                    return true;
728
                }
729
            }
730
        }
731
732
        return false;
733
    }
734
735
    /**
736
     * Called when the screen is unloaded. Used to disable keyboard repeat events
737
     */
738
    public void onGuiClosed()
739
    {
740
        if (this.mc.thePlayer != null)
741
        {
742
            this.inventorySlots.onContainerClosed(this.mc.thePlayer);
743
        }
744
    }
745
746
    /**
747
     * Returns true if this GUI should pause the game when it is displayed in single-player
748
     */
749
    public boolean doesGuiPauseGame()
750
    {
751
        return false;
752
    }
753
754
    /**
755
     * Called from the main game loop to update the screen.
756
     */
757
    public void updateScreen()
758
    {
759
        super.updateScreen();
760
761
        if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead)
762
        {
763
            this.mc.thePlayer.closeScreen();
764
        }
765
    }
766
}
767

Deobfuscated MCP 1.8.9 source of GuiContainer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/gui/inventory/GuiContainer.java), stored verbatim.