mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Fix #832 enchant_with_levels loot preview
This commit is contained in:
@@ -311,7 +311,9 @@ const LootFunctions: Record<string, (params: any) => 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,10 +819,13 @@ 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)
|
||||
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
|
||||
cost = clamp(Math.round(cost + cost * f), 1, Number.MAX_SAFE_INTEGER)
|
||||
|
||||
Reference in New Issue
Block a user