Skip to content

Commit 48676c4

Browse files
committed
Get enchants() updated.
Added processing of enchantments for versions from 1.20.5 to the latest The processing of enchantments has been changed for versions from 1.13 to 1.20.4. The "typeOfEnchantLevelValue" function remains "short" for versions 1.8 to latest. Because of this, "string" was removed for versions 1.13 to 1.20.4, and the "typeOfEnchantLevelValue" condition was replaced in get enchants()
1 parent e808e99 commit 48676c4

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function loader (registryOrVersion) {
242242
}
243243

244244
return itemEnch.map((ench) => ({ lvl: ench.lvl, name: registry.enchantments[ench.id]?.name || null }))
245-
} else if (typeOfEnchantLevelValue === 'string' && enchantNbtKey === 'Enchantments') {
245+
} else if (typeOfEnchantLevelValue === 'short' && enchantNbtKey === 'Enchantments') {
246246
let itemEnch = []
247247

248248
if (useStoredEnchantments && this?.nbt?.value?.StoredEnchantments) {
@@ -257,6 +257,21 @@ function loader (registryOrVersion) {
257257
lvl: ench.lvl,
258258
name: typeof ench.id === 'string' ? ench.id.replace('minecraft:', '') : null
259259
}))
260+
} else if (typeOfEnchantLevelValue === 'short' && enchantNbtKey === 'componentEnchantments') {
261+
let itemEnch = []
262+
263+
if (useStoredEnchantments && this?.components?.some(c => c.type === "stored_enchantments")) {
264+
itemEnch = this.components.find(c => c.type === "stored_enchantments").data.enchantments;
265+
} else if (this?.components?.some(c => c.type === "enchantments")) {
266+
itemEnch = this.components.find(c => c.type === "enchantments").data.enchantments;
267+
} else {
268+
itemEnch = []
269+
}
270+
271+
return itemEnch.map((ench) => ({
272+
lvl: ench.level,
273+
name: registry.enchantments[ench.id]?.name || null
274+
}))
260275
}
261276
throw new Error("Don't know how to get the enchants from an item on this mc version")
262277
}

0 commit comments

Comments
 (0)