I think this is would be better...
int chain[] ={0,1,2,3,4,5,6,...,28};
int chain[] ={0,4,8,12,16,20,24,1,5,9,13,17,...};
for (int i = 0; i < 28; i++) {
Item item =getInventory().getItemInSlot(chain[i]);
if (item!=null &&(item.getName().contains("pack"))){
getInventory().interact(chain[i],"Open");
sleep....
}
}