Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
0
  private boolean onTick() {

    tickNumber++;

    // Not calling "cfgManager.makeSureConfigurationIsLoaded()" for performance reasons
    InvTweaksConfig config = cfgManager.getConfig();
    if (config == null) {
      return false;
    }

    // Clone the hotbar to be able to monitor changes on it
    if (itemPickupPending) {
      onItemPickup();
    }
    apn currentScreen = getCurrentScreen();
    if (currentScreen == null || isGuiInventory(currentScreen)) {
      cloneHotbar();
    }

    // Handle sort key changes
    if (sortingKeyCodeCache != getKeyCode(SORT_KEY_BINDING)) {
      if (sortingKeyCodeCache == -1) {
        sortingKeyCodeCache = getKeyCode(SORT_KEY_BINDING);
      } else {
        int keyCode = getKeyCode(SORT_KEY_BINDING);
        if (keyCode > 0) {
          config.setProperty(InvTweaksConfig.PROP_KEY_SORT_INVENTORY, Keyboard.getKeyName(keyCode));
        }
      }
    }

    handleConfigSwitch();

    return true;
  }
Ejemplo n.º 3
0
  private boolean onTick() {

    tickNumber++;

    // Not calling "cfgManager.makeSureConfigurationIsLoaded()" for performance reasons
    InvTweaksConfig config = cfgManager.getConfig();
    if (config == null) {
      return false;
    }

    // Clone the hotbar to be able to monitor changes on it
    if (itemPickupPending) {
      onItemPickup();
    }
    aue currentScreen = getCurrentScreen();
    if (currentScreen == null || isGuiInventory(currentScreen)) {
      cloneHotbar();
    }

    // Handle sort key
    if (Keyboard.isKeyDown(config.getSortKeyCode())) {
      if (!sortKeyDown) {
        sortKeyDown = true;
        onSortingKeyPressed();
      }
    } else {
      sortKeyDown = false;
    }

    // Handle config switch
    handleConfigSwitch();

    return true;
  }
Ejemplo n.º 4
0
  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;
  }
Ejemplo n.º 5
0
  private void handleGUILayout(apn guiScreen) {

    InvTweaksConfig config = cfgManager.getConfig();
    boolean isValidChest = isValidChest(guiScreen);

    if (isValidChest || (isStandardInventory(guiScreen) && !isGuiEnchantmentTable(guiScreen))) {

      aqh guiContainer = asGuiContainer(guiScreen);
      int w = 10, h = 10;

      // Look for the mods buttons
      boolean customButtonsAdded = false;
      List<Object> controlList = getControlList(guiScreen);
      for (Object o : controlList) {
        if (isGuiButton(o)) {
          aoh button = asGuiButton(o);
          if (getId(button) == InvTweaksConst.JIMEOWAN_ID) {
            customButtonsAdded = true;
            break;
          }
        }
      }

      if (!customButtonsAdded) {

        // Check for custom button texture
        boolean customTextureAvailable = hasTexture("/gui/button10px.png");

        // Inventory button
        if (!isValidChest) {
          controlList.add(
              new InvTweaksGuiSettingsButton(
                  cfgManager,
                  InvTweaksConst.JIMEOWAN_ID,
                  getGuiX(guiContainer) + getGuiWidth(guiContainer) - 15,
                  getGuiY(guiContainer) + 5,
                  w,
                  h,
                  "...",
                  InvTweaksLocalization.get("invtweaks.button.settings.tooltip"),
                  customTextureAvailable));
        }

        // Chest buttons
        else {
          // Reset sorting algorithm selector
          chestAlgorithmClickTimestamp = 0;

          int id = InvTweaksConst.JIMEOWAN_ID,
              x = getGuiX(guiContainer) + getGuiWidth(guiContainer) - 16,
              y = getGuiY(guiContainer) + 5;
          boolean isChestWayTooBig = mods.isChestWayTooBig(guiScreen);

          // NotEnoughItems compatibility
          if (isChestWayTooBig && classExists("mod_NotEnoughItems")) {
            if (isNotEnoughItemsEnabled()) {
              x = getGuiX(guiContainer) + getGuiWidth(guiContainer) - 35;
              y += 50;
            }
          }

          // Settings button
          controlList.add(
              new InvTweaksGuiSettingsButton(
                  cfgManager,
                  id++,
                  (isChestWayTooBig) ? x + 22 : x - 1,
                  (isChestWayTooBig) ? y - 3 : y,
                  w,
                  h,
                  "...",
                  InvTweaksLocalization.get("invtweaks.button.settings.tooltip"),
                  customTextureAvailable));

          // Sorting buttons
          if (!config.getProperty(InvTweaksConfig.PROP_SHOW_CHEST_BUTTONS).equals("false")) {

            int rowSize = getContainerRowSize(guiContainer);

            InvTweaksObfuscationGuiButton button =
                new InvTweaksGuiSortingButton(
                    cfgManager,
                    id++,
                    (isChestWayTooBig) ? x + 22 : x - 13,
                    (isChestWayTooBig) ? y + 12 : y,
                    w,
                    h,
                    "h",
                    InvTweaksLocalization.get("invtweaks.button.chest3.tooltip"),
                    InvTweaksHandlerSorting.ALGORITHM_HORIZONTAL,
                    rowSize,
                    customTextureAvailable);
            controlList.add(button);

            button =
                new InvTweaksGuiSortingButton(
                    cfgManager,
                    id++,
                    (isChestWayTooBig) ? x + 22 : x - 25,
                    (isChestWayTooBig) ? y + 25 : y,
                    w,
                    h,
                    "v",
                    InvTweaksLocalization.get("invtweaks.button.chest2.tooltip"),
                    InvTweaksHandlerSorting.ALGORITHM_VERTICAL,
                    rowSize,
                    customTextureAvailable);
            controlList.add(button);

            button =
                new InvTweaksGuiSortingButton(
                    cfgManager,
                    id++,
                    (isChestWayTooBig) ? x + 22 : x - 37,
                    (isChestWayTooBig) ? y + 38 : y,
                    w,
                    h,
                    "s",
                    InvTweaksLocalization.get("invtweaks.button.chest1.tooltip"),
                    InvTweaksHandlerSorting.ALGORITHM_DEFAULT,
                    rowSize,
                    customTextureAvailable);
            controlList.add(button);
          }
        }
      }
    } else {
      // Remove "..." button from non-survival tabs of the creative screen
      if (isGuiInventoryCreative(guiScreen)) {
        List<Object> controlList = getControlList(guiScreen);
        aoh buttonToRemove = null;
        for (Object o : controlList) {
          if (isGuiButton(o)) {
            if (getId(asGuiButton(o)) == InvTweaksConst.JIMEOWAN_ID) {
              buttonToRemove = asGuiButton(o);
              break;
            }
          }
        }
        if (buttonToRemove != null) {
          controlList.remove(buttonToRemove);
        }
      }
    }
  }
