Added more items, basic cleanup

This commit is contained in:
Stijn Bannink 2024-04-14 19:51:38 +02:00
parent 5fbf906391
commit 40a3b0de94
Signed by: SBDeveloper
GPG key ID: B730712F2C3A9D7A
4 changed files with 13 additions and 15 deletions

View file

@ -8,6 +8,7 @@ const itemDamages = {
'netherite_hoe': 2031,
'diamond_axe': 1561,
'diamond_hoe': 1561,
'shears': 238,
};
/**
@ -20,7 +21,7 @@ const itemDamages = {
* @returns {String} The JSON for the texturepack.
*/
function buildJSON(supportsCMD, item, namespace, models) {
namespace = (namespace == "minecraft") ? "" : namespace + ":";
namespace = (namespace === "minecraft") ? "" : namespace + ":";
const json = {};

View file

@ -1 +1 @@
const itemDamages={leather_helmet:55,leather_chestplate:80,leather_leggings:75,leather_boots:65,netherite_hoe:2031,diamond_axe:1561,diamond_hoe:1561};function buildJSON(e,t,a,d){a="minecraft"==a?"":a+":";const r={parent:"item/handheld"};if(r.textures={layer0:"item/"+t,layer1:"item/"+t+"_overlay"},r.overrides=[],e)for(let e=0;e<d.length;e++)r.overrides[e+1]={predicate:{custom_model_data:e+1},model:a+"item/"+d[e]};else{r.overrides[0]={predicate:{damaged:0,damage:0},model:a+"item/"+t};for(let e=0;e<d.length;e++){const a=d[e],i=(e+1)/(itemDamages[t]-1);r.overrides[e+1]={predicate:{damaged:0,damage:i},model:a}}r.overrides[d.length+1]={predicate:{damaged:1,damage:0},model:"item/"+t}}return JSON.stringify(r,null,2)}
const itemDamages={leather_helmet:55,leather_chestplate:80,leather_leggings:75,leather_boots:65,netherite_hoe:2031,diamond_axe:1561,diamond_hoe:1561,shears:238};function buildJSON(supportsCMD,item,namespace,models){namespace=namespace==="minecraft"?"":namespace+":";const json={};json["parent"]="item/handheld";json["textures"]={layer0:"item/"+item,layer1:"item/"+item+"_overlay"};json["overrides"]=[];if(supportsCMD){for(let i=0;i<models.length;i++){json["overrides"][i+1]={predicate:{custom_model_data:i+1},model:namespace+"item/"+models[i]}}}else{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]={predicate:{damaged:0,damage:damage},model:model}}json["overrides"][models.length+1]={predicate:{damaged:1,damage:0},model:"item/"+item}}return JSON.stringify(json,null,2)}

21
dist/js/scripts.js vendored
View file

