Skip to content

Commit f243be3

Browse files
committed
Fix #832 enchant_with_levels loot preview
1 parent 84028a0 commit f243be3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/app/components/previews/LootTable.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
311311
})
312312
},
313313
enchant_with_levels: ({ options, levels }) => (item, ctx) => {
314-
const allowed = getHomogeneousList(options, ctx.getEnchantmentTag)
314+
const allowed = options
315+
? getHomogeneousList(options, ctx.getEnchantmentTag)
316+
: [...ctx.getEnchantments().keys()]
315317
const selected = selectEnchantments(item, computeInt(levels, ctx), allowed, ctx)
316318
if (item.is('book')) {
317319
item.id = Identifier.create('enchanted_book')
@@ -817,9 +819,12 @@ interface Enchant {
817819
}
818820

819821
function selectEnchantments(item: ResolvedItem, levels: number, options: string[], ctx: LootContext): Enchant[] {
820-
const enchantable = item.get('enchantable', tag => tag.isCompound() ? tag.getNumber('value') : undefined)
821-
if (enchantable === undefined) {
822-
return []
822+
let enchantable: number | undefined = 1 // Not fully correct before version 1.21.2
823+
if (checkVersion(ctx.version, '1.21.2')) {
824+
enchantable = item.get('enchantable', tag => tag.isCompound() ? tag.getNumber('value') : undefined)
825+
if (enchantable === undefined) {
826+
return []
827+
}
823828
}
824829
let cost = levels + 1 + ctx.random.nextInt(Math.floor(enchantable / 4 + 1)) + ctx.random.nextInt(Math.floor(enchantable / 4 + 1))
825830
const f = (ctx.random.nextFloat() + ctx.random.nextFloat() - 1) * 0.15

0 commit comments

Comments
 (0)