def get_all_contained_items(item, stoptest=None):
    """
    Recursively retrieve all items contained in another item

    :param text_game_maker.game_objects.items.Item item: item to retrieve items        from
    :param stoptest: callback to call on each sub-item to test whether        recursion should continue. If stoptest() == True, recursion will        continue
    :return: list of retrieved items
    :rtype: [text_game_maker.game_objects.items.Item]
    """
    ret = []
    if not item.is_container:
        return ret
    stack = [item]
    while stack:
        subitem = stack.pop(0)
        for i in subitem.items:
            ret.append(i)
            if i.is_container:
                if stoptest and stoptest(i):
                    continue
                stack.append(i)
    return ret