@ -22,7 +22,7 @@ $(document).ready(function () {
const $select = $('#item');
minus.click(function (e) {
minus.click(function () {
const currentVal = parseInt(input.attr('value'));
if (!isNaN(currentVal)) {
@ -30,7 +30,7 @@ $(document).ready(function () {
input.attr('value', (currentVal - 1).toString());
}
if (currentVal - 1 == input.attr('min')) {
if (currentVal - 1 === input.attr('min')) {
$(this).attr('disabled', true);
}
@ -40,7 +40,7 @@ $(document).ready(function () {
}
});
plus.click(function (e) {
plus.click(function () {
const currentVal = parseInt(input.attr('value'));
if (!isNaN(currentVal)) {
@ -48,7 +48,7 @@ $(document).ready(function () {
input.attr('value', (currentVal + 1).toString());
}
if (currentVal == input.attr('max')) {
if (currentVal === input.attr('max')) {
$(this).attr('disabled', true);
return;
}
@ -66,7 +66,7 @@ $(document).ready(function () {
});
// Append the items to the select on load (default for CMD is checked)
$.each(itemDamages, function (key, value) {
$.each(itemDamages, function (key) {
const itemName = capitalize(key);
$select.append($('<option></option>').attr('value', key).text(itemName));
});
@ -84,8 +84,7 @@ $(document).ready(function () {
if ($cmd.is(':checked')) {
if (hasSupportText) {
const updatedText = itemName;
$(this).text(updatedText);
$(this).text(itemName);
}
} else {
if (!hasSupportText) {
@ -99,9 +98,7 @@ $(document).ready(function () {
nsp.change(function () {
namespace = nsp.val();
if (namespace == "") {
namespace = "minecraft";
}
if (!namespace) namespace = "minecraft";
nsp.val(namespace);
$("span[id^='namespace']").text(namespace + ":item/");
});
@ -156,9 +153,9 @@ $(document).ready(function () {
/**
* Capitalize a string.
*
*
* @param {string} str A string to capitalize
* @returns
* @returns
*/
function capitalize(str) {
return str.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');

View file

@ -1 +1 @@
let namespace="vp";$(document).ready((function(){const t=$("#custommodeldata"),e=$("#calculatorForm"),a=$("#formItems"),n=$("#item"),i=$("#itemcount"),c=$("#items"),o=$("#content"),s=$("#copyButton"),r=$("#downloadButton"),l=$("#minus"),p=$("#plus"),m=$("input[name='quant']"),u=$("#namespace"),d=$("#item");function f(t){return t.split("_").map((t=>t.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(e<m.attr("max")&&m.attr("value",(e+1).toString()),e==m.attr("max"))return void $(this).attr("disabled",!0);parseInt(m.attr("value"))>1?l.prop("disabled",!1):l.prop("disabled",!0),c.append('<div id="iteminput'+(e+1)+'" class="mb-3 w-50"><label for="item'+(e+1)+'">Model for damage '+(e+1)+':</label><div class="input-group mb-3"><span class="input-group-text" id="namespace'+(e+1)+'">'+namespace+':item/</span><input type="text" class="form-control" id="item'+(e+1)+'" name="item'+(e+1)+'" placeholder="cars/'+function(){const t=["red_car","blue_car","green_car","orange_car","blue_bicycle","red_bicycle","green_bicycle","orange_bicycle"];return t[Math.floor(Math.random()*t.length)]}()+'" required></div></div>')}})),$.each(itemDamages,(function(t,e){const a=f(t);d.append($("<option></option>").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<c;t++)s[t]=$("#item"+(t+1)).val();const l=buildJSON(a,i,namespace,s);o.html(syntaxHighlight(l));const p="data:text/json;charset=utf-8,"+encodeURIComponent(l);return r.attr("href",p),r.attr("download",i+".json"),!1})),s.click((function(t){t.preventDefault(),navigator.clipboard.writeText(o.text())}))}));
let namespace="vp";$(document).ready(function(){const $cmd=$("#custommodeldata");const form=$("#calculatorForm");const formOptions=$("#formItems");const item=$("#item");const itemCount=$("#itemcount");const items=$("#items");const output=$("#content");const copyButton=$("#copyButton");const downloadButton=$("#downloadButton");const minus=$("#minus");const plus=$("#plus");const input=$("input[name='quant']");const nsp=$("#namespace");const $select=$("#item");minus.click(function(){const currentVal=parseInt(input.attr("value"));if(!isNaN(currentVal)){if(currentVal>input.attr("min")){input.attr("value",(currentVal-1).toString())}if(currentVal-1===input.attr("min")){$(this).attr("disabled",true)}$("#iteminput"+currentVal).remove()}else{input.attr("value","0")}});plus.click(function(){const currentVal=parseInt(input.attr("value"));if(!isNaN(currentVal)){if(currentVal<input.attr("max")){input.attr("value",(currentVal+1).toString())}if(currentVal===input.attr("max")){$(this).attr("disabled",true);return}if(parseInt(input.attr("value"))>1){minus.prop("disabled",false)}else{minus.prop("disabled",true)}items.append('<div id="iteminput'+(currentVal+1)+'" class="mb-3 w-50"><label for="item'+(currentVal+1)+'">Model for damage '+(currentVal+1)+':</label><div class="input-group mb-3"><span class="input-group-text" id="namespace'+(currentVal+1)+'">'+namespace+':item/</span><input type="text" class="form-control" id="item'+(currentVal+1)+'" name="item'+(currentVal+1)+'" placeholder="cars/'+randomModel()+'" required></div></div>')}else{input.attr("value","0")}});$.each(itemDamages,function(key){const itemName=capitalize(key);$select.append($("<option></option>").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===""){return}if($cmd.is(":checked")){if(hasSupportText){$(this).text(itemName)}}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+":item/")});item.change(function(){if(this.value!==""){formOptions.show();const max=itemDamages[this.value];itemCount.prop("max",max);plus.prop("disabled",false)}else{formOptions.hide()}});form.on("submit",function(e){e.preventDefault();const supportsCMD=$cmd.is(":checked");const selectedItem=item.val();const currentVal=parseInt(input.attr("value"));const models=[];for(let i=0;i<currentVal;i++){models[i]=$("#item"+(i+1)).val()}const json=buildJSON(supportsCMD,selectedItem,namespace,models);output.html(syntaxHighlight(json));const dataStr="data:text/json;charset=utf-8,"+encodeURIComponent(json);downloadButton.attr("href",dataStr);downloadButton.attr("download",selectedItem+".json");return false});copyButton.click(function(e){e.preventDefault();navigator.clipboard.writeText(output.text())});function capitalize(str){return str.split("_").map(word=>word.charAt(0).toUpperCase()+word.slice(1)).join(" ")}function randomModel(){const months=["red_car","blue_car","green_car","orange_car","blue_bicycle","red_bicycle","green_bicycle","orange_bicycle"];return months[Math.floor(Math.random()*months.length)]}});