/**
  * Performs all the functions associated with the install button. This requires communicating with
  * the server.
  */
 private void doInstall() {
   ItemStack stack = targetItem.getSelectedItem().getItem();
   IPowerModule module = targetModule.getSelectedModule().getModule();
   if (player.capabilities.isCreativeMode
       || MuseItemUtils.hasInInventory(module.getInstallCost(), player.inventory)) {
     Musique.playClientSound(SoundLoader.SOUND_GUI_INSTALL, 1);
     // Now send request to server to make it legit
     MusePacket newpacket =
         new MusePacketInstallModuleRequest(
             (Player) player, targetItem.getSelectedItem().inventorySlot, module.getName());
     player.sendQueue.addToSendQueue(newpacket.getPacket250());
   }
 }
 private void doSalvage() {
   IPowerModule module = targetModule.getSelectedModule().getModule();
   MusePacket newpacket =
       new MusePacketSalvageModuleRequest(
           (Player) player, targetItem.getSelectedItem().inventorySlot, module.getName());
   player.sendQueue.addToSendQueue(newpacket.getPacket250());
 }
 @Override
 public void draw() {
   if (targetItem.getSelectedItem() != null && targetModule.getSelectedModule() != null) {
     drawBackground();
     drawItems();
     drawButtons();
   }
 }
 @Override
 public void onMouseUp(double x, double y, int button) {
   if (selectedSlider != null
       && itemTarget.getSelectedItem() != null
       && moduleTarget.getSelectedModule() != null) {
     ClickableItem item = itemTarget.getSelectedItem();
     IPowerModule module = moduleTarget.getSelectedModule().getModule();
     MusePacket tweakRequest =
         new MusePacketTweakRequest(
             (Player) player,
             item.inventorySlot,
             module.getName(),
             selectedSlider.getName(),
             selectedSlider.getValue());
     player.sendQueue.addToSendQueue(tweakRequest.getPacket250());
   }
   if (button == 0) {
     selectedSlider = null;
   }
 }
  private void drawButtons() {
    ItemStack stack = targetItem.getSelectedItem().getItem();
    IPowerModule module = targetModule.getSelectedModule().getModule();
    if (!MuseItemUtils.itemHasModule(stack, module.getName())) {

      installButton.setEnabled(
          player.capabilities.isCreativeMode
              || MuseItemUtils.hasInInventory(module.getInstallCost(), player.inventory));
      installButton.draw();
    } else {
      salvageButton.draw();
    }
  }
 @Override
 public void update(double mousex, double mousey) {
   mousex /= SCALERATIO;
   mousey /= SCALERATIO;
   if (itemTarget.getSelectedItem() != null && moduleTarget.getSelectedModule() != null) {
     ItemStack stack = itemTarget.getSelectedItem().getItem();
     IPowerModule module = moduleTarget.getSelectedModule().getModule();
     if (MuseItemUtils.itemHasModule(
         itemTarget.getSelectedItem().getItem(),
         moduleTarget.getSelectedModule().getModule().getName())) {
       loadTweaks(stack, module);
     } else {
       sliders = null;
       propertyStrings = null;
     }
   } else {
     sliders = null;
     propertyStrings = null;
   }
   if (selectedSlider != null) {
     selectedSlider.moveSlider(mousex, mousey);
   }
 }
 @Override
 public List<String> getToolTip(int x, int y) {
   if (targetItem.getSelectedItem() != null && targetModule.getSelectedModule() != null) {
     ItemStack stack = targetItem.getSelectedItem().getItem();
     IPowerModule module = targetModule.getSelectedModule().getModule();
     List<ItemStack> itemsToCheck = module.getInstallCost();
     double yoffset;
     if (!MuseItemUtils.itemHasModule(stack, module.getName())) {
       yoffset = border.top() + 4;
     } else {
       yoffset = border.bottom() - 20;
     }
     if (yoffset + 16 > y && yoffset < y) {
       double xoffset = -8.0 * itemsToCheck.size() + (border.left() + border.right()) / 2;
       if (xoffset + 16 * itemsToCheck.size() > x && xoffset < x) {
         int index = (int) (x - xoffset) / 16;
         List<String> tip = itemsToCheck.get(index).getTooltip(player, false);
         return tip;
       }
     }
   }
   return null;
 }
 private void drawItems() {
   ItemStack stack = targetItem.getSelectedItem().getItem();
   IPowerModule module = targetModule.getSelectedModule().getModule();
   List<ItemStack> itemsToDraw = module.getInstallCost();
   double yoffset;
   if (!MuseItemUtils.itemHasModule(stack, module.getName())) {
     yoffset = border.top() + 4;
   } else {
     yoffset = border.bottom() - 20;
   }
   double xoffset = -8.0 * itemsToDraw.size() + (border.left() + border.right()) / 2;
   int i = 0;
   for (ItemStack costItem : itemsToDraw) {
     MuseRenderer.drawItemAt(16 * i++ + xoffset, yoffset, costItem);
   }
 }
  @Override
  public void onMouseDown(double x, double y, int button) {
    ClickableItem selItem = targetItem.getSelectedItem();
    ClickableModule selModule = targetModule.getSelectedModule();
    if (selItem != null && selModule != null) {
      ItemStack stack = selItem.getItem();
      IPowerModule module = selModule.getModule();

      if (!MuseItemUtils.itemHasModule(stack, module.getName())) {
        if (installButton.hitBox(x, y)) {
          doInstall();
        }
      } else {
        if (salvageButton.hitBox(x, y)) {
          doSalvage();
        }
      }
    }
  }