Fix #642 more validation in loot table preview
Some checks are pending
Deploy to GitHub Pages / build (push) Waiting to run
Deploy to GitHub Pages / deploy (push) Blocked by required conditions

This commit is contained in:
Misode
2024-11-27 23:40:07 +01:00
parent dc72614e85
commit 94a8210e4c
2 changed files with 11 additions and 6 deletions

View File

@@ -271,7 +271,7 @@ function composeFunctions(functions: any[]): LootFunction {
for (const fn of functions) {
if (Array.isArray(fn)) {
composeFunctions(fn)
} else if (composeConditions(fn.conditions ?? [])(ctx)) {
} else if (isObject(fn) && composeConditions(fn.conditions ?? [])(ctx)) {
const type = fn.function?.replace(/^minecraft:/, '');
(LootFunctions[type]?.(fn) ?? (i => i))(item, ctx)
}
@@ -403,6 +403,9 @@ function testCondition(condition: any, ctx: LootContext): boolean {
if (Array.isArray(condition)) {
return composeConditions(condition)(ctx)
}
if (!isObject(condition) || typeof condition.condition !== 'string') {
return false
}
const type = condition.condition?.replace(/^minecraft:/, '')
return (LootConditions[type]?.(condition) ?? (() => true))(ctx)
}