
function itemOf(tag) {
    var stacks = toStacks(tag);
    if(stacks.length>0){
        stacks.sort((a,b) => compareMod(a.mod,b.mod));
        return stacks[0].id;
    }else{
        return null;
    }
}

function compareMod(a,b){
    if(a==b) return 0;
    for(let mod of modIds){
        if(a == mod) return -1;
        if(b == mod) return 1;
    }
    console.error(a+' '+b);
    return 0;
}

function toStacks(tag) {
    return utils.listOf(Ingredient.of(tag).stacks).toArray();
}

function fluidOf(tag, amount) {
    return {
        tag: tag,
        amount: amount,
        type: 'immersiveengineering:fluid'
    };
}

function parseIntD(str, d) {
    var num = parseInt(str);
    return num != NaN? num : d;
}

function drop(str, sep) {
    var arr = str.split(sep);
    return arr[arr.length-1];
}

function mmItem(isTag, id, count) {
    var build = { type: 'masterfulmachinery:items', data: { count: count } };
    if(isTag) {
        build.data.tag = id;
    }else{
        build.data.item = id;
    }
    return build;
}