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) => {
|
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)
|
const selected = selectEnchantments(item, computeInt(levels, ctx), allowed, ctx)
|
||||||
if (item.is('book')) {
|
if (item.is('book')) {
|
||||||
item.id = Identifier.create('enchanted_book')
|
item.id = Identifier.create('enchanted_book')
|
||||||
@@ -817,9 +819,12 @@ interface Enchant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function selectEnchantments(item: ResolvedItem, levels: number, options: string[], ctx: LootContext): 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 (enchantable === undefined) {
|
if (checkVersion(ctx.version, '1.21.2')) {
|
||||||
return []
|
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))
|
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
|
const f = (ctx.random.nextFloat() + ctx.random.nextFloat() - 1) * 0.15
|
||||||
|
|||||||
Reference in New Issue
Block a user