1
0
Fork 0
mirror of https://github.com/haselkern/Minecraft-ArmorStand.git synced 2025-12-03 06:24:07 +00:00

Use the new equipments field for 1.21.5+

This commit is contained in:
Lenny Lord 2025-11-20 01:08:09 +05:30 committed by thelennylord
parent 6413875cd0
commit d51acd0135
2 changed files with 36 additions and 3 deletions

View file

@ -32,7 +32,8 @@
<div class="padding underline"> <div class="padding underline">
<select id="mcversion"> <select id="mcversion">
<option value="1.21">Minecraft 1.21 and above</option> <option value="1.21.5">Minecraft 1.21.5 and above</option>
<option value="1.21">Minecraft 1.21 to 1.21.4</option>
<option value="1.20.5">Minecraft 1.20.5 &amp; 1.20.6</option> <option value="1.20.5">Minecraft 1.20.5 &amp; 1.20.6</option>
<option value="1.16">Minecraft 1.16 to 1.20.4</option> <option value="1.16">Minecraft 1.16 to 1.20.4</option>
<option value="1.14">Minecraft 1.14 &amp; 1.15</option> <option value="1.14">Minecraft 1.14 &amp; 1.15</option>

View file

@ -357,7 +357,8 @@ const MC_VERSION = Object.freeze({
v1_14: 4, v1_14: 4,
v1_16: 5, v1_16: 5,
v1_20_5: 6, v1_20_5: 6,
v1_21: 7 v1_21: 7,
v1_21_5: 8,
}); });
function getMcVersion() { function getMcVersion() {
@ -572,6 +573,18 @@ function updateUI(){
mSkull.visible = equipHelmet != ""; mSkull.visible = equipHelmet != "";
} }
function pruneEmpty(obj) {
for (const key in obj) {
const value = obj[key];
if (Object.keys(value).length === 0) {
delete obj[key];
}
}
return obj;
}
function generateCode() { function generateCode() {
const tags = { const tags = {
Invisible: invisible || null, Invisible: invisible || null,
@ -599,7 +612,7 @@ function generateCode() {
// Equipment: [ RightHand, Boots, Leggings, Chestplate, Helmet ] // Equipment: [ RightHand, Boots, Leggings, Chestplate, Helmet ]
const rightHandItem = generateHandItems()[0]; const rightHandItem = generateHandItems()[0];
tags.Equipment = [rightHandItem, ...generateArmorItems()]; tags.Equipment = [rightHandItem, ...generateArmorItems()];
} else { } else if (mcVersion >= MC_VERSION.v1_9 && mcVersion < MC_VERSION.v1_21_5) {
// New 1.9+ Equipment format // New 1.9+ Equipment format
if (equipShoes != "" || equipLeggings != "" || equipChestplate != "" || equipHelmet != "") { if (equipShoes != "" || equipLeggings != "" || equipChestplate != "" || equipHelmet != "") {
tags.ArmorItems = generateArmorItems(); tags.ArmorItems = generateArmorItems();
@ -608,6 +621,25 @@ function generateCode() {
if (equipHandRight != "" || equipHandLeft != "") { if (equipHandRight != "" || equipHandLeft != "") {
tags.HandItems = generateHandItems(); tags.HandItems = generateHandItems();
} }
} else {
// Since 1.21.5, The ArmorItems and HandItems fields have been merged into an equipment field.
// Reference: https://minecraft.wiki/w/Java_Edition_1.21.5
let [feetArmor, legsArmor, chestArmor, headArmor] = generateArmorItems();
let [mainHand, offHand] = generateHandItems();
let equipments = pruneEmpty({
mainhand: mainHand,
offhand: offHand,
head: headArmor,
chest: chestArmor,
legs: legsArmor,
feet: feetArmor,
});
if (Object.keys(equipments).length > 0) {
tags.equipment = equipments;
}
} }
} }