Guest User

[Minecraft] GuiContainer

a guest
Mar 8th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.76 KB | None | 0 0
  1. import java.util.HashSet;
  2. import java.util.Iterator;
  3. import java.util.Set;
  4.  
  5. import org.lwjgl.input.Keyboard;
  6. import org.lwjgl.opengl.GL11;
  7. import org.lwjgl.opengl.GL12;
  8.  
  9. import com.mojang.realmsclient.gui.ChatFormatting;
  10.  
  11. import net.minecraft.client.Minecraft;
  12. import net.minecraft.client.gui.FontRenderer;
  13. import net.minecraft.client.gui.GuiScreen;
  14. import net.minecraft.client.gui.inventory.GuiContainer;
  15. import net.minecraft.client.renderer.OpenGlHelper;
  16. import net.minecraft.client.renderer.RenderHelper;
  17. import net.minecraft.client.renderer.texture.TextureMap;
  18. import net.minecraft.entity.player.InventoryPlayer;
  19. import net.minecraft.inventory.Container;
  20. import net.minecraft.inventory.Slot;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.util.EnumChatFormatting;
  23. import net.minecraft.util.IIcon;
  24. import net.minecraft.util.MathHelper;
  25. import net.minecraft.util.ResourceLocation;
  26.  
  27.  
  28. public abstract class GuiContainerImpl extends GuiContainer {
  29.  
  30.     protected static final ResourceLocation texture = new ResourceLocation("textures/gui/container/inventory.png");
  31.     /** The X size of the inventory window in pixels. */
  32.     protected int xSize = 176;
  33.    
  34.     /** The Y size of the inventory window in pixels. */
  35.     protected int ySize = 166;
  36.    
  37.     /** A list of the players inventory slots */
  38.     public Container inventorySlots;
  39.    
  40.     /** Starting X position for the Gui. Inconsistent use for Gui backgrounds. */
  41.     protected int guiLeft;
  42.    
  43.     /** Starting Y position for the Gui. Inconsistent use for Gui backgrounds. */
  44.     protected int guiTop;
  45.     protected Slot theSlot;
  46.    
  47.     /** Used when touchscreen is enabled. */
  48.     protected Slot selectedSlot;
  49.    
  50.     /** Used when touchscreen is enabled. */
  51.     protected boolean isRightMouseClick;
  52.    
  53.     /** Used when touchscreen is enabled */
  54.     protected ItemStack draggedStack;
  55.     protected Slot returningStackDestSlot;
  56.     protected long returningStackTime;
  57.    
  58.     /** some touchscreen x/y variables */
  59.     protected int touchX;
  60.     protected int touchY;
  61.    
  62.     /** A set of itemstacks being placed into multiple slots while dragging */
  63.     protected final Set placedItemstacks = new HashSet();
  64.    
  65.     /** Used when touchscreen is enabled */
  66.     protected ItemStack returningStack;
  67.    
  68.     /** Some itemstack referred to shiftclicking */
  69.     protected ItemStack shiftItemstack;
  70.    
  71.     /** some touchscreen slot, seems to be the destination slot item is being moved to */
  72.     protected Slot touchDestSlot;
  73.     protected Slot lastClickedSlot;
  74.  
  75.     protected boolean isDragging;
  76.     protected boolean ignoreNextReleaseEvent;
  77.     protected boolean doubleClick;
  78.    
  79.     /** some touchscreen time-value, no need in this */
  80.     protected long lastTouchTime;
  81.     protected long lastClickTime;
  82.     protected int draggedButton;
  83.    
  84.     /** The last released button while holding an itemstack */
  85.     protected int lastReleasedButton;
  86.    
  87.     /** Stacksize of the item current being divided (when item is being dragged around the inventory) */
  88.     protected int dividedItemStacksize;
  89.    
  90.     protected int lastClickedButton;
  91.  
  92.     public GuiContainerImpl(Container container)
  93.     {
  94.         super(null);
  95.         this.inventorySlots = container;
  96.         this.ignoreNextReleaseEvent = true;
  97.     }
  98.  
  99.     /**
  100.      * Adds the buttons (and other controls) to the screen in question.
  101.      */
  102.     public void initGui()
  103.     {
  104.         this.mc.thePlayer.openContainer = this.inventorySlots;
  105.         this.guiLeft = (this.width - this.xSize) / 2;
  106.         this.guiTop = (this.height - this.ySize) / 2;
  107.     }
  108.  
  109.     /**
  110.      * Draws the screen and all the components in it.
  111.      */
  112.     public void drawScreen(int mx, int my, float partialTicks)
  113.     {
  114.         this.drawDefaultBackground();
  115.         int left = this.guiLeft;
  116.         int top = this.guiTop;
  117.         this.drawGuiContainerBackgroundLayer(partialTicks, mx, my);
  118.         GL11.glDisable(GL12.GL_RESCALE_NORMAL);
  119.         RenderHelper.disableStandardItemLighting();
  120.         GL11.glDisable(GL11.GL_LIGHTING);
  121.         GL11.glDisable(GL11.GL_DEPTH_TEST);
  122.         RenderHelper.enableGUIStandardItemLighting();
  123.         GL11.glPushMatrix();
  124.         GL11.glTranslatef((float)left, (float)top, 0.0F);
  125.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  126.         GL11.glEnable(GL12.GL_RESCALE_NORMAL);
  127.         this.theSlot = null;
  128.         short u = 240;
  129.         short v = 240;
  130.         OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)u / 1.0F, (float)v / 1.0F);
  131.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  132.         int slotY;
  133.  
  134.         for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
  135.         {
  136.             Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
  137.             this.renderSlot(slot);
  138.  
  139.             if (this.isMouseOverSlot(slot, mx, my) && slot.func_111238_b())
  140.             {
  141.                 this.theSlot = slot;
  142.                 GL11.glDisable(GL11.GL_LIGHTING);
  143.                 GL11.glDisable(GL11.GL_DEPTH_TEST);
  144.                 int slotX = slot.xDisplayPosition;
  145.                 slotY = slot.yDisplayPosition;
  146.                 GL11.glColorMask(true, true, true, false);
  147.                 this.drawGradientRect(slotX, slotY, slotX + 16, slotY + 16, -2130706433, -2130706433);
  148.                 GL11.glColorMask(true, true, true, true);
  149.                 GL11.glEnable(GL11.GL_LIGHTING);
  150.                 GL11.glEnable(GL11.GL_DEPTH_TEST);
  151.             }
  152.         }
  153.  
  154.         //Forge: Force lighting to be disabled as there are some issue where lighting would
  155.         //incorrectly be applied based on items that are in the inventory.
  156.         GL11.glDisable(GL11.GL_LIGHTING);
  157.         this.drawGuiContainerForegroundLayer(mx, my);
  158.         GL11.glEnable(GL11.GL_LIGHTING);
  159.         InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;
  160.         ItemStack itemstack = this.draggedStack == null ? inventoryplayer.getItemStack() : this.draggedStack;
  161.  
  162.         if (itemstack != null)
  163.         {
  164.             slotY = this.draggedStack == null ? 8 : 16;
  165.             String s = null;
  166.  
  167.             if (this.draggedStack != null && this.isRightMouseClick)
  168.             {
  169.                 itemstack = itemstack.copy();
  170.                 itemstack.stackSize = MathHelper.ceiling_float_int((float)itemstack.stackSize / 2.0F);
  171.             }
  172.             else if (this.isDragging && this.placedItemstacks.size() > 1)
  173.             {
  174.                 itemstack = itemstack.copy();
  175.                 itemstack.stackSize = this.dividedItemStacksize;
  176.  
  177.                 if (itemstack.stackSize == 0)
  178.                 {
  179.                     s = "" + EnumChatFormatting.YELLOW + "0";
  180.                 }
  181.             }
  182.  
  183.             this.drawItemStack(itemstack, mx - left - 8, my - top - slotY, s);
  184.         }
  185.  
  186.         if (this.returningStack != null)
  187.         {
  188.             float f1 = (float)(Minecraft.getSystemTime() - this.returningStackTime) / 100.0F;
  189.  
  190.             if (f1 >= 1.0F)
  191.             {
  192.                 f1 = 1.0F;
  193.                 this.returningStack = null;
  194.             }
  195.  
  196.             slotY = this.returningStackDestSlot.xDisplayPosition - this.touchX;
  197.             int j2 = this.returningStackDestSlot.yDisplayPosition - this.touchY;
  198.             int l1 = this.touchX + (int)((float)slotY * f1);
  199.             int i2 = this.touchY + (int)((float)j2 * f1);
  200.             this.drawItemStack(this.returningStack, l1, i2, (String)null);
  201.         }
  202.  
  203.         GL11.glPopMatrix();
  204.  
  205.         if (inventoryplayer.getItemStack() == null && this.theSlot != null && this.theSlot.getHasStack())
  206.         {
  207.             ItemStack itemstack1 = this.theSlot.getStack();
  208.             this.renderToolTip(itemstack1, mx, my);
  209.         }
  210.  
  211.         GL11.glEnable(GL11.GL_LIGHTING);
  212.         GL11.glEnable(GL11.GL_DEPTH_TEST);
  213.         RenderHelper.enableStandardItemLighting();
  214.     }
  215.  
  216.     protected void drawItemStack(ItemStack itemstack, int x, int y, String strCount)
  217.     {
  218.         GL11.glTranslatef(0.0F, 0.0F, 32.0F);
  219.         this.zLevel = 200.0F;
  220.         itemRender.zLevel = 200.0F;
  221.         FontRenderer font = null;
  222.         if (itemstack != null) font = itemstack.getItem().getFontRenderer(itemstack);
  223.         if (font == null) font = fontRendererObj;
  224.         itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), itemstack, x, y);
  225.         itemRender.renderItemOverlayIntoGUI(font, this.mc.getTextureManager(), itemstack, x, y - (this.draggedStack == null ? 0 : 8), strCount);
  226.         this.zLevel = 0.0F;
  227.         itemRender.zLevel = 0.0F;
  228.     }
  229.  
  230.     /**
  231.      * Draw the foreground layer for the GuiContainer (everything in front of the items)
  232.      */
  233.     protected void drawGuiContainerForegroundLayer(int x, int y) {}
  234.  
  235.     protected abstract void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y);
  236.  
  237.     protected void renderSlot(Slot slot)
  238.     {
  239.         int x = slot.xDisplayPosition;
  240.         int y = slot.yDisplayPosition;
  241.         ItemStack itemstack = slot.getStack();
  242.         boolean isHighlighted = false;
  243.         boolean cancelItemRender = slot == this.selectedSlot && this.draggedStack != null && !this.isRightMouseClick;
  244.         ItemStack heldItemstack = this.mc.thePlayer.inventory.getItemStack();
  245.         String itemCount = null;
  246.  
  247.         if (slot == this.selectedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null)
  248.         {
  249.             itemstack = itemstack.copy();
  250.             itemstack.stackSize /= 2;
  251.         }
  252.         else if (this.isDragging && this.placedItemstacks.contains(slot) && heldItemstack != null)
  253.         {
  254.             if (this.placedItemstacks.size() == 1)
  255.             {
  256.                 return;
  257.             }
  258.  
  259.             if (Container.func_94527_a(slot, heldItemstack, true) && this.inventorySlots.canDragIntoSlot(slot))
  260.             {
  261.                 itemstack = heldItemstack.copy();
  262.                 isHighlighted = true;
  263.                 Container.func_94525_a(this.placedItemstacks, this.draggedButton, itemstack, slot.getStack() == null ? 0 : slot.getStack().stackSize);
  264.  
  265.                 if (itemstack.stackSize > itemstack.getMaxStackSize())
  266.                 {
  267.                     itemCount = EnumChatFormatting.YELLOW + "" + itemstack.getMaxStackSize();
  268.                     itemstack.stackSize = itemstack.getMaxStackSize();
  269.                 }
  270.  
  271.                 if (itemstack.stackSize > slot.getSlotStackLimit())
  272.                 {
  273.                     itemCount = EnumChatFormatting.YELLOW + "" + slot.getSlotStackLimit();
  274.                     itemstack.stackSize = slot.getSlotStackLimit();
  275.                 }
  276.             }
  277.             else
  278.             {
  279.                 this.placedItemstacks.remove(slot);
  280.                 this.divideItemstacks();
  281.             }
  282.         }
  283.  
  284.         this.zLevel = 100.0F;
  285.         itemRender.zLevel = 100.0F;
  286.  
  287.         if (itemstack == null)
  288.         {
  289.             IIcon iicon = slot.getBackgroundIconIndex();
  290.  
  291.             if (iicon != null)
  292.             {
  293.                 GL11.glDisable(GL11.GL_LIGHTING);
  294.                 this.mc.getTextureManager().bindTexture(TextureMap.locationItemsTexture);
  295.                 this.drawTexturedModelRectFromIcon(x, y, iicon, 16, 16);
  296.                 GL11.glEnable(GL11.GL_LIGHTING);
  297.                 cancelItemRender = true;
  298.             }
  299.         }
  300.  
  301.         if (!cancelItemRender)
  302.         {
  303.             if (isHighlighted)
  304.             {
  305.                 drawRect(x, y, x + 16, y + 16, -2130706433);
  306.             }
  307.  
  308.             GL11.glEnable(GL11.GL_DEPTH_TEST);
  309.             itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), itemstack, x, y);
  310.             itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), itemstack, x, y, itemCount);
  311.         }
  312.  
  313.         itemRender.zLevel = 0.0F;
  314.         this.zLevel = 0.0F;
  315.     }
  316.  
  317.     /** Method is called while dragging mouse around the empty slots with a not null held item */
  318.     protected void divideItemstacks()
  319.     {
  320.         ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
  321.  
  322.         if (itemstack != null && this.isDragging)
  323.         {
  324.             this.dividedItemStacksize = itemstack.stackSize;
  325.             ItemStack itemstack1;
  326.             int i;
  327.  
  328.             for (Iterator iterator = this.placedItemstacks.iterator(); iterator.hasNext(); this.dividedItemStacksize -= itemstack1.stackSize - i)
  329.             {
  330.                 Slot slot = (Slot)iterator.next();
  331.                 itemstack1 = itemstack.copy();
  332.                 i = slot.getStack() == null ? 0 : slot.getStack().stackSize;
  333.                 Container.func_94525_a(this.placedItemstacks, this.draggedButton, itemstack1, i);
  334.  
  335.                 if (itemstack1.stackSize > itemstack1.getMaxStackSize())
  336.                 {
  337.                     itemstack1.stackSize = itemstack1.getMaxStackSize();
  338.                 }
  339.  
  340.                 if (itemstack1.stackSize > slot.getSlotStackLimit())
  341.                 {
  342.                     itemstack1.stackSize = slot.getSlotStackLimit();
  343.                 }
  344.             }
  345.         }
  346.     }
  347.  
  348.     /**
  349.      * Returns the slot at the given coordinates or null if there is none.
  350.      */
  351.     protected Slot getSlotAtPosition(int x, int y)
  352.     {
  353.         for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k)
  354.         {
  355.             Slot slot = (Slot)this.inventorySlots.inventorySlots.get(k);
  356.  
  357.             if (this.isMouseOverSlot(slot, x, y))
  358.             {
  359.                 return slot;
  360.             }
  361.         }
  362.  
  363.         return null;
  364.     }
  365.  
  366.     /**
  367.      * Called when the mouse is clicked.
  368.      */
  369.     protected void mouseClicked(int mx, int my, int mouseButton)
  370.     {
  371.         boolean flag = mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100;
  372.         Slot handledSlot = this.getSlotAtPosition(mx, my);
  373.         long time = Minecraft.getSystemTime();
  374.         this.doubleClick = this.lastClickedSlot == handledSlot && time - this.lastClickTime < 250L && this.lastClickedButton == mouseButton;
  375.         this.ignoreNextReleaseEvent = false;
  376.  
  377.         if (mouseButton == 0 || mouseButton == 1 || flag)
  378.         {
  379.             int x = this.guiLeft;
  380.             int y = this.guiTop;
  381.             boolean outsideBounds = mx < x || my < y || mx >= x + this.xSize || my >= y + this.ySize;
  382.             int slotIndex = -1;
  383.  
  384.             if (handledSlot != null)
  385.             {
  386.                 slotIndex = handledSlot.slotNumber;
  387.             }
  388.  
  389.             //mark item to drop
  390.             if (outsideBounds)
  391.             {
  392.                 slotIndex = -999;
  393.             }
  394.  
  395.             //exits the menu if tapped outside of the window bounds [touchscreen]
  396.             if (this.mc.gameSettings.touchscreen && outsideBounds && this.mc.thePlayer.inventory.getItemStack() == null)
  397.             {
  398.                 this.mc.displayGuiScreen((GuiScreen)null);
  399.                 return;
  400.             }
  401.  
  402.             if (slotIndex != -1)
  403.             {
  404.                 if (this.mc.gameSettings.touchscreen)
  405.                 {
  406.                     if (handledSlot != null && handledSlot.getHasStack())
  407.                     {
  408.                         this.selectedSlot = handledSlot;
  409.                         this.draggedStack = null;
  410.                         this.isRightMouseClick = mouseButton == 1;
  411.                     }
  412.                     else
  413.                     {
  414.                         this.selectedSlot = null;
  415.                     }
  416.                 }
  417.                 else if (!this.isDragging)
  418.                 {
  419.                     if (this.mc.thePlayer.inventory.getItemStack() == null)
  420.                     {
  421.                         if (mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100)
  422.                         {
  423.                             this.handleMouseClick(handledSlot, slotIndex, mouseButton, 3);
  424.                         }
  425.                         else
  426.                         {
  427.                             boolean shiftPressed = slotIndex != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
  428.                             byte action = 0; //take item
  429.  
  430.                             if (shiftPressed)
  431.                             {
  432.                                 this.shiftItemstack = handledSlot != null && handledSlot.getHasStack() ? handledSlot.getStack() : null;
  433.                                 action = 1;
  434.                             }
  435.                             else if (slotIndex == -999)
  436.                             {
  437.                                 action = 4; //drop item
  438.                             }
  439.  
  440.                             this.handleMouseClick(handledSlot, slotIndex, mouseButton, action);
  441.                         }
  442.  
  443.                         this.ignoreNextReleaseEvent = true;
  444.                     }
  445.                     else
  446.                     {
  447.                         this.isDragging = true;
  448.                         this.lastReleasedButton = mouseButton;
  449.                         this.placedItemstacks.clear();
  450.  
  451.                         if (mouseButton == 0)
  452.                         {
  453.                             this.draggedButton = 0;
  454.                         }
  455.                         else if (mouseButton == 1)
  456.                         {
  457.                             this.draggedButton = 1;
  458.                         }
  459.                     }
  460.                 }
  461.             }
  462.         }
  463.  
  464.         this.lastClickedSlot = handledSlot;
  465.         this.lastClickTime = time;
  466.         this.lastClickedButton = mouseButton;
  467.     }
  468.  
  469.     /**
  470.      * Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY,
  471.      * lastButtonClicked & timeSinceMouseClick.
  472.      */
  473.     protected void mouseClickMove(int mx, int my, int lastButtonClicked, long timeSinceMouseClick)
  474.     {
  475.         Slot slot = this.getSlotAtPosition(mx, my);
  476.         ItemStack heldItemstack = this.mc.thePlayer.inventory.getItemStack();
  477.  
  478.         if (this.selectedSlot != null && this.mc.gameSettings.touchscreen)
  479.         {
  480.             if (lastButtonClicked == 0 || lastButtonClicked == 1)
  481.             {
  482.                 if (this.draggedStack == null)
  483.                 {
  484.                     if (slot != this.selectedSlot)
  485.                     {
  486.                         this.draggedStack = this.selectedSlot.getStack().copy();
  487.                     }
  488.                 }
  489.                 else if (this.draggedStack.stackSize > 1 && slot != null && Container.func_94527_a(slot, this.draggedStack, false))
  490.                 {
  491.                     long i1 = Minecraft.getSystemTime();
  492.  
  493.                     if (this.touchDestSlot == slot)
  494.                     {
  495.                         if (i1 - this.lastTouchTime > 500L)
  496.                         {
  497.                             this.handleMouseClick(this.selectedSlot, this.selectedSlot.slotNumber, 0, 0);
  498.                             this.handleMouseClick(slot, slot.slotNumber, 1, 0);
  499.                             this.handleMouseClick(this.selectedSlot, this.selectedSlot.slotNumber, 0, 0);
  500.                             this.lastTouchTime = i1 + 750L;
  501.                             --this.draggedStack.stackSize;
  502.                         }
  503.                     }
  504.                     else
  505.                     {
  506.                         this.touchDestSlot = slot;
  507.                         this.lastTouchTime = i1;
  508.                     }
  509.                 }
  510.             }
  511.         }
  512.         else if (this.isDragging && slot != null && heldItemstack != null && heldItemstack.stackSize > this.placedItemstacks.size() && Container.func_94527_a(slot, heldItemstack, true) && slot.isItemValid(heldItemstack) && this.inventorySlots.canDragIntoSlot(slot))
  513.         {
  514.             this.placedItemstacks.add(slot);
  515.             this.divideItemstacks();
  516.         }
  517.     }
  518.  
  519.     /**
  520.      * Called when the mouse is moved or a mouse button is released.  Signature: (mouseX, mouseY, which) which==-1 is
  521.      * mouseMove, which==0 or which==1 is mouseUp
  522.      */
  523.     protected void mouseMovedOrUp(int mx, int my, int mouseButton)
  524.     {
  525.         Slot slot = this.getSlotAtPosition(mx, my);
  526.         int left = this.guiLeft;
  527.         int top = this.guiTop;
  528.         boolean outsideBounds = mx < left || my < top || mx >= left + this.xSize || my >= top + this.ySize;
  529.         int slotIndex = -1;
  530.  
  531.         if (slot != null)
  532.         {
  533.             slotIndex = slot.slotNumber;
  534.         }
  535.  
  536.         if (outsideBounds)
  537.         {
  538.             slotIndex = -999;
  539.         }
  540.  
  541.         Slot slot1;
  542.         Iterator iterator;
  543.  
  544.         if (this.doubleClick && slot != null && mouseButton == 0 && this.inventorySlots.func_94530_a((ItemStack)null, slot))
  545.         {
  546.             if (isShiftKeyDown())
  547.             {
  548.                 if (slot != null && slot.inventory != null && this.shiftItemstack != null)
  549.                 {
  550.                     iterator = this.inventorySlots.inventorySlots.iterator();
  551.  
  552.                     while (iterator.hasNext())
  553.                     {
  554.                         slot1 = (Slot)iterator.next();
  555.  
  556.                         if (slot1 != null && slot1.canTakeStack(this.mc.thePlayer) && slot1.getHasStack() && slot1.inventory == slot.inventory && Container.func_94527_a(slot1, this.shiftItemstack, true))
  557.                         {
  558.                             this.handleMouseClick(slot1, slot1.slotNumber, mouseButton, 1);
  559.                         }
  560.                     }
  561.                 }
  562.             }
  563.             else
  564.             {
  565.                 //performs double click: collects as many items as it can
  566.                 //from all over the inventory into a held item
  567.                 this.handleMouseClick(slot, slotIndex, mouseButton, 6);
  568.             }
  569.  
  570.             this.doubleClick = false;
  571.             this.lastClickTime = 0L;
  572.         }
  573.         else
  574.         {
  575.             if (this.isDragging && this.lastReleasedButton != mouseButton)
  576.             {
  577.                 this.isDragging = false;
  578.                 this.placedItemstacks.clear();
  579.                 this.ignoreNextReleaseEvent = true;
  580.                 return;
  581.             }
  582.  
  583.             if (this.ignoreNextReleaseEvent)
  584.             {
  585.                 this.ignoreNextReleaseEvent = false;
  586.                 return;
  587.             }
  588.  
  589.             boolean shiftPressed;
  590.  
  591.             //ignoring this section, nah need in this
  592.             if (this.selectedSlot != null && this.mc.gameSettings.touchscreen)
  593.             {
  594.                 if (mouseButton == 0 || mouseButton == 1)
  595.                 {
  596.                     if (this.draggedStack == null && slot != this.selectedSlot)
  597.                     {
  598.                         this.draggedStack = this.selectedSlot.getStack();
  599.                     }
  600.  
  601.                     shiftPressed = Container.func_94527_a(slot, this.draggedStack, false);
  602.  
  603.                     if (slotIndex != -1 && this.draggedStack != null && shiftPressed)
  604.                     {
  605.                         this.handleMouseClick(this.selectedSlot, this.selectedSlot.slotNumber, mouseButton, 0);
  606.                         this.handleMouseClick(slot, slotIndex, 0, 0);
  607.                        
  608.                         if (this.mc.thePlayer.inventory.getItemStack() != null)
  609.                         {
  610.                             this.handleMouseClick(this.selectedSlot, this.selectedSlot.slotNumber, mouseButton, 0);
  611.                             this.touchX = mx - left;
  612.                             this.touchY = my - top;
  613.                             this.returningStackDestSlot = this.selectedSlot;
  614.                             this.returningStack = this.draggedStack;
  615.                             this.returningStackTime = Minecraft.getSystemTime();
  616.                         }
  617.                         else
  618.                         {
  619.                             this.returningStack = null;
  620.                         }
  621.                     }
  622.                     else if (this.draggedStack != null)
  623.                     {
  624.                         this.touchX = mx - left;
  625.                         this.touchY = my - top;
  626.                         this.returningStackDestSlot = this.selectedSlot;
  627.                         this.returningStack = this.draggedStack;
  628.                         this.returningStackTime = Minecraft.getSystemTime();
  629.                     }
  630.  
  631.                     this.draggedStack = null;
  632.                     this.selectedSlot = null;
  633.                 }
  634.             }
  635.             else if (isDragging && !this.placedItemstacks.isEmpty())
  636.             {
  637.                 this.handleMouseClick((Slot)null, -999, Container.func_94534_d(0, this.draggedButton), 5);
  638.                 iterator = this.placedItemstacks.iterator();
  639.                
  640.                 while (iterator.hasNext())
  641.                 {
  642.                     slot1 = (Slot)iterator.next();
  643.                     this.handleMouseClick(slot1, slot1.slotNumber, Container.func_94534_d(1, this.draggedButton), 5);
  644.                 }
  645.                
  646.                 this.handleMouseClick((Slot)null, -999, Container.func_94534_d(2, this.draggedButton), 5);
  647.             }
  648.             else if (this.mc.thePlayer.inventory.getItemStack() != null)
  649.             {
  650.                 if (mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100)
  651.                 {
  652.                     this.handleMouseClick(slot, slotIndex, mouseButton, 3);
  653.                 }
  654.                 else
  655.                 {
  656.                     shiftPressed = slotIndex != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
  657.                     if (shiftPressed)
  658.                     {
  659.                        this.shiftItemstack = slot != null && slot.getHasStack() ? slot.getStack() : null;
  660.                     }
  661.  
  662.                     this.handleMouseClick(slot, slotIndex, mouseButton, shiftPressed ? 1 : 0);
  663.                 }
  664.             }
  665.         }
  666.  
  667.         if (this.mc.thePlayer.inventory.getItemStack() == null)
  668.         {
  669.             this.lastClickTime = 0L;
  670.         }
  671.  
  672.         this.isDragging = false;
  673.     }
  674.  
  675.     /**
  676.      * Returns if the passed mouse position is over the specified slot.
  677.      */
  678.     protected boolean isMouseOverSlot(Slot slot, int mx, int my)
  679.     {
  680.         return this.isPointInRegion(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mx, my);
  681.     }
  682.  
  683.     protected boolean isPointInRegion(int left, int top, int width, int height, int pointX, int pointY)
  684.     {
  685.         int k1 = this.guiLeft;
  686.         int l1 = this.guiTop;
  687.         pointX -= k1;
  688.         pointY -= l1;
  689.         return pointX >= left - 1 && pointX < left + width + 1 && pointY >= top - 1 && pointY < top + height + 1;
  690.     }
  691.  
  692.     protected void handleMouseClick(Slot slot, int slotIndex, int mouseButton, int par4)
  693.     {
  694.         if (slot != null)
  695.         {
  696.             slotIndex = slot.slotNumber;
  697.         }
  698.  
  699.         this.mc.playerController.windowClick(this.inventorySlots.windowId, slotIndex, mouseButton, par4, this.mc.thePlayer);
  700.     }
  701.  
  702.     /**
  703.      * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
  704.      */
  705.     protected void keyTyped(char keyChar, int keyCode)
  706.     {
  707.         this.checkHotbarKeys(keyCode);
  708.  
  709.         if (this.theSlot != null && this.theSlot.getHasStack())
  710.         {
  711.             if (keyCode == this.mc.gameSettings.keyBindPickBlock.getKeyCode())
  712.             {
  713.                 this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, 0, 3);
  714.             }
  715.             else if (keyCode == this.mc.gameSettings.keyBindDrop.getKeyCode())
  716.             {
  717.                 this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, isCtrlKeyDown() ? 1 : 0, 4);
  718.             }
  719.         }
  720.     }
  721.  
  722.     /**
  723.      * This function is what controls the hotbar shortcut check when you press a number key when hovering a stack.
  724.      */
  725.     protected boolean checkHotbarKeys(int pressedNumber)
  726.     {
  727.         if (this.mc.thePlayer.inventory.getItemStack() == null && this.theSlot != null)
  728.         {
  729.             for (int j = 0; j < 9; ++j)
  730.             {
  731.                 if (pressedNumber == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode())
  732.                 {
  733.                     this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, j, 2);
  734.                     return true;
  735.                 }
  736.             }
  737.         }
  738.  
  739.         return false;
  740.     }
  741.  
  742.     /**
  743.      * Called when the screen is unloaded. Used to disable keyboard repeat events
  744.      */
  745.     public void onGuiClosed()
  746.     {
  747.         if (this.mc.thePlayer != null)
  748.         {
  749.             this.inventorySlots.onContainerClosed(this.mc.thePlayer);
  750.         }
  751.     }
  752.  
  753.     /**
  754.      * Returns true if this GUI should pause the game when it is displayed in single-player
  755.      */
  756.     public boolean doesGuiPauseGame()
  757.     {
  758.         return false;
  759.     }
  760.  
  761.     /**
  762.      * Called from the main game loop to update the screen.
  763.      */
  764.     public void updateScreen()
  765.     {
  766.         if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead)
  767.         {
  768.             this.mc.thePlayer.closeScreen();
  769.         }
  770.     }
  771. }
Advertisement
Add Comment
Please, Sign In to add comment