mirror of
https://github.com/haselkern/Minecraft-ArmorStand.git
synced 2025-05-18 05:55:35 +00:00
Refactor to use minecraft version as an enum
This commit is contained in:
parent
08daed25dc
commit
c8705323d5
1 changed files with 91 additions and 104 deletions
189
js/main.js
189
js/main.js
|
@ -349,10 +349,24 @@ function setup(){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MC_VERSION = Object.freeze({
|
||||||
|
v1_8: 0,
|
||||||
|
v1_9: 1,
|
||||||
|
v1_11: 2,
|
||||||
|
v1_13: 3,
|
||||||
|
v1_14: 4,
|
||||||
|
v1_16: 5
|
||||||
|
});
|
||||||
|
|
||||||
|
function getMcVersion() {
|
||||||
|
let tag = document.getElementById("mcversion");
|
||||||
|
return tag.options.length - tag.selectedIndex - 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Write stuff from input into variables
|
// Write stuff from input into variables
|
||||||
function handleInput(){
|
function handleInput(){
|
||||||
|
|
||||||
mcVersion = $("#mcversion").val();
|
mcVersion = getMcVersion();
|
||||||
|
|
||||||
invisible = getCheckBoxInput("invisible");
|
invisible = getCheckBoxInput("invisible");
|
||||||
invulnerable = getCheckBoxInput("invulnerable");
|
invulnerable = getCheckBoxInput("invulnerable");
|
||||||
|
@ -467,43 +481,30 @@ function updateUI(){
|
||||||
// Show disabled slots
|
// Show disabled slots
|
||||||
if(useDisabledSlots) {
|
if(useDisabledSlots) {
|
||||||
// Hide offhand disabled slot buttons for versions below 1.13
|
// Hide offhand disabled slot buttons for versions below 1.13
|
||||||
switch (mcVersion) {
|
if (mcVersion > MC_VERSION.v1_13) {
|
||||||
case "1.13":
|
$(".sprite.offhand").show();
|
||||||
case "1.11":
|
$("#dO").show();
|
||||||
case "1.9":
|
$("#rO").show();
|
||||||
case "1.8":
|
$("#pO").show();
|
||||||
$(".sprite.offhand").hide();
|
} else {
|
||||||
$("#dO").hide();
|
$(".sprite.offhand").hide();
|
||||||
$("#rO").hide();
|
$("#dO").hide();
|
||||||
$("#pO").hide();
|
$("#rO").hide();
|
||||||
break;
|
$("#pO").hide();
|
||||||
|
|
||||||
default:
|
|
||||||
$(".sprite.offhand").show();
|
|
||||||
$("#dO").show();
|
|
||||||
$("#rO").show();
|
|
||||||
$("#pO").show();
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#disabledslots").slideDown();
|
$("#disabledslots").slideDown();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
$("#disabledslots").slideUp();
|
$("#disabledslots").slideUp();
|
||||||
|
}
|
||||||
|
|
||||||
//Hide 1.13 features for 1.12 and lower.
|
//Hide 1.13 features for 1.12 and lower.
|
||||||
switch (mcVersion) {
|
if (mcVersion < MC_VERSION.v1_13) {
|
||||||
case "1.11":
|
$("#namecustomization").hide();
|
||||||
case "1.9":
|
$("#centercorrected").hide();
|
||||||
case "1.8":
|
} else {
|
||||||
$("#namecustomization").hide();
|
$("#namecustomization").show();
|
||||||
$("#centercorrected").hide();
|
$("#centercorrected").show();
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$("#namecustomization").show();
|
|
||||||
$("#centercorrected").show();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate code
|
// Generate code
|
||||||
|
@ -511,7 +512,7 @@ function updateUI(){
|
||||||
$("#code").text(generatedCode);
|
$("#code").text(generatedCode);
|
||||||
|
|
||||||
// Show hint, when command is too long
|
// Show hint, when command is too long
|
||||||
const characterLimit = (mcVersion == "1.8" || mcVersion == "1.9") ? 100 : 256;
|
const characterLimit = (mcVersion <= MC_VERSION.v1_9) ? 100 : 256;
|
||||||
if (generatedCode.length > characterLimit)
|
if (generatedCode.length > characterLimit)
|
||||||
$("#codeinfo").slideDown();
|
$("#codeinfo").slideDown();
|
||||||
else
|
else
|
||||||
|
@ -545,15 +546,15 @@ function generateCode(){
|
||||||
|
|
||||||
if (!give) {
|
if (!give) {
|
||||||
// Old entity name
|
// Old entity name
|
||||||
if(mcVersion == "1.8" || mcVersion == "1.9"){
|
if (mcVersion <= MC_VERSION.v1_9) {
|
||||||
code = "/summon ArmorStand ~ ~ ~ {";
|
code = "/summon ArmorStand ~ ~ ~ {";
|
||||||
} else if (mcVersion == "1.11") {
|
} else if (mcVersion == MC_VERSION.v1_11) {
|
||||||
code = "/summon armor_stand ~ ~ ~ {";
|
code = "/summon armor_stand ~ ~ ~ {";
|
||||||
} else {
|
} else {
|
||||||
centercorrected ? code = "/summon armor_stand ~ ~-0.5 ~ {" : code = "/summon armor_stand ~ ~ ~ {"
|
centercorrected ? code = "/summon armor_stand ~ ~-0.5 ~ {" : code = "/summon armor_stand ~ ~ ~ {"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(mcVersion == "1.8" || mcVersion == "1.9" || mcVersion == "1.11"){
|
if(mcVersion <= MC_VERSION.v1_11){
|
||||||
code = "/give @p minecraft:armor_stand 1 0 {EntityTag:{";
|
code = "/give @p minecraft:armor_stand 1 0 {EntityTag:{";
|
||||||
} else {
|
} else {
|
||||||
code = "/give @p armor_stand{EntityTag:{"
|
code = "/give @p armor_stand{EntityTag:{"
|
||||||
|
@ -587,7 +588,7 @@ function generateCode(){
|
||||||
// Equipment
|
// Equipment
|
||||||
if(useEquipment){
|
if(useEquipment){
|
||||||
// Old 1.8 Equipment format
|
// Old 1.8 Equipment format
|
||||||
if(mcVersion == "1.8"){
|
if (mcVersion == MC_VERSION.v1_8) {
|
||||||
var armor = [];
|
var armor = [];
|
||||||
|
|
||||||
armor.push(getHandRightItem());
|
armor.push(getHandRightItem());
|
||||||
|
@ -618,68 +619,58 @@ function generateCode(){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide netherite armour for lower versions
|
// Hide netherite armour for lower versions
|
||||||
switch (mcVersion) {
|
if (mcVersion <= MC_VERSION.v1_11) {
|
||||||
case "1.14":
|
$("#list-helmet").empty().append(helmetList.filter("[value!=netherite_helmet]").filter("[value!=turtle_helmet]"));
|
||||||
case "1.13":
|
$("#list-chestplate").empty().append(chestplateList.filter("[value!=netherite_chestplate]").filter("[value!=turtle_chestplate]"));
|
||||||
$("#list-helmet").empty().append(helmetList.filter("[value!=netherite_helmet]"));
|
$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]").filter("[value!=turtle_leggings]"));
|
||||||
$("#list-chestplate").empty().append(chestplateList.filter("[value!=netherite_chestplate]"));
|
$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]").filter("[value!=turtle_boots]"));
|
||||||
$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]"));
|
|
||||||
$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]"));
|
} else if (mcVersion <= MC_VERSION.v1_14) {
|
||||||
break;
|
$("#list-helmet").empty().append(helmetList.filter("[value!=netherite_helmet]"));
|
||||||
case "1.11":
|
$("#list-chestplate").empty().append(chestplateList.filter("[value!=netherite_chestplate]"));
|
||||||
case "1.9":
|
$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]"));
|
||||||
case "1.8":
|
$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]"));
|
||||||
$("#list-helmet").empty().append(helmetList.filter("[value!=netherite_helmet]").filter("[value!=turtle_helmet]"));
|
|
||||||
$("#list-chestplate").empty().append(chestplateList.filter("[value!=netherite_chestplate]").filter("[value!=turtle_chestplate]"));
|
} else {
|
||||||
$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]").filter("[value!=turtle_leggings]"));
|
$("#list-helmet").empty().append(helmetList);
|
||||||
$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]").filter("[value!=turtle_boots]"));
|
$("#list-chestplate").empty().append(chestplateList);
|
||||||
break;
|
$("#list-leggings").empty().append(leggingsList);
|
||||||
default:
|
$("#list-shoes").empty().append(bootsList);
|
||||||
$("#list-helmet").empty().append(helmetList);
|
|
||||||
$("#list-chestplate").empty().append(chestplateList);
|
|
||||||
$("#list-leggings").empty().append(leggingsList);
|
|
||||||
$("#list-shoes").empty().append(bootsList);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom name
|
// Custom name
|
||||||
if(customName) {
|
if(customName) {
|
||||||
let name = [];
|
let name = [];
|
||||||
switch (mcVersion) {
|
if (mcVersion <= MC_VERSION.v1_11) {
|
||||||
case "1.8":
|
tags.push(`CustomName:"${customName}"`);
|
||||||
case "1.9":
|
|
||||||
case "1.11":
|
|
||||||
tags.push(`CustomName:"${customName}"`);
|
|
||||||
break;
|
|
||||||
case "1.13":
|
|
||||||
name.push(getName());
|
|
||||||
name.push(getNameColor());
|
|
||||||
name.push(getNameBold());
|
|
||||||
name.push(getNameItalic());
|
|
||||||
name.push(getNameObfuscated());
|
|
||||||
name.push(getNameStrikethrough());
|
|
||||||
|
|
||||||
tags.push(`CustomName:"{${name.join("")}}"`);
|
} else if (mcVersion == MC_VERSION.v1_13) {
|
||||||
break;
|
name.push(getName());
|
||||||
default:
|
name.push(getNameColor());
|
||||||
// CustomNames from 1.14+ can now use single quotes to contain json
|
name.push(getNameBold());
|
||||||
// Replace escaped double quotes with single quotes to make it look pretty
|
name.push(getNameItalic());
|
||||||
name.push(getName().replaceAll("\\", ""));
|
name.push(getNameObfuscated());
|
||||||
name.push(getNameColor().replaceAll("\\", ""));
|
name.push(getNameStrikethrough());
|
||||||
name.push(getNameBold().replaceAll("\\", ""));
|
|
||||||
name.push(getNameItalic().replaceAll("\\", ""));
|
tags.push(`CustomName:"{${name.join("")}}"`);
|
||||||
name.push(getNameObfuscated().replaceAll("\\", ""));
|
|
||||||
name.push(getNameStrikethrough().replaceAll("\\", ""));
|
} else {
|
||||||
tags.push(`CustomName:'{${name.join("")}}'`);
|
// CustomNames from 1.14+ can now use single quotes to contain json
|
||||||
break;
|
// Replace escaped double quotes with single quotes to make it look pretty
|
||||||
|
name.push(getName().replaceAll("\\", ""));
|
||||||
|
name.push(getNameColor().replaceAll("\\", ""));
|
||||||
|
name.push(getNameBold().replaceAll("\\", ""));
|
||||||
|
name.push(getNameItalic().replaceAll("\\", ""));
|
||||||
|
name.push(getNameObfuscated().replaceAll("\\", ""));
|
||||||
|
name.push(getNameStrikethrough().replaceAll("\\", ""));
|
||||||
|
tags.push(`CustomName:'{${name.join("")}}'`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(showCustomName)
|
if(showCustomName)
|
||||||
tags.push("CustomNameVisible:1b");
|
tags.push("CustomNameVisible:1b");
|
||||||
|
|
||||||
|
|
||||||
//Scoreboard tags
|
//Scoreboard tags
|
||||||
if (scoreboardTags) {
|
if (scoreboardTags) {
|
||||||
const tagsList = scoreboardTags.split(',');
|
const tagsList = scoreboardTags.split(',');
|
||||||
|
@ -722,7 +713,7 @@ function generateCode(){
|
||||||
code += "}";
|
code += "}";
|
||||||
if (give) {
|
if (give) {
|
||||||
code += "}";
|
code += "}";
|
||||||
if (mcVersion != "1.8" && mcVersion != "1.9" && mcVersion != "1.11") {
|
if (mcVersion > MC_VERSION.v_11) {
|
||||||
code += " 1"
|
code += " 1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -772,7 +763,7 @@ function getHeadItem(){
|
||||||
|
|
||||||
// Use input as player name
|
// Use input as player name
|
||||||
else if(equipCustomHeadMode == "player"){
|
else if(equipCustomHeadMode == "player"){
|
||||||
if (mcVersion == "1.8" || mcVersion == "1.10" || mcVersion == "1.11") {
|
if (mcVersion <= MC_VERSION.v1_11) {
|
||||||
return "{id:\"skull\",Count:1b,Damage:3b,tag:{SkullOwner:\""+equipHelmet+"\"}}";
|
return "{id:\"skull\",Count:1b,Damage:3b,tag:{SkullOwner:\""+equipHelmet+"\"}}";
|
||||||
} else {
|
} else {
|
||||||
return "{id:\"player_head\",Count:1b,tag:{SkullOwner:\""+equipHelmet+"\"}}";
|
return "{id:\"player_head\",Count:1b,tag:{SkullOwner:\""+equipHelmet+"\"}}";
|
||||||
|
@ -784,16 +775,12 @@ function getHeadItem(){
|
||||||
else if(equipCustomHeadMode == "url"){
|
else if(equipCustomHeadMode == "url"){
|
||||||
var base64Value = btoa('{"textures":{"SKIN":{"url":"'+equipHelmet+'"}}}');
|
var base64Value = btoa('{"textures":{"SKIN":{"url":"'+equipHelmet+'"}}}');
|
||||||
|
|
||||||
switch (mcVersion) {
|
if (mcVersion <= MC_VERSION.v1_11) {
|
||||||
case "1.8":
|
return '{id:"skull",Count:1b,Damage:3b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
|
||||||
case "1.9":
|
} else if (mcVersion <= MC_VERSION.v1_14) {
|
||||||
case "1.11":
|
return '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
|
||||||
return '{id:"skull",Count:1b,Damage:3b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
|
} else {
|
||||||
case "1.13":
|
return '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:'+generateIntArray()+',Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
|
||||||
case "1.14":
|
|
||||||
return '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
|
|
||||||
default:
|
|
||||||
return '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:'+generateIntArray()+',Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,7 +806,7 @@ function getHeadItem(){
|
||||||
if(c == ":") bracketsStarted = true;
|
if(c == ":") bracketsStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mcVersion == "1.8" || mcVersion == "1.10" || mcVersion == "1.11") {
|
if (mcVersion <= MC_VERSION.v1_11) {
|
||||||
return '{id:"skull",Count:1b,Damage:3b,tag:{'+parsed+'}}';
|
return '{id:"skull",Count:1b,Damage:3b,tag:{'+parsed+'}}';
|
||||||
} else {
|
} else {
|
||||||
return '{id:"player_head",Count:1b,tag:{'+parsed+'}}';
|
return '{id:"player_head",Count:1b,tag:{'+parsed+'}}';
|
||||||
|
@ -830,7 +817,7 @@ function getHeadItem(){
|
||||||
else{
|
else{
|
||||||
var skullOwnerRaw = equipHelmet.substring(equipHelmet.indexOf("SkullOwner:"));
|
var skullOwnerRaw = equipHelmet.substring(equipHelmet.indexOf("SkullOwner:"));
|
||||||
skullOwnerRaw = skullOwnerRaw.substring(0, skullOwnerRaw.indexOf("}"));
|
skullOwnerRaw = skullOwnerRaw.substring(0, skullOwnerRaw.indexOf("}"));
|
||||||
if (mcVersion == "1.8" || mcVersion == "1.10" || mcVersion == "1.11") {
|
if (mcVersion <= MC_VERSION.v1_11) {
|
||||||
return '{id:"skull",Count:1b,Damage:3b,tag:{'+skullOwnerRaw+'}}';
|
return '{id:"skull",Count:1b,Damage:3b,tag:{'+skullOwnerRaw+'}}';
|
||||||
} else {
|
} else {
|
||||||
return '{id:"player_head",Count:1b,tag:{'+skullOwnerRaw+'}}';
|
return '{id:"player_head",Count:1b,tag:{'+skullOwnerRaw+'}}';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue