diff --git a/src/app/components/previews/LootTable.ts b/src/app/components/previews/LootTable.ts index 51fc9791..ea12b31f 100644 --- a/src/app/components/previews/LootTable.ts +++ b/src/app/components/previews/LootTable.ts @@ -311,7 +311,9 @@ const LootFunctions: Record LootFunction> = { }) }, enchant_with_levels: ({ options, levels }) => (item, ctx) => { - const allowed = getHomogeneousList(options, ctx.getEnchantmentTag) + const allowed = options + ? getHomogeneousList(options, ctx.getEnchantmentTag) + : [...ctx.getEnchantments().keys()] const selected = selectEnchantments(item, computeInt(levels, ctx), allowed, ctx) if (item.is('book')) { item.id = Identifier.create('enchanted_book') @@ -817,9 +819,12 @@ interface Enchant { } function selectEnchantments(item: ResolvedItem, levels: number, options: string[], ctx: LootContext): Enchant[] { - const enchantable = item.get('enchantable', tag => tag.isCompound() ? tag.getNumber('value') : undefined) - if (enchantable === undefined) { - return [] + let enchantable: number | undefined = 1 // Not fully correct before version 1.21.2 + if (checkVersion(ctx.version, '1.21.2')) { + enchantable = item.get('enchantable', tag => tag.isCompound() ? tag.getNumber('value') : undefined) + if (enchantable === undefined) { + return [] + } } let cost = levels + 1 + ctx.random.nextInt(Math.floor(enchantable / 4 + 1)) + ctx.random.nextInt(Math.floor(enchantable / 4 + 1)) const f = (ctx.random.nextFloat() + ctx.random.nextFloat() - 1) * 0.15