Fix #596 support item tag and loot table references in loot preview

This commit is contained in:
Misode
2024-09-11 14:39:53 +02:00
parent 95f7ca7738
commit fff1b1603a
3 changed files with 47 additions and 33 deletions

View File

@@ -25,6 +25,9 @@ interface LootOptions {
daytime: number,
weather: string,
stackMixer: StackMixer,
getItemTag(id: string): string[],
getLootTable(id: string): any,
getPredicate(id: string): any,
}
interface LootContext extends LootOptions {
@@ -32,9 +35,6 @@ interface LootContext extends LootOptions {
luck: number
weather: string,
dayTime: number,
getItemTag(id: string): string[],
getLootTable(id: string): any,
getPredicate(id: string): any,
}
export function generateLootTable(lootTable: any, options: LootOptions) {
@@ -130,9 +130,6 @@ function createLootContext(options: LootOptions): LootContext {
luck: options.luck,
weather: options.weather,
dayTime: options.daytime,
getItemTag: () => [],
getLootTable: () => ({ pools: [] }),
getPredicate: () => [],
}
}
@@ -203,7 +200,7 @@ function expandEntry(entry: any, ctx: LootContext, consumer: (entry: any) => voi
return true
case 'tag':
if (entry.expand) {
ctx.getItemTag(entry.tag ?? '').forEach(tagEntry => {
ctx.getItemTag(entry.name ?? '').forEach(tagEntry => {
consumer({ type: 'item', name: tagEntry })
})
} else {
@@ -241,7 +238,10 @@ function createItem(entry: any, consumer: ItemConsumer, ctx: LootContext) {
})
break
case 'loot_table':
generateTable(ctx.getLootTable(entry.name), entryConsumer, ctx)
const lootTable = ctx.getLootTable(entry.name)
if (lootTable !== undefined) {
generateTable(lootTable, entryConsumer, ctx)
}
break
case 'dynamic':
// not relevant for this simulation
@@ -659,7 +659,6 @@ const AlwaysHasGlint = new Set([
])
export function itemHasGlint(item: ItemStack) {
console.log(item)
if (AlwaysHasGlint.has(item.id.toString())) {
return true
}