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
2023-01-20 19:55:28 +01:00

57 lines
1.2 KiB
JavaScript

const itemDamages = {
'leather_boots': 64,
'netherite_hoe': 2030
};
/**
* Generate the JSON file.
*
* @param item The item to generate it for.
* @param models An array of models to insert.
* @returns {String} The JSON for the texturepack.
*/
function buildJSON(item, models) {
const json = {};
//Default values
json['parent'] = 'item/handheld';
json['textures'] = {
'layer0': 'item/' + item
};
//Insert models
json['overrides'] = [];
//Insert default model
json['overrides'][0] = {
'predicate': {
'damaged': 0,
'damage': 0
},
'model': 'item/' + item
};
for (let i = 0; i < models.length; i++) {
const model = models[i];
const damage = (i + 1) / itemDamages[item];
json['overrides'][i + 1] = {
'predicate': {
'damaged': 0,
'damage': damage
},
'model': model
};
}
//Insert damaged model
json['overrides'][models.length + 1] = {
'predicate': {
'damaged': 1,
'damage': 0
},
'model': 'item/' + item
};
return JSON.stringify(json, null, 2);
}