2024-04-14 10:37:48 +00:00
|
|
|
// Damage values for items
|
|
|
|
// Can be found at: https://minecraft.fandom.com/wiki/
|
2021-04-07 13:34:07 +00:00
|
|
|
const itemDamages = {
|
2024-04-14 10:37:48 +00:00
|
|
|
'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,
|
2021-04-07 13:34:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the JSON file.
|
|
|
|
*
|
2024-04-14 15:36:28 +00:00
|
|
|
* @param supportsCMD Whether custom model data is supported.
|
2021-04-07 13:34:07 +00:00
|
|
|
* @param item The item to generate it for.
|
2024-04-14 12:27:10 +00:00
|
|
|
* @param namespace The namespace to use.
|
2021-04-07 13:34:07 +00:00
|
|
|
* @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 + ":";
|
2024-04-14 12:27:10 +00:00
|
|
|
|
2021-04-07 13:34:07 +00:00
|
|
|
const json = {};
|
|
|
|
|
|
|
|
//Default values
|
|
|
|
json['parent'] = 'item/handheld';
|
|
|
|
json['textures'] = {
|
2024-04-14 12:27:10 +00:00
|
|
|
'layer0': 'item/' + item,
|
|
|
|
'layer1': 'item/' + item + '_overlay'
|
2021-04-07 13:34:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//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++) {
|
2024-10-13 12:29:21 +00:00
|
|
|
json['overrides'][i] = {
|
2024-04-14 15:36:28 +00:00
|
|
|
'predicate': {
|
|
|
|
'custom_model_data': i + 1
|
|
|
|
},
|
|
|
|
'model': namespace + 'item/' + models[i]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
2024-04-15 17:41:44 +00:00
|
|
|
//Insert not damaged item (in default namespace)
|
2024-04-14 15:36:28 +00:00
|
|
|
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++) {
|
|
|
|
json['overrides'][i + 1] = {
|
|
|
|
'predicate': {
|
|
|
|
'damaged': 0,
|
2024-04-15 17:43:01 +00:00
|
|
|
'damage': ((i + 1) / (itemDamages[item] - 1)).toFixed(6)
|
2024-04-14 15:36:28 +00:00
|
|
|
},
|
2024-04-15 17:41:44 +00:00
|
|
|
'model': namespace + 'item/' + models[i]
|
2024-04-14 15:36:28 +00:00
|
|
|
};
|
|
|
|
}
|
2021-04-07 13:34:07 +00:00
|
|
|
|
2024-04-15 17:41:44 +00:00
|
|
|
//Insert fully damaged item (in default namespace)
|
2024-04-14 15:36:28 +00:00
|
|
|
json['overrides'][models.length + 1] = {
|
2021-04-07 13:34:07 +00:00
|
|
|
'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
|
2021-04-07 13:34:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON.stringify(json, null, 2);
|
2021-09-01 20:07:16 +00:00
|
|
|
}
|