mirror of
				https://github.com/haselkern/Minecraft-ArmorStand.git
				synced 2025-11-04 05:14:06 +00:00 
			
		
		
		
	Refactor to use minecraft version as an enum
This commit is contained in:
		
							parent
							
								
									08daed25dc
								
							
						
					
					
						commit
						46864f706c
					
				
					 1 changed files with 91 additions and 104 deletions
				
			
		
							
								
								
									
										117
									
								
								js/main.js
									
										
									
									
									
								
							
							
						
						
									
										117
									
								
								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":
 | 
					 | 
				
			||||||
			case "1.11":
 | 
					 | 
				
			||||||
			case "1.9":
 | 
					 | 
				
			||||||
			case "1.8":
 | 
					 | 
				
			||||||
				$(".sprite.offhand").hide();
 | 
					 | 
				
			||||||
				$("#dO").hide();
 | 
					 | 
				
			||||||
				$("#rO").hide();
 | 
					 | 
				
			||||||
				$("#pO").hide();
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			default:
 | 
					 | 
				
			||||||
			$(".sprite.offhand").show();
 | 
								$(".sprite.offhand").show();
 | 
				
			||||||
			$("#dO").show();
 | 
								$("#dO").show();
 | 
				
			||||||
			$("#rO").show();
 | 
								$("#rO").show();
 | 
				
			||||||
			$("#pO").show();
 | 
								$("#pO").show();
 | 
				
			||||||
				break;
 | 
							} else {
 | 
				
			||||||
 | 
								$(".sprite.offhand").hide();
 | 
				
			||||||
 | 
								$("#dO").hide();
 | 
				
			||||||
 | 
								$("#rO").hide();
 | 
				
			||||||
 | 
								$("#pO").hide();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$("#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":
 | 
					 | 
				
			||||||
		case "1.9":
 | 
					 | 
				
			||||||
		case "1.8":
 | 
					 | 
				
			||||||
		$("#namecustomization").hide();
 | 
							$("#namecustomization").hide();
 | 
				
			||||||
		$("#centercorrected").hide();
 | 
							$("#centercorrected").hide();
 | 
				
			||||||
			break;
 | 
						} else {
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
		$("#namecustomization").show();
 | 
							$("#namecustomization").show();
 | 
				
			||||||
		$("#centercorrected").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,41 +619,33 @@ 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":
 | 
					 | 
				
			||||||
			case "1.13":
 | 
					 | 
				
			||||||
				$("#list-helmet").empty().append(helmetList.filter("[value!=netherite_helmet]"));
 | 
					 | 
				
			||||||
				$("#list-chestplate").empty().append(chestplateList.filter("[value!=netherite_chestplate]"));
 | 
					 | 
				
			||||||
				$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]"));
 | 
					 | 
				
			||||||
				$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]"));
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			case "1.11":
 | 
					 | 
				
			||||||
			case "1.9":
 | 
					 | 
				
			||||||
			case "1.8":
 | 
					 | 
				
			||||||
			$("#list-helmet").empty().append(helmetList.filter("[value!=netherite_helmet]").filter("[value!=turtle_helmet]"));
 | 
								$("#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]"));
 | 
								$("#list-chestplate").empty().append(chestplateList.filter("[value!=netherite_chestplate]").filter("[value!=turtle_chestplate]"));
 | 
				
			||||||
			$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]").filter("[value!=turtle_leggings]"));
 | 
								$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]").filter("[value!=turtle_leggings]"));
 | 
				
			||||||
			$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]").filter("[value!=turtle_boots]"));
 | 
								$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]").filter("[value!=turtle_boots]"));
 | 
				
			||||||
				break;
 | 
					
 | 
				
			||||||
			default:
 | 
							} else if (mcVersion <= MC_VERSION.v1_14) {
 | 
				
			||||||
 | 
								$("#list-helmet").empty().append(helmetList.filter("[value!=netherite_helmet]"));
 | 
				
			||||||
 | 
								$("#list-chestplate").empty().append(chestplateList.filter("[value!=netherite_chestplate]"));
 | 
				
			||||||
 | 
								$("#list-leggings").empty().append(leggingsList.filter("[value!=netherite_leggings]"));
 | 
				
			||||||
 | 
								$("#list-shoes").empty().append(bootsList.filter("[value!=netherite_boots]"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			$("#list-helmet").empty().append(helmetList);
 | 
								$("#list-helmet").empty().append(helmetList);
 | 
				
			||||||
			$("#list-chestplate").empty().append(chestplateList);
 | 
								$("#list-chestplate").empty().append(chestplateList);
 | 
				
			||||||
			$("#list-leggings").empty().append(leggingsList);
 | 
								$("#list-leggings").empty().append(leggingsList);
 | 
				
			||||||
			$("#list-shoes").empty().append(bootsList);
 | 
								$("#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":
 | 
					 | 
				
			||||||
			case "1.9":
 | 
					 | 
				
			||||||
			case "1.11":
 | 
					 | 
				
			||||||
			tags.push(`CustomName:"${customName}"`);
 | 
								tags.push(`CustomName:"${customName}"`);
 | 
				
			||||||
				break;
 | 
					
 | 
				
			||||||
			case "1.13":
 | 
							} else if (mcVersion == MC_VERSION.v1_13) {
 | 
				
			||||||
			name.push(getName());
 | 
								name.push(getName());
 | 
				
			||||||
			name.push(getNameColor());
 | 
								name.push(getNameColor());
 | 
				
			||||||
			name.push(getNameBold());
 | 
								name.push(getNameBold());
 | 
				
			||||||
| 
						 | 
					@ -661,8 +654,8 @@ function generateCode(){
 | 
				
			||||||
			name.push(getNameStrikethrough());
 | 
								name.push(getNameStrikethrough());
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			tags.push(`CustomName:"{${name.join("")}}"`);
 | 
								tags.push(`CustomName:"{${name.join("")}}"`);
 | 
				
			||||||
				break;
 | 
					
 | 
				
			||||||
			default:
 | 
							} else {
 | 
				
			||||||
			// CustomNames from 1.14+ can now use single quotes to contain json
 | 
								// CustomNames from 1.14+ can now use single quotes to contain json
 | 
				
			||||||
			// Replace escaped double quotes with single quotes to make it look pretty				
 | 
								// Replace escaped double quotes with single quotes to make it look pretty				
 | 
				
			||||||
			name.push(getName().replaceAll("\\", ""));
 | 
								name.push(getName().replaceAll("\\", ""));
 | 
				
			||||||
| 
						 | 
					@ -672,14 +665,12 @@ function generateCode(){
 | 
				
			||||||
			name.push(getNameObfuscated().replaceAll("\\", ""));
 | 
								name.push(getNameObfuscated().replaceAll("\\", ""));
 | 
				
			||||||
			name.push(getNameStrikethrough().replaceAll("\\", ""));
 | 
								name.push(getNameStrikethrough().replaceAll("\\", ""));
 | 
				
			||||||
			tags.push(`CustomName:'{${name.join("")}}'`);
 | 
								tags.push(`CustomName:'{${name.join("")}}'`);
 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	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,15 +775,11 @@ 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":
 | 
					 | 
				
			||||||
			case "1.9":
 | 
					 | 
				
			||||||
			case "1.11":
 | 
					 | 
				
			||||||
			return '{id:"skull",Count:1b,Damage:3b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
 | 
								return '{id:"skull",Count:1b,Damage:3b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
 | 
				
			||||||
			case "1.13":
 | 
							} else if (mcVersion <= MC_VERSION.v1_14) {
 | 
				
			||||||
			case "1.14":
 | 
					 | 
				
			||||||
			return '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
 | 
								return '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:"'+generateUUID()+'",Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
 | 
				
			||||||
			default:
 | 
							} else {
 | 
				
			||||||
			return '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:'+generateIntArray()+',Properties:{textures:[{Value:"'+base64Value+'"}]}}}}';
 | 
								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