Ejemplo n.º 6
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;
    }
  }
Ejemplo n.º 7
0
  private void handleConfigSwitch() {

    InvTweaksConfig config = cfgManager.getConfig();
    apn currentScreen = getCurrentScreen();

    // Switch between configurations (shortcut)
    InvTweaksShortcutMapping switchMapping =
        cfgManager
            .getShortcutsHandler()
            .isShortcutDown(InvTweaksShortcutType.MOVE_TO_SPECIFIC_HOTBAR_SLOT);
    if (isSortingShortcutDown() && switchMapping != null) {
      String newRuleset = null;
      int pressedKey = switchMapping.getKeyCodes().get(0);
      if (pressedKey >= Keyboard.KEY_1 && pressedKey <= Keyboard.KEY_9) {
        newRuleset = config.switchConfig(pressedKey - Keyboard.KEY_1);
      } else {
        switch (pressedKey) {
          case Keyboard.KEY_NUMPAD1:
            newRuleset = config.switchConfig(0);
            break;
          case Keyboard.KEY_NUMPAD2:
            newRuleset = config.switchConfig(1);
            break;
          case Keyboard.KEY_NUMPAD3:
            newRuleset = config.switchConfig(2);
            break;
          case Keyboard.KEY_NUMPAD4:
            newRuleset = config.switchConfig(3);
            break;
          case Keyboard.KEY_NUMPAD5:
            newRuleset = config.switchConfig(4);
            break;
          case Keyboard.KEY_NUMPAD6:
            newRuleset = config.switchConfig(5);
            break;
          case Keyboard.KEY_NUMPAD7:
            newRuleset = config.switchConfig(6);
            break;
          case Keyboard.KEY_NUMPAD8:
            newRuleset = config.switchConfig(7);
            break;
          case Keyboard.KEY_NUMPAD9:
            newRuleset = config.switchConfig(8);
            break;
        }
      }

      if (newRuleset != null) {
        logInGame(
            String.format(InvTweaksLocalization.get("invtweaks.loadconfig.enabled"), newRuleset),
            true);
        // Hack to prevent 2nd way to switch configs from being enabled
        sortingKeyPressedDate = Integer.MAX_VALUE;
      }
    }

    // Switch between configurations (by holding the sorting key)
    if (isSortingShortcutDown()) {
      long currentTime = System.currentTimeMillis();
      if (sortingKeyPressedDate == 0) {
        sortingKeyPressedDate = currentTime;
      } else if (currentTime - sortingKeyPressedDate > InvTweaksConst.RULESET_SWAP_DELAY
          && sortingKeyPressedDate != Integer.MAX_VALUE) {
        String previousRuleset = config.getCurrentRulesetName();
        String newRuleset = config.switchConfig();
        // Log only if there is more than 1 ruleset
        if (previousRuleset != null && newRuleset != null && !previousRuleset.equals(newRuleset)) {
          logInGame(
              String.format(InvTweaksLocalization.get("invtweaks.loadconfig.enabled"), newRuleset),
              true);
          handleSorting(currentScreen);
        }
        sortingKeyPressedDate = currentTime;
      }
    } else {
      sortingKeyPressedDate = 0;
    }
  }
Ejemplo n.º 8
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);
    }
  }