Ejemplo n.º 1
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;
 }