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

71 lines
1.6 KiB
JavaScript
Raw Normal View History

// 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
};
/**
* Generate the JSON file.
*
* @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(item, namespace, models) {
if (namespace == "minecraft") {
namespace = "";
} else {
namespace += ":";
}
const json = {};
//Default values
json['parent'] = 'item/handheld';
json['textures'] = {
'layer0': 'item/' + item,
'layer1': 'item/' + item + '_overlay'
};
//Insert models
json['overrides'] = [];
2021-09-02 15:09:29 +00:00
//Insert default model
json['overrides'][0] = {
'predicate': {
'damaged': 0,
'damage': 0
},
'model': namespace + 'item/' + item
2021-09-02 15:09:29 +00:00
};
for (let i = 0; i < models.length; i++) {
const model = models[i];
const damage = (i + 1) / (itemDamages[item] - 1);
2021-09-02 15:11:11 +00:00
json['overrides'][i + 1] = {
'predicate': {
'damaged': 0,
2021-09-02 15:09:29 +00:00
'damage': damage
},
'model': model
};
}
//Insert damaged model
2021-09-02 15:11:11 +00:00
json['overrides'][models.length + 1] = {
'predicate': {
'damaged': 1,
2021-09-02 15:09:29 +00:00
'damage': 0
},
'model': 'item/' + item
};
return JSON.stringify(json, null, 2);
2021-09-01 20:07:16 +00:00
}