Skip to content

Commit 1f8be81

Browse files
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 7e9c50e. * add condition_add action * Add union member name overrides Co-authored-by: Misode <misoloo64@gmail.com> --------- Co-authored-by: Misode <misoloo64@gmail.com>
1 parent e02c26f commit 1f8be81

4 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
use ::java::data::loot::LootPool
2+
use ::java::data::loot::LootPoolEntry
3+
use ::java::data::loot::LootContextType
4+
use ::java::data::loot::LootCondition
5+
6+
dispatch minecraft:resource[loot-table-modifier:loot_modifier] to struct {
7+
actions: [Action],
8+
predicate: Predicate,
9+
}
10+
11+
struct Action {
12+
type: #[id] ActionType,
13+
...loot-table-modifier:loot_modifier_action_types[[type]],
14+
}
15+
16+
struct Predicate {
17+
type: #[id] PredicateType,
18+
...loot-table-modifier:loot_modifier_predicate_types[[type]],
19+
}
20+
21+
enum(string) ActionType {
22+
PoolAdd = "loot-table-modifier:pool_add",
23+
PoolRemove = "loot-table-modifier:pool_remove",
24+
25+
26+
EntryAdd = "loot-table-modifier:entry_add",
27+
EntryRemove = "loot-table-modifier:entry_remove",
28+
29+
EntryItemSet = "loot-table-modifier:entry_item_set",
30+
31+
32+
ConditionAdd = "loot-table-modifier:condition_add"
33+
}
34+
35+
enum(string) PredicateType {
36+
Inverted = "loot-table-modifier:inverted",
37+
AnyOf = "loot-table-modifier:any_of",
38+
AllOf = "loot-table-modifier:all_of",
39+
40+
41+
EntryItem = "loot-table-modifier:entry_item",
42+
43+
44+
Table = "loot-table-modifier:table",
45+
}
46+
47+
48+
/// Utils
49+
struct Pattern {
50+
regexPattern: #[regex_pattern] string,
51+
}
52+
53+
type LiteralOrPattern<T> = (
54+
#[misode_member_name="Literal"] T |
55+
#[misode_member_name="Regex pattern"] Pattern |
56+
)
57+
58+
59+
/// Actions
60+
61+
dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:pool_add] to struct {
62+
pools: [LootPool],
63+
}
64+
dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:pool_remove] to struct {
65+
66+
}
67+
68+
69+
dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:entry_add] to struct {
70+
entries: [LootPoolEntry],
71+
}
72+
dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:entry_remove] to struct {
73+
74+
}
75+
76+
dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:entry_item_set] to struct {
77+
name: #[id="item"] string,
78+
canReplaceEntry?: boolean,
79+
}
80+
81+
82+
dispatch loot-table-modifier:loot_modifier_action_types[loot-table-modifier:condition_add] to struct {
83+
conditions: [LootCondition],
84+
includePools?: boolean,
85+
includeEntries?: boolean,
86+
}
87+
88+
89+
/// Predicates
90+
91+
/// # op
92+
dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:inverted] to struct {
93+
term: Predicate,
94+
}
95+
96+
dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:any_of] to struct {
97+
terms: [Predicate],
98+
}
99+
100+
dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:all_of] to struct {
101+
terms: [Predicate],
102+
}
103+
104+
/// # entry
105+
dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:entry_item] to struct {
106+
name: LiteralOrPattern<#[id="item"] string>,
107+
}
108+
109+
/// # table
110+
dispatch loot-table-modifier:loot_modifier_predicate_types[loot-table-modifier:table] to struct {
111+
identifiers?: [LiteralOrPattern<#[id="loot_table"] string>],
112+
types?: [LiteralOrPattern<LootContextType>],
113+
}

src/app/components/generator/McdocRenderer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ function UnionHead({ type, optional, node, ctx }: Props<UnionType<SimplifiedMcdo
432432
}
433433

434434
function formatUnionMember(type: SimplifiedMcdocTypeNoUnion, others: SimplifiedMcdocTypeNoUnion[]): string {
435+
const memberNameAttribute = type.attributes?.find(a => a.name === 'misode_member_name')?.value
436+
if (memberNameAttribute?.kind === 'literal' && memberNameAttribute.value.kind === 'string') {
437+
return memberNameAttribute.value.value
438+
}
435439
if (type.kind === 'literal') {
436440
return formatIdentifier(type.value.value.toString())
437441
}

src/config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,13 @@
948948
"tags": ["partners"],
949949
"dependency": "create"
950950
},
951+
{
952+
"id": "loot-table-modifier:loot_modifier",
953+
"url": "loot-table-modifier/loot_modifier",
954+
"path": "loot-table-modifier/loot_modifier",
955+
"tags": ["partners"],
956+
"dependency": "loot-table-modifier"
957+
},
951958
{
952959
"id": "thermoo:environment_provider",
953960
"url": "thermoo/environment_provider",

src/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"generator.jukebox_song": "Jukebox Song",
9393
"generator.lang": "Language",
9494
"generator.loot_table": "Loot Table",
95+
"generator.loot-table-modifier:loot_modifier": "Loot Modifier",
9596
"generator.model": "Model",
9697
"generator.texture_meta": "Texture Metadata",
9798
"generator.neoforge:biome_modifier": "Biome Modifier",
@@ -229,6 +230,7 @@
229230
"partner.fabric": "Fabric",
230231
"partner.immersive_weathering": "Immersive Weathering",
231232
"partner.lithostitched": "Lithostitched",
233+
"partner.loot-table-modifier": "Loot Table Modifier",
232234
"partner.neoforge": "NeoForge",
233235
"partner.obsidian": "Obsidian",
234236
"partner.ohthetreesyoullgrow": "Oh The Trees You'll Grow",

0 commit comments

Comments
 (0)