LTDV10/packet/kubejs/server_scripts/Sophisticated Backpacks/recipes.js
2026-04-14 18:20:56 +08:00

34 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 额应该叫背包 NBT 修改?
* @param {number} inventorySlots 背包槽数
* @param {number} upgradeSlots 背包升级槽数
* @param {string} [name] 背包名字
* @param {string} [clothColor] 表面颜色 (HEX 颜色代码)
* @param {string} [borderColor] 边框颜色HEX 颜色代码)
*/
function createBackpack(inventorySlots, upgradeSlots, name, clothColor, borderColor) {
let backpackNBT = `{inventorySlots:${inventorySlots},upgradeSlots:${upgradeSlots}`;
if (name !== undefined) {
backpackNBT += `,display:{Name:'{"italic":false,"extra":[{"text":""},{"text":"${name}"}],"text":""}'}`;
}
if (clothColor !== undefined) {
let clothColorDecimal = hexToDecimal(clothColor);
backpackNBT += `,clothColor:${clothColorDecimal}`;
}
if (borderColor !== undefined) {
let borderColorDecimal = hexToDecimal(borderColor);
backpackNBT += `,borderColor:${borderColorDecimal}`;
}
backpackNBT += `}`;
return Item.of("sophisticatedbackpacks:backpack", backpackNBT);
}
function hexToDecimal(hex) {
hex = hex.replace(/^#/, "");
return parseInt(hex, 16);
}