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