From 1f8be81f5045a35f2a2c8a67e60f7879b6bdf6af Mon Sep 17 00:00:00 2001 From: OffsetMonkey538 Date: Mon, 19 Jan 2026 22:06:31 +0200 Subject: [PATCH] Loot Table Modifier generator (#758) * Loot Table Modifier loot_modifier generator Should support everything currently implemented * Translation keys * Make 'actions' and 'predicates' always a list Seems simpler to understand and a list of one entry behaves exactly the same * Update loot-table-modifier.mcdoc Should match currently latest commit * Fix loot modifier path in datapack being incorrect * Match v2 alpha 1 * Import LootPoolEntry * Add files via upload * Revert "Add files via upload" This reverts commit 7e9c50ee10fd1d58b1c20bbfb20968d8ff9ff0b2. * add condition_add action * Add union member name overrides Co-authored-by: Misode --------- Co-authored-by: Misode --- public/mcdoc/loot-table-modifier.mcdoc | 113 ++++++++++++++++++ .../components/generator/McdocRenderer.tsx | 4 + src/config.json | 7 ++ src/locales/en.json | 2 + 4 files changed, 126 insertions(+) create mode 100644 public/mcdoc/loot-table-modifier.mcdoc diff --git a/public/mcdoc/loot-table-modifier.mcdoc b/public/mcdoc/loot-table-modifier.mcdoc new file mode 100644 index 00000000..9ef841bf --- /dev/null +++ b/public/mcdoc/loot-table-modifier.mcdoc @@ -0,0 +1,113 @@ +use ::java::data::loot::LootPool +use ::java::data::loot::LootPoolEntry +use ::java::data::loot::LootContextType +use ::java::data::loot::LootCondition + +dispatch minecraft:resource[loot-table-modifier:loot_modifier] to struct { + actions: [Action], + predicate: Predicate, +} + +struct Action { + type: #[id] ActionType, + ...loot-table-modifier:loot_modifier_action_types[[type]], +} + +struct Predicate { + type: #[id] PredicateType, + ...loot-table-modifier:loot_modifier_predicate_types[[type]], +} + +enum(string) ActionType { + PoolAdd = "loot-table-modifier:pool_add", + PoolRemove = "loot-table-modifier:pool_remove", + + + EntryAdd = "loot-table-modifier:entry_add", + EntryRemove = "loot-table-modifier:entry_remove", + + EntryItemSet = "loot-table-modifier:entry_item_set", + + + ConditionAdd = "loot-table-modifier:condition_add" +} + +enum(string) PredicateType { + Inverted = "loot-table-modifier:inverted", + AnyOf = "loot-table-modifier:any_of", + AllOf = "loot-table-modifier:all_of", + + + EntryItem = "loot-table-modifier:entry_item", + + + Table = "loot-table-modifier:table", +} + + +/// Utils +struct Pattern { + regexPattern: #[regex_pattern] string, +} + +type LiteralOrPattern = ( + #[misode_member_name="Literal"] T | + #[misode_member_name="Regex pattern"] Pattern | +) + + +/// Actions + +dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:pool_add] to struct { + pools: [LootPool], +} +dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:pool_remove] to struct { + +} + + +dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:entry_add] to struct { + entries: [LootPoolEntry], +} +dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:entry_remove] to struct { + +} + +dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:entry_item_set] to struct { + name: #[id="item"] string, + canReplaceEntry?: boolean, +} + + +dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:condition_add] to struct { + conditions: [LootCondition], + includePools?: boolean, + includeEntries?: boolean, +} + + +/// Predicates + +/// # op +dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:inverted] to struct { + term: Predicate, +} + +dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:any_of] to struct { + terms: [Predicate], +} + +dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:all_of] to struct { + terms: [Predicate], +} + +/// # entry +dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:entry_item] to struct { + name: LiteralOrPattern<#[id="item"] string>, +} + +/// # table +dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:table] to struct { + identifiers?: [LiteralOrPattern<#[id="loot_table"] string>], + types?: [LiteralOrPattern], +} diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index 06e9b187..eeb5035e 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -432,6 +432,10 @@ function UnionHead({ type, optional, node, ctx }: Props a.name === 'misode_member_name')?.value + if (memberNameAttribute?.kind === 'literal' && memberNameAttribute.value.kind === 'string') { + return memberNameAttribute.value.value + } if (type.kind === 'literal') { return formatIdentifier(type.value.value.toString()) } diff --git a/src/config.json b/src/config.json index 6288c9cf..038e91a1 100644 --- a/src/config.json +++ b/src/config.json @@ -948,6 +948,13 @@ "tags": ["partners"], "dependency": "create" }, + { + "id": "loot-table-modifier:loot_modifier", + "url": "loot-table-modifier/loot_modifier", + "path": "loot-table-modifier/loot_modifier", + "tags": ["partners"], + "dependency": "loot-table-modifier" + }, { "id": "thermoo:environment_provider", "url": "thermoo/environment_provider", diff --git a/src/locales/en.json b/src/locales/en.json index 429875d5..f7d7f336 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -92,6 +92,7 @@ "generator.jukebox_song": "Jukebox Song", "generator.lang": "Language", "generator.loot_table": "Loot Table", + "generator.loot-table-modifier:loot_modifier": "Loot Modifier", "generator.model": "Model", "generator.texture_meta": "Texture Metadata", "generator.neoforge:biome_modifier": "Biome Modifier", @@ -229,6 +230,7 @@ "partner.fabric": "Fabric", "partner.immersive_weathering": "Immersive Weathering", "partner.lithostitched": "Lithostitched", + "partner.loot-table-modifier": "Loot Table Modifier", "partner.neoforge": "NeoForge", "partner.obsidian": "Obsidian", "partner.ohthetreesyoullgrow": "Oh The Trees You'll Grow",