private void handleAutoRefill() {

    um currentStack = getFocusedStack();
    int currentStackId = (currentStack == null) ? 0 : getItemID(currentStack);
    int currentStackDamage = (currentStack == null) ? 0 : getItemDamage(currentStack);
    int focusedSlot = getFocusedSlot() + 27; // Convert to container slots index
    InvTweaksConfig config = cfgManager.getConfig();

    if (currentStackId != storedStackId || currentStackDamage != storedStackDamage) {

      if (storedFocusedSlot != focusedSlot) { // Filter selection change
        storedFocusedSlot = focusedSlot;
      } else if ((currentStack == null
              || getItemID(currentStack) == 281
                  && storedStackId == 282) // Handle eaten mushroom soup
          && (getCurrentScreen() == null
              || // Filter open inventory or other window
              isGuiEditSign(getCurrentScreen()))) {

        if (config.isAutoRefillEnabled(storedStackId, storedStackId)) {
          try {
            cfgManager
                .getAutoRefillHandler()
                .autoRefillSlot(focusedSlot, storedStackId, storedStackDamage);
          } catch (Exception e) {
            logInGameError("invtweaks.sort.autorefill.error", e);
          }
        }
      } else {
        int itemMaxDamage = getMaxDamage(getItem(currentStack));
        if (itemMaxDamage != 0
            && itemMaxDamage - currentStackDamage < InvTweaksConst.AUTO_REFILL_DAMAGE_TRESHOLD
            && itemMaxDamage - storedStackDamage >= InvTweaksConst.AUTO_REFILL_DAMAGE_TRESHOLD
            && config
                .getProperty(InvTweaksConfig.PROP_AUTO_REFILL_BEFORE_BREAK)
                .equals(InvTweaksConfig.VALUE_TRUE)
            && config.isAutoRefillEnabled(storedStackId, storedStackId)) {
          // Trigger auto-refill before the tool breaks
          try {
            cfgManager
                .getAutoRefillHandler()
                .autoRefillSlot(focusedSlot, storedStackId, storedStackDamage);
          } catch (Exception e) {
            logInGameError("invtweaks.sort.autorefill.error", e);
          }
        }
      }
    }

    // Copy some info about current selected stack for auto-refill
    storedStackId = currentStackId;
    storedStackDamage = currentStackDamage;
  }
示例#2
0
  private void handleAutoRefill() {

    rj currentStack = getFocusedStack();
    int currentStackId = (currentStack == null) ? 0 : getItemID(currentStack);
    int currentStackDamage = (currentStack == null) ? 0 : getItemDamage(currentStack);
    int focusedSlot = getFocusedSlot() + 27; // Convert to container slots index
    InvTweaksConfig config = cfgManager.getConfig();

    if (currentStackId != storedStackId || currentStackDamage != storedStackDamage) {

      if (storedFocusedSlot != focusedSlot) { // Filter selection change
        storedFocusedSlot = focusedSlot;
      } else if ((currentStack == null
              || getItemID(currentStack) == 281
                  && storedStackId == 282) // Handle eaten mushroom soup
          && (getCurrentScreen() == null
              || // Filter open inventory or other window
              isGuiEditSign(getCurrentScreen()))) {

        if (config.isAutoRefillEnabled(storedStackId, storedStackId)) {
          try {
            cfgManager
                .getAutoRefillHandler()
                .autoRefillSlot(focusedSlot, storedStackId, storedStackDamage);
          } catch (Exception e) {
            logInGameError("invtweaks.sort.autorefill.error", e);
          }
        }
      }
    }

    storedStackId = currentStackId;
    storedStackDamage = currentStackDamage;
  }
示例#3
0
  private void handleSorting(apn guiScreen) {

    rj selectedItem = null;
    int focusedSlot = getFocusedSlot();
    rj[] mainInventory = getMainInventory();
    if (focusedSlot < mainInventory.length && focusedSlot >= 0) {
      selectedItem = mainInventory[focusedSlot];
    }

    // Sorting
    try {
      new InvTweaksHandlerSorting(
              mc,
              cfgManager.getConfig(),
              InvTweaksContainerSection.INVENTORY,
              InvTweaksHandlerSorting.ALGORITHM_INVENTORY,
              InvTweaksConst.INVENTORY_ROW_SIZE)
          .sort();
    } catch (Exception e) {
      logInGameError("invtweaks.sort.inventory.error", e);
      e.printStackTrace();
    }

    playClick();

    // This needs to be remembered so that the
    // auto-refill feature doesn't trigger
    if (selectedItem != null && mainInventory[focusedSlot] == null) {
      storedStackId = 0;
    }
  }
示例#4
0
 /** When Minecraft gains focus, reset all pressed keys to avoid the "stuck keys" bug. */
 private void unlockKeysIfNecessary() {
   boolean hasFocus = Display.isActive();
   if (!hadFocus && hasFocus) {
     Keyboard.destroy();
     boolean firstTry = true;
     while (!Keyboard.isCreated()) {
       try {
         Keyboard.create();
       } catch (LWJGLException e) {
         if (firstTry) {
           logInGameError("invtweaks.keyboardfix.error", e);
           firstTry = false;
         }
       }
     }
     if (!firstTry) {
       logInGame("invtweaks.keyboardfix.recover");
     }
   }
   hadFocus = hasFocus;
 }
