/** Callback for when the crafting gui is closed. */
  public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) {
    InventoryPlayer var2 = par1EntityPlayer.inventory;

    if (var2.getItemStack() != null) {
      par1EntityPlayer.dropPlayerItem(var2.getItemStack());
      var2.setItemStack((ItemStack) null);
    }
  }
  protected void handleMouseClick(Slot par1Slot, int par2, int par3, int par4) {
    this.field_74234_w = true;
    boolean var5 = par4 == 1;
    InventoryPlayer var6;
    ItemStack var7;

    if (par1Slot != null) {
      if (par1Slot == this.field_74235_v && var5) {
        for (int var10 = 0;
            var10 < this.mc.thePlayer.inventoryContainer.getInventory().size();
            ++var10) {
          this.mc.playerController.sendSlotPacket((ItemStack) null, var10);
        }
      } else if (selectedTabIndex == CreativeTabs.tabInventory.getTabIndex()) {
        if (par1Slot == this.field_74235_v) {
          this.mc.thePlayer.inventory.setItemStack((ItemStack) null);
        } else {
          this.mc.thePlayer.inventoryContainer.slotClick(
              SlotCreativeInventory.func_75240_a((SlotCreativeInventory) par1Slot).slotNumber,
              par3,
              par4,
              this.mc.thePlayer);
          this.mc.thePlayer.inventoryContainer.updateCraftingResults();
        }
      } else if (par1Slot.inventory == inventory) {
        var6 = this.mc.thePlayer.inventory;
        var7 = var6.getItemStack();
        ItemStack var8 = par1Slot.getStack();
        ItemStack var9;

        if (par4 == 2) {
          if (var8 != null && par3 >= 0 && par3 < 9) {
            var9 = var8.copy();
            var9.stackSize = var9.getMaxStackSize();
            this.mc.thePlayer.inventory.setInventorySlotContents(par3, var9);
            this.mc.thePlayer.inventoryContainer.updateCraftingResults();
          }

          return;
        }

        if (par4 == 3) {
          if (var6.getItemStack() == null && par1Slot.getHasStack()) {
            var9 = par1Slot.getStack().copy();
            var9.stackSize = var9.getMaxStackSize();
            var6.setItemStack(var9);
          }

          return;
        }

        if (var7 != null && var8 != null && var7.isItemEqual(var8)) {
          if (par3 == 0) {
            if (var5) {
              var7.stackSize = var7.getMaxStackSize();
            } else if (var7.stackSize < var7.getMaxStackSize()) {
              ++var7.stackSize;
            }
          } else if (var7.stackSize <= 1) {
            var6.setItemStack((ItemStack) null);
          } else {
            --var7.stackSize;
          }
        } else if (var8 != null && var7 == null) {
          var6.setItemStack(ItemStack.copyItemStack(var8));
          var7 = var6.getItemStack();

          if (var5) {
            var7.stackSize = var7.getMaxStackSize();
          }
        } else {
          var6.setItemStack((ItemStack) null);
        }
      } else {
        this.inventorySlots.slotClick(par1Slot.slotNumber, par3, par4, this.mc.thePlayer);
        ItemStack var11 = this.inventorySlots.getSlot(par1Slot.slotNumber).getStack();
        this.mc.playerController.sendSlotPacket(
            var11, par1Slot.slotNumber - this.inventorySlots.inventorySlots.size() + 9 + 36);
      }
    } else {
      var6 = this.mc.thePlayer.inventory;

      if (var6.getItemStack() != null) {
        if (par3 == 0) {
          this.mc.thePlayer.dropPlayerItem(var6.getItemStack());
          this.mc.playerController.func_78752_a(var6.getItemStack());
          var6.setItemStack((ItemStack) null);
        }

        if (par3 == 1) {
          var7 = var6.getItemStack().splitStack(1);
          this.mc.thePlayer.dropPlayerItem(var7);
          this.mc.playerController.func_78752_a(var7);

          if (var6.getItemStack().stackSize == 0) {
            var6.setItemStack((ItemStack) null);
          }
        }
      }
    }
  }
  public ItemStack slotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {
    ItemStack var5 = null;

    if (par2 > 1) {
      return null;
    } else {
      if (par2 == 0 || par2 == 1) {
        InventoryPlayer var6 = par4EntityPlayer.inventory;

        if (par1 == -999) {
          if (var6.getItemStack() != null && par1 == -999) {
            if (par2 == 0) {
              par4EntityPlayer.dropPlayerItem(var6.getItemStack());
              var6.setItemStack((ItemStack) null);
            }

            if (par2 == 1) {
              par4EntityPlayer.dropPlayerItem(var6.getItemStack().splitStack(1));

              if (var6.getItemStack().stackSize == 0) {
                var6.setItemStack((ItemStack) null);
              }
            }
          }
        } else if (par3) {
          ItemStack var7 = this.transferStackInSlot(par1);

          if (var7 != null) {
            int var8 = var7.itemID;
            var5 = var7.copy();
            Slot var9 = (Slot) this.inventorySlots.get(par1);

            if (var9 != null && var9.getStack() != null && var9.getStack().itemID == var8) {
              this.retrySlotClick(par1, par2, par3, par4EntityPlayer);
            }
          }
        } else {
          if (par1 < 0) {
            return null;
          }

          Slot var12 = (Slot) this.inventorySlots.get(par1);

          if (var12 != null) {
            ItemStack var13 = var12.getStack();
            ItemStack var14 = var6.getItemStack();

            if (var13 != null) {
              var5 = var13.copy();
            }

            int var10;

            if (var13 == null) {
              if (var14 != null && var12.isItemValid(var14)) {
                var10 = par2 == 0 ? var14.stackSize : 1;

                if (var10 > var12.getSlotStackLimit()) {
                  var10 = var12.getSlotStackLimit();
                }

                var12.putStack(var14.splitStack(var10));

                if (var14.stackSize == 0) {
                  var6.setItemStack((ItemStack) null);
                }
              }
            } else if (var14 == null) {
              var10 = par2 == 0 ? var13.stackSize : (var13.stackSize + 1) / 2;
              ItemStack var11 = var12.decrStackSize(var10);
              var6.setItemStack(var11);

              if (var13.stackSize == 0) {
                var12.putStack((ItemStack) null);
              }

              var12.onPickupFromSlot(var6.getItemStack());
            } else if (var12.isItemValid(var14)) {
              if (var13.itemID == var14.itemID
                  && (!var13.getHasSubtypes() || var13.getItemDamage() == var14.getItemDamage())
                  && ItemStack.func_77970_a(var13, var14)) {
                var10 = par2 == 0 ? var14.stackSize : 1;

                if (var10 > var12.getSlotStackLimit() - var13.stackSize) {
                  var10 = var12.getSlotStackLimit() - var13.stackSize;
                }

                if (var10 > var14.getMaxStackSize() - var13.stackSize) {
                  var10 = var14.getMaxStackSize() - var13.stackSize;
                }

                var14.splitStack(var10);

                if (var14.stackSize == 0) {
                  var6.setItemStack((ItemStack) null);
                }

                var13.stackSize += var10;
              } else if (var14.stackSize <= var12.getSlotStackLimit()) {
                var12.putStack(var14);
                var6.setItemStack(var13);
              }
            } else if (var13.itemID == var14.itemID
                && var14.getMaxStackSize() > 1
                && (!var13.getHasSubtypes() || var13.getItemDamage() == var14.getItemDamage())
                && ItemStack.func_77970_a(var13, var14)) {
              var10 = var13.stackSize;

              if (var10 > 0 && var10 + var14.stackSize <= var14.getMaxStackSize()) {
                var14.stackSize += var10;
                var13 = var12.decrStackSize(var10);

                if (var13.stackSize == 0) {
                  var12.putStack((ItemStack) null);
                }

                var12.onPickupFromSlot(var6.getItemStack());
              }
            }

            var12.onSlotChanged();
          }
        }
      }

      return var5;
    }
  }