This repository has been archived on 2024-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
VPModelFileTool/dist/js/calculator.js
SBDeveloper 3d42c62b54
Some checks are pending
Validate HTML site / build (push) Waiting to run
Fixed generator issue and some template improvements
2024-10-13 14:29:21 +02:00

80 lines
2.2 KiB
JavaScript

// Damage values for items
// Can be found at: https://minecraft.fandom.com/wiki/
const itemDamages = {
'leather_helmet': 55, // Called a cap for new versions of the game
'leather_chestplate': 80,
'leather_leggings': 75,
'leather_boots': 65,
'netherite_hoe': 2031,
'diamond_axe': 1561,
'diamond_hoe': 1561,
'shears': 238,
};
/**
* Generate the JSON file.
*
* @param supportsCMD Whether custom model data is supported.
* @param item The item to generate it for.
* @param namespace The namespace to use.
* @param models An array of models to insert.
* @returns {String} The JSON for the texturepack.
*/
function buildJSON(supportsCMD, item, namespace, models) {
namespace = (namespace === "minecraft") ? "" : namespace + ":";
const json = {};
//Default values
json['parent'] = 'item/handheld';
json['textures'] = {
'layer0': 'item/' + item,
'layer1': 'item/' + item + '_overlay'
};
//Insert models
json['overrides'] = [];
if (supportsCMD) {
//Insert custom model data models
for (let i = 0; i < models.length; i++) {
json['overrides'][i] = {
'predicate': {
'custom_model_data': i + 1
},
'model': namespace + 'item/' + models[i]
};
}
} else {
//Insert not damaged item (in default namespace)
json['overrides'][0] = {
'predicate': {
'damaged': 0,
'damage': 0
},
'model': 'item/' + item
};
//Insert damaged models
for (let i = 0; i < models.length; i++) {
json['overrides'][i + 1] = {
'predicate': {
'damaged': 0,
'damage': ((i + 1) / (itemDamages[item] - 1)).toFixed(6)
},
'model': namespace + 'item/' + models[i]
};
}
//Insert fully damaged item (in default namespace)
json['overrides'][models.length + 1] = {
'predicate': {
'damaged': 1,
'damage': 0
},
'model': 'item/' + item
};
}
return JSON.stringify(json, null, 2);
}