From 56c3374b318aec2a53eb1d71cb8ccd9c18433229 Mon Sep 17 00:00:00 2001 From: SBDeveloper Date: Sun, 14 Apr 2024 17:36:28 +0200 Subject: [PATCH] Added custom model data support --- dist/js/calculator.js | 72 ++++++++++++++++++++++----------------- dist/js/calculator.min.js | 2 +- dist/js/scripts.js | 49 +++++++++++++++++++++----- dist/js/scripts.min.js | 2 +- index.html | 20 +++++------ 5 files changed, 93 insertions(+), 52 deletions(-) diff --git a/dist/js/calculator.js b/dist/js/calculator.js index c0a1df0..003c3b7 100644 --- a/dist/js/calculator.js +++ b/dist/js/calculator.js @@ -11,17 +11,14 @@ const itemDamages = { /** * 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(item, namespace, models) { - if (namespace == "minecraft") { - namespace = ""; - } else { - namespace += ":"; - } +function buildJSON(supportsCMD, item, namespace, models) { + namespace = (namespace == "minecraft") ? "" : namespace + ":"; const json = {}; @@ -35,36 +32,49 @@ function buildJSON(item, namespace, models) { //Insert models json['overrides'] = []; - //Insert default model - json['overrides'][0] = { - 'predicate': { - 'damaged': 0, - 'damage': 0 - }, - 'model': namespace + 'item/' + item - }; - - for (let i = 0; i < models.length; i++) { - const model = models[i]; - const damage = (i + 1) / (itemDamages[item] - 1); - - json['overrides'][i + 1] = { + 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': damage + 'damage': 0 }, - 'model': model + 'model': namespace + 'item/' + item + }; + + //Insert damaged models + for (let i = 0; i < models.length; i++) { + const model = models[i]; + const damage = (i + 1) / (itemDamages[item] - 1); + + json['overrides'][i + 1] = { + 'predicate': { + 'damaged': 0, + 'damage': damage + }, + 'model': model + }; + } + + //Insert fully damaged item + json['overrides'][models.length + 1] = { + 'predicate': { + 'damaged': 1, + 'damage': 0 + }, + 'model': 'item/' + item }; } - //Insert damaged model - json['overrides'][models.length + 1] = { - 'predicate': { - 'damaged': 1, - 'damage': 0 - }, - 'model': 'item/' + item - }; - return JSON.stringify(json, null, 2); } diff --git a/dist/js/calculator.min.js b/dist/js/calculator.min.js index f927069..095a980 100644 --- a/dist/js/calculator.min.js +++ b/dist/js/calculator.min.js @@ -1 +1 @@ -const itemDamages={leather_helmet:55,leather_chestplate:80,leather_leggings:75,leather_boots:65,netherite_hoe:2031};function buildJSON(e,t,a){"minecraft"==t?t="":t+=":";const r={parent:"item/handheld"};r.textures={layer0:"item/"+e,layer1:"item/"+e+"_overlay"},r.overrides=[],r.overrides[0]={predicate:{damaged:0,damage:0},model:t+"item/"+e};for(let t=0;t').attr('value', key).text(itemName)); - }); - minus.click(function (e) { const currentVal = parseInt(input.attr('value')); @@ -63,19 +59,51 @@ $(document).ready(function () { minus.prop('disabled', true); } - items.append("
" + namespace + ":
"); + items.append("
" + namespace + ":item/
"); } else { input.attr('value', '0'); } }); + // Append the items to the select on load (default for CMD is checked) + $.each(itemDamages, function (key, value) { + const itemName = capitalize(key); + $select.append($('').attr('value', key).text(itemName)); + }); + + $cmd.change(function () { + $select.find('option').each(function () { + const key = $(this).val(); + const itemName = capitalize(key); + const hasSupportText = ($(this).text().includes('(supports')); + + if (key === "") { + // Keep the default "Select an item..." option as is + return; + } + + if ($cmd.is(':checked')) { + if (hasSupportText) { + const updatedText = itemName; + $(this).text(updatedText); + } + } else { + if (!hasSupportText) { + const updatedText = itemName + ' (supports ' + itemDamages[key] + ' models)'; + $(this).text(updatedText); + } + } + }); + }); + + nsp.change(function () { namespace = nsp.val(); if (namespace == "") { namespace = "minecraft"; } nsp.val(namespace); - $("span[id^='namespace']").text(namespace + ":"); + $("span[id^='namespace']").text(namespace + ":item/"); }); item.change(function () { @@ -95,6 +123,9 @@ $(document).ready(function () { form.on("submit", function (e) { e.preventDefault(); + //Check if custommodeldata is supported + const supportsCMD = $cmd.is(":checked"); + //Get selected item and amount of models const selectedItem = item.val(); const currentVal = parseInt(input.attr('value')); @@ -106,7 +137,7 @@ $(document).ready(function () { } //Convert to JSON, and set in content field (with syntax highlighting) - const json = buildJSON(selectedItem, namespace, models); + const json = buildJSON(supportsCMD, selectedItem, namespace, models); output.html(syntaxHighlight(json)); //And fix the Download button diff --git a/dist/js/scripts.min.js b/dist/js/scripts.min.js index 8ae8b15..9cc9acf 100644 --- a/dist/js/scripts.min.js +++ b/dist/js/scripts.min.js @@ -1 +1 @@ -let namespace="vp";$(document).ready((function(){const t=$("#calculatorForm"),e=$("#formItems"),a=$("#item"),n=$("#itemcount"),i=$("#items"),r=$("#content"),o=$("#copyButton"),c=$("#downloadButton"),s=$("#minus"),l=$("#plus"),p=$("input[name='quant']"),m=$("#namespace"),u=$("#item");$.each(itemDamages,(function(t,e){const a=t.split("_").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join(" ")+" (supports "+e+" models)";u.append($("").attr("value",t).text(a))})),s.click((function(t){const e=parseInt(p.attr("value"));isNaN(e)?p.attr("value","0"):(e>p.attr("min")&&p.attr("value",(e-1).toString()),e-1==p.attr("min")&&$(this).attr("disabled",!0),$("#iteminput"+e).remove())})),l.click((function(t){const e=parseInt(p.attr("value"));if(isNaN(e))p.attr("value","0");else{if(e1?s.prop("disabled",!1):s.prop("disabled",!0),i.append('
'+namespace+':
')}})),m.change((function(){namespace=m.val(),""==namespace&&(namespace="minecraft"),m.val(namespace),$("span[id^='namespace']").text(namespace+":")})),a.change((function(){if(""!==this.value){e.show();const t=itemDamages[this.value];n.prop("max",t),l.prop("disabled",!1)}else e.hide()})),t.on("submit",(function(t){t.preventDefault();const e=a.val(),n=parseInt(p.attr("value")),i=[];for(let t=0;tt.charAt(0).toUpperCase()+t.slice(1))).join(" ")}l.click((function(t){const e=parseInt(m.attr("value"));isNaN(e)?m.attr("value","0"):(e>m.attr("min")&&m.attr("value",(e-1).toString()),e-1==m.attr("min")&&$(this).attr("disabled",!0),$("#iteminput"+e).remove())})),p.click((function(t){const e=parseInt(m.attr("value"));if(isNaN(e))m.attr("value","0");else{if(e1?l.prop("disabled",!1):l.prop("disabled",!0),c.append('
'+namespace+':item/
')}})),$.each(itemDamages,(function(t,e){const a=f(t);d.append($("").attr("value",t).text(a))})),t.change((function(){d.find("option").each((function(){const e=$(this).val(),a=f(e),n=$(this).text().includes("(supports");if(""!==e)if(t.is(":checked")){if(n){const t=a;$(this).text(t)}}else if(!n){const t=a+" (supports "+itemDamages[e]+" models)";$(this).text(t)}}))})),u.change((function(){namespace=u.val(),""==namespace&&(namespace="minecraft"),u.val(namespace),$("span[id^='namespace']").text(namespace+":item/")})),n.change((function(){if(""!==this.value){a.show();const t=itemDamages[this.value];i.prop("max",t),p.prop("disabled",!1)}else a.hide()})),e.on("submit",(function(e){e.preventDefault();const a=t.is(":checked"),i=n.val(),c=parseInt(m.attr("value")),s=[];for(let t=0;t
- SBDevelopment logo -

Model File Generator

+

SBDevelopment logo Model File Generator

Generate the resourcepack asset files for your VehiclesPlus models.

-
+

You indicate which item you want to use and the path to the models models for each value. This tool then creates the .json file for you.

- +
@@ -72,9 +72,9 @@
- +
- vp: + vp:item/
@@ -83,7 +83,7 @@
-
+
Output JSON:
Fill in the form above to get an output.