Fellies/kubejs/server_scripts/fellies/kubejs/functions.js

94 lines
2.4 KiB
JavaScript

const air = 'minecraft:air';
function unificationBlacklistEntry(material, type) {
return { material: material, type: type };
}
function entryIsBlacklisted(material, type) {
for (var i = 0; i < unificationBlacklist.length; i++) {
if (unificationBlacklist[i].material === material && unificationBlacklist[i].type === type) {
return true;
}
}
return false;
}
function getPreferredItemInTag(tag) {
const pref = wrapArray(tag.stacks).sort(({ mod: a }, { mod: b }) => compareIndices(a, b, tag))[0] || item.of(air);
return pref;
}
function compareIndices(a, b, tag) {
if (a == b) return 0; // iff a == b, they'll be found at the same position in modPriorities
for (let mod of modPriorities) {
if (mod == a) return -1; // if a comes before b, then idx(a) < idx(b), so -1
if (mod == b) return 1; // if a comes after b, then idx(a) > idx(b), so 1
}
console.error('[' + a + ', ' + b + '] were both unaccounted for in mod unification' + (tag ? ' for ' + tag : '!'));
return 0;
}
function wrapArray(array) {
return utils.listOf(array).toArray();
}
function tagIsEmpty(tag) {
return getPreferredItemInTag(ingredient.of(tag)).id == air;
}
function gear_unification(event, material, ingot, gem, gear) {
if (gear == air) {
return;
}
var output = gear,
input,
mold = 'immersiveengineering:mold_gear';
if (ingot != air) {
input = '#forge:ingots/' + material;
} else if (gem != air) {
input = '#forge:gems/' + material;
} else {
return;
}
event.recipes.immersiveengineering.metal_press(output, ingredient.of(input, 4), mold);
event.shaped(gear, [' B ', 'BAB', ' B '], {
A: '#forge:nuggets/iron',
B: input
});
}
function rod_unification(event, material, ingot, gem, rod) {
if (rod == air) {
return;
}
event.remove({ type: 'minecraft:crafting_shaped', output: rod });
var output = item.of(rod, 2),
input,
mold = 'immersiveengineering:mold_rod';
if (ingot != air) {
input = '#forge:ingots/' + material;
} else if (gem != air) {
input = '#forge:gems/' + material;
} else {
return;
}
event.recipes.thermal.press(output, [input, mold]).energy(2400);
event.recipes.immersiveengineering.metal_press(output, input, mold);
event.shaped(output, [' A ', ' A ', ' '], {
A: input
});
}
const unificationBlacklist = [
unificationBlacklistEntry('quartz', 'gem'),
unificationBlacklistEntry('quartz', 'storage_block')
];