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

84 lines
2.2 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,
2024-04-14 17:23:52 +00:00
'netherite_hoe': 2031,
'diamond_axe': 1561,
'diamond_hoe': 1561,
2024-04-14 17:51:38 +00:00
'shears': 238,
};
/**
* Generate the JSON file.
*
2024-04-14 15:36:28 +00:00
* @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.
*/
2024-04-14 15:36:28 +00:00
function buildJSON(supportsCMD, item, namespace, models) {
2024-04-14 17:51:38 +00:00
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'] = [];
2024-04-14 15:36:28 +00:00
if (supportsCMD) {
//Insert custom model data models
for (let i = 0; i < models.length; i++) {
json['overrides'][i + 1] = {
'predicate': {
'custom_model_data': i + 1
},
'model': namespace + 'item/' + models[i]
};
}
} else {
//Insert not damaged item
json['overrides'][0] = {
'predicate': {
'damaged': 0,
'damage': 0
},
2024-04-15 17:37:12 +00:00
'model': 'item/' + item
2024-04-14 15:36:28 +00:00
};
//Insert damaged models
for (let i = 0; i < models.length; i++) {
const model = models[i];
const damage = (i + 1) / (itemDamages[item] - 1);
2021-09-02 15:09:29 +00:00
2024-04-14 15:36:28 +00:00
json['overrides'][i + 1] = {
'predicate': {
'damaged': 0,
'damage': damage
},
2024-04-15 17:37:12 +00:00
'model': namespace + model
2024-04-14 15:36:28 +00:00
};
}
2024-04-14 15:36:28 +00:00
//Insert fully damaged item
json['overrides'][models.length + 1] = {
'predicate': {
2024-04-14 15:36:28 +00:00
'damaged': 1,
'damage': 0
2021-09-02 15:09:29 +00:00
},
2024-04-14 15:36:28 +00:00
'model': 'item/' + item
};
}
return JSON.stringify(json, null, 2);
2021-09-01 20:07:16 +00:00
}