Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 9440e2c

Browse files
committed
Fix implementation of nested switch cases
1 parent 2f06dc6 commit 9440e2c

File tree

3 files changed

+41
-50
lines changed

3 files changed

+41
-50
lines changed

java/1.21.4/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mcschema/java-1.21.4",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"description": "Schemas for Java Edition 1.21.4",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

java/1.21.4/src/schemas/assets/ItemDefinition.ts

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,23 @@ export function initItemDefinitionSchemas(schemas: SchemaRegistry, collections:
4444
},
4545
'minecraft:condition': {
4646
property: StringNode({ validator: 'resource', params: { pool: collections.get('model_condition_type') } }),
47-
[Switch]: [{ push: 'property' }],
48-
[Case]: {
49-
'minecraft:has_component': {
50-
component: StringNode({ validator: 'resource', params: { pool: 'data_component_type' } })
51-
},
52-
'minecraft:custom_model_data': {
53-
index: Opt(NumberNode({ integer: true }))
54-
}
55-
},
47+
component: Mod(StringNode({ validator: 'resource', params: { pool: 'data_component_type' } }), {
48+
enabled: path => path.push('property').get() === 'minecraft:has_component'
49+
}),
50+
index: Mod(Opt(NumberNode({ integer: true })), {
51+
enabled: path => path.push('property').get() === 'minecraft:custom_model_data'
52+
}),
5653
on_true: Reference('item_model'),
5754
on_false: Reference('item_model')
5855
},
5956
'minecraft:select': {
6057
property: StringNode({ validator: 'resource', params: { pool: collections.get('select_model_property_type') } }),
61-
[Switch]: [{ push: 'property' }],
62-
[Case]: {
63-
'minecraft:block_state': {
64-
'block_state_property': StringNode()
65-
},
66-
'minecraft:custom_model_data': {
67-
index: Opt(NumberNode({ integer: true }))
68-
}
69-
},
58+
block_state_property: Mod(StringNode(), {
59+
enabled: path => path.push('property').get() === 'minecraft:block_state'
60+
}),
61+
index: Mod(NumberNode({ integer: true }), {
62+
enabled: path => path.push('property').get() === 'minecraft:custom_model_data'
63+
}),
7064
cases: ObjectNode({
7165
when: StringNode(),
7266
model: Reference('item_model')
@@ -75,37 +69,34 @@ export function initItemDefinitionSchemas(schemas: SchemaRegistry, collections:
7569
},
7670
'minecraft:range_dispatch': {
7771
property: StringNode({ validator: 'resource', params: { pool: collections.get('numeric_model_property_type') } }),
78-
[Switch]: [{ push: 'property' }],
79-
[Case]: {
80-
'minecraft:custom_model_data': {
81-
index: Opt(NumberNode({ integer: true }))
82-
},
83-
'minecraft:damage': {
84-
normalize: Opt(BooleanNode())
85-
},
86-
'minecraft:count': {
87-
normalize: Opt(BooleanNode())
88-
},
89-
'minecraft:time': {
90-
wobble: Opt(BooleanNode()),
91-
natural_only: Opt(BooleanNode())
92-
},
93-
'minecraft:compass': {
94-
target: StringNode({ enum: ['spawn', 'lodestone', 'recovery'] }),
95-
wobble: Opt(BooleanNode())
96-
},
97-
'minecraft:use_duration': {
98-
remaining: Opt(BooleanNode())
99-
},
100-
'minecraft:use_cycle': {
101-
period: Opt(NumberNode())
102-
}
103-
},
104-
scale: Opt(NumberNode()),
105-
entries: ObjectNode({
106-
threshold: NumberNode(),
107-
model: Reference('item_model')
72+
index: Mod(Opt(NumberNode({ integer: true })), {
73+
enabled: path => path.push('property').get() === 'minecraft:custom_model_data'
74+
}),
75+
normalize: Mod(Opt(BooleanNode()), {
76+
enabled: path => path.push('property').get() === 'minecraft:damage' || path.push('property').get() === 'minecraft:count'
10877
}),
78+
natural_only: Mod(Opt(BooleanNode()), {
79+
enabled: path => path.push('property').get() === 'minecraft:time'
80+
}),
81+
target: Mod(StringNode({ enum: ['spawn', 'lodestone', 'recovery'] }), {
82+
enabled: path => path.push('property').get() === 'minecraft:compass'
83+
}),
84+
wobble: Mod(Opt(BooleanNode()), {
85+
enabled: path => path.push('property').get() === 'minecraft:time' || path.push('property').get() === 'minecraft:compass'
86+
}),
87+
remaining: Mod(Opt(BooleanNode()), {
88+
enabled: path => path.push('property').get() === 'minecraft:use_duration'
89+
}),
90+
period: Mod(Opt(NumberNode()), {
91+
enabled: path => path.push('property').get() === 'minecraft:use_cycle'
92+
}),
93+
scale: Opt(NumberNode()),
94+
entries: ListNode(
95+
ObjectNode({
96+
threshold: NumberNode(),
97+
model: Reference('item_model')
98+
}),
99+
),
109100
fallback: Opt(Reference('item_model'))
110101
}
111102
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)