Esempio n. 1
0
  public boolean switchTools(ToolType tool) {
    MainPlayerEntity player = world.getBot().getPlayer();
    if (player == null) return false;
    PlayerInventory inventory = player.getInventory();

    ItemStack bestTool = null;
    int bestToolSlot = -1, bestToolValue = -1;
    for (int i = 0; i < 36; i++) {
      ItemStack item = inventory.getItemAt(i);
      if (tool == null) {
        if (i > 8) break;
        if (item == null || ToolType.getById(item.getId()) == null) {
          bestTool = item;
          bestToolSlot = i;
          break;
        }
        continue;
      }
      if (item == null) continue;
      ToolType toolType = ToolType.getById(item.getId());
      if (toolType == null || toolType != tool) continue;
      int toolValue = getToolPriority(item.getId());
      if (bestTool == null || toolValue > bestToolValue) {
        bestTool = item;
        bestToolSlot = i;
        bestToolValue = toolValue;
      }
    }
    if (bestToolSlot == -1) return false;
    return switchHeldItems(bestToolSlot);
  }
Esempio n. 2
0
 public boolean switchHeldItems(int newSlot) {
   if (inventory.getCurrentHeldSlot() == newSlot) return true;
   if (newSlot > 8) {
     int hotbarSpace = 9;
     for (int hotbarIndex = 0; hotbarIndex < 9; hotbarIndex++) {
       ItemStack item = inventory.getItemAt(hotbarIndex);
       if (item == null) {
         hotbarSpace = hotbarIndex;
         break;
       } else if (ToolType.getById(item.getId()) == null && hotbarIndex < hotbarSpace)
         hotbarSpace = hotbarIndex;
     }
     if (hotbarSpace == 9) hotbarSpace = 0;
     inventory.selectItemAt(newSlot);
     inventory.selectItemAt(hotbarSpace);
     if (inventory.getSelectedItem() != null) inventory.selectItemAt(newSlot);
     inventory.close();
     newSlot = hotbarSpace;
   }
   inventory.setCurrentHeldSlot(newSlot);
   return true;
 }
Esempio n. 3
0
 @Override
 public void setWornItemAt(int slot, ItemStack item) {
   if (slot == 0) inventory.setItemAt(inventory.getCurrentHeldSlot(), item);
   else if (slot > 0 && slot <= 4) inventory.setArmorAt(slot - 1, item);
 }
Esempio n. 4
0
 @Override
 public ItemStack getWornItemAt(int slot) {
   return slot == 0
       ? inventory.getCurrentHeldItem()
       : slot > 0 && slot <= 4 ? inventory.getArmorAt(slot - 1) : null;
 }
Esempio n. 5
0
  public MainPlayerEntity(World world, MainPlayerEntity player) {
    this(world, player.getId(), player.getName(), player.getGameMode());

    inventory.setDelay(player.getInventory().getDelay());
  }