示例#5
0
  private void handleMiddleClick(apn guiScreen) {

    if (Mouse.isButtonDown(2)) {

      if (!cfgManager.makeSureConfigurationIsLoaded()) {
        return;
      }
      InvTweaksConfig config = cfgManager.getConfig();

      // Check that middle click sorting is allowed
      if (config
          .getProperty(InvTweaksConfig.PROP_ENABLE_MIDDLE_CLICK)
          .equals(InvTweaksConfig.VALUE_TRUE)) {

        if (!chestAlgorithmButtonDown) {
          chestAlgorithmButtonDown = true;

          InvTweaksContainerManager containerMgr = new InvTweaksContainerManager(mc);
          pr slotAtMousePosition = containerMgr.getSlotAtMousePosition();
          InvTweaksContainerSection target = null;
          if (slotAtMousePosition != null) {
            target = containerMgr.getSlotSection(getSlotNumber(slotAtMousePosition));
          }

          if (isValidChest(guiScreen)) {

            // Check if the middle click target the chest or the inventory
            // (copied GuiContainer.getSlotAtPosition algorithm)
            aqh guiContainer = asGuiContainer(guiScreen);

            if (InvTweaksContainerSection.CHEST.equals(target)) {

              // Play click
              playClick();

              long timestamp = System.currentTimeMillis();
              if (timestamp - chestAlgorithmClickTimestamp
                  > InvTweaksConst.CHEST_ALGORITHM_SWAP_MAX_INTERVAL) {
                chestAlgorithm = InvTweaksHandlerSorting.ALGORITHM_DEFAULT;
              }
              try {
                new InvTweaksHandlerSorting(
                        mc,
                        cfgManager.getConfig(),
                        InvTweaksContainerSection.CHEST,
                        chestAlgorithm,
                        getContainerRowSize(guiContainer))
                    .sort();
              } catch (Exception e) {
                logInGameError("invtweaks.sort.chest.error", e);
                e.printStackTrace();
              }
              chestAlgorithm = (chestAlgorithm + 1) % 3;
              chestAlgorithmClickTimestamp = timestamp;

            } else if (InvTweaksContainerSection.INVENTORY_HOTBAR.equals(target)
                || (InvTweaksContainerSection.INVENTORY_NOT_HOTBAR.equals(target))) {
              handleSorting(guiScreen);
            }

          } else if (isValidInventory(guiScreen)) {

            /*
                         	 // Crafting stacks evening (hook ready, TODO implement algorithm)
                         	 if (InvTweaksContainerSection.CRAFTING_IN.equals(target)) {
                                 try {
            	new InvTweaksHandlerSorting(mc, cfgManager.getConfig(),
            	        InvTweaksContainerSection.CRAFTING_IN,
            	        InvTweaksHandlerSorting.ALGORITHM_EVEN_STACKS,
            	        (containerMgr.getSize(target) == 9) ? 3 : 2).sort();
            } catch (Exception e) {
                                     logInGameError("invtweaks.sort.crafting.error", e);
                                     e.printStackTrace();
            }
                             }*/

            handleSorting(guiScreen);
          }
        }
      }
    } else {
      chestAlgorithmButtonDown = false;
    }
  }
示例#6
0
  /**
   * To be called everytime a stack has been picked up. Moves the picked up item in another slot
   * that matches best the current configuration.
   */
  public void onItemPickup() {

    if (!cfgManager.makeSureConfigurationIsLoaded()) {
      return;
    }
    InvTweaksConfig config = cfgManager.getConfig();
    // Handle option to disable this feature
    if (cfgManager
        .getConfig()
        .getProperty(InvTweaksConfig.PROP_ENABLE_SORTING_ON_PICKUP)
        .equals("false")) {
      return;
    }

    try {
      InvTweaksContainerSectionManager containerMgr =
          new InvTweaksContainerSectionManager(mc, InvTweaksContainerSection.INVENTORY);

      // Find stack slot (look in hotbar only).
      // We're looking for a brand new stack in the hotbar
      // (not an existing stack whose amount has been increased)
      int currentSlot = -1;
      for (int i = 0; i < InvTweaksConst.INVENTORY_HOTBAR_SIZE; i++) {
        rj currentHotbarStack = containerMgr.getItemStack(i + 27);
        // Don't move already started stacks
        if (currentHotbarStack != null
            && getAnimationsToGo(currentHotbarStack) == 5
            && hotbarClone[i] == null) {
          currentSlot = i + 27;
        }
      }

      if (currentSlot != -1) {
        itemPickupPending = false;

        // Find preffered slots
        List<Integer> prefferedPositions = new LinkedList<Integer>();
        InvTweaksItemTree tree = config.getTree();
        rj stack = containerMgr.getItemStack(currentSlot);
        List<InvTweaksItemTreeItem> items = tree.getItems(getItemID(stack), getItemDamage(stack));
        for (InvTweaksConfigSortingRule rule : config.getRules()) {
          if (tree.matches(items, rule.getKeyword())) {
            for (int slot : rule.getPreferredSlots()) {
              prefferedPositions.add(slot);
            }
          }
        }

        // Find best slot for stack
        boolean hasToBeMoved = true;
        if (prefferedPositions != null) {
          for (int newSlot : prefferedPositions) {
            try {
              // Already in the best slot!
              if (newSlot == currentSlot) {
                hasToBeMoved = false;
                break;
              }
              // Is the slot available?
              else if (containerMgr.getItemStack(newSlot) == null) {
                // TODO: Check rule level before to move
                if (containerMgr.move(currentSlot, newSlot)) {
                  break;
                }
              }
            } catch (TimeoutException e) {
              logInGameError("Failed to move picked up stack", e);
            }
          }
        }

        // Else, put the slot anywhere
        if (hasToBeMoved) {
          for (int i = 0; i < containerMgr.getSize(); i++) {
            if (containerMgr.getItemStack(i) == null) {
              if (containerMgr.move(currentSlot, i)) {
                break;
              }
            }
          }
        }
      }

    } catch (Exception e) {
      logInGameError("Failed to move picked up stack", e);
    }
  }