Skip to content

Commit

Permalink
Fix implementation of nested switch cases
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Nov 6, 2024
1 parent 2f06dc6 commit 9440e2c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 50 deletions.
2 changes: 1 addition & 1 deletion java/1.21.4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mcschema/java-1.21.4",
"version": "0.0.10",
"version": "0.0.11",
"description": "Schemas for Java Edition 1.21.4",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
87 changes: 39 additions & 48 deletions java/1.21.4/src/schemas/assets/ItemDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,23 @@ export function initItemDefinitionSchemas(schemas: SchemaRegistry, collections:
},
'minecraft:condition': {
property: StringNode({ validator: 'resource', params: { pool: collections.get('model_condition_type') } }),
[Switch]: [{ push: 'property' }],
[Case]: {
'minecraft:has_component': {
component: StringNode({ validator: 'resource', params: { pool: 'data_component_type' } })
},
'minecraft:custom_model_data': {
index: Opt(NumberNode({ integer: true }))
}
},
component: Mod(StringNode({ validator: 'resource', params: { pool: 'data_component_type' } }), {
enabled: path => path.push('property').get() === 'minecraft:has_component'
}),
index: Mod(Opt(NumberNode({ integer: true })), {
enabled: path => path.push('property').get() === 'minecraft:custom_model_data'
}),
on_true: Reference('item_model'),
on_false: Reference('item_model')
},
'minecraft:select': {
property: StringNode({ validator: 'resource', params: { pool: collections.get('select_model_property_type') } }),
[Switch]: [{ push: 'property' }],
[Case]: {
'minecraft:block_state': {
'block_state_property': StringNode()
},
'minecraft:custom_model_data': {
index: Opt(NumberNode({ integer: true }))
}
},
block_state_property: Mod(StringNode(), {
enabled: path => path.push('property').get() === 'minecraft:block_state'
}),
index: Mod(NumberNode({ integer: true }), {
enabled: path => path.push('property').get() === 'minecraft:custom_model_data'
}),
cases: ObjectNode({
when: StringNode(),
model: Reference('item_model')
Expand All @@ -75,37 +69,34 @@ export function initItemDefinitionSchemas(schemas: SchemaRegistry, collections:
},
'minecraft:range_dispatch': {
property: StringNode({ validator: 'resource', params: { pool: collections.get('numeric_model_property_type') } }),
[Switch]: [{ push: 'property' }],
[Case]: {
'minecraft:custom_model_data': {
index: Opt(NumberNode({ integer: true }))
},
'minecraft:damage': {
normalize: Opt(BooleanNode())
},
'minecraft:count': {
normalize: Opt(BooleanNode())
},
'minecraft:time': {
wobble: Opt(BooleanNode()),
natural_only: Opt(BooleanNode())
},
'minecraft:compass': {
target: StringNode({ enum: ['spawn', 'lodestone', 'recovery'] }),
wobble: Opt(BooleanNode())
},
'minecraft:use_duration': {
remaining: Opt(BooleanNode())
},
'minecraft:use_cycle': {
period: Opt(NumberNode())
}
},
scale: Opt(NumberNode()),
entries: ObjectNode({
threshold: NumberNode(),
model: Reference('item_model')
index: Mod(Opt(NumberNode({ integer: true })), {
enabled: path => path.push('property').get() === 'minecraft:custom_model_data'
}),
normalize: Mod(Opt(BooleanNode()), {
enabled: path => path.push('property').get() === 'minecraft:damage' || path.push('property').get() === 'minecraft:count'
}),
natural_only: Mod(Opt(BooleanNode()), {
enabled: path => path.push('property').get() === 'minecraft:time'
}),
target: Mod(StringNode({ enum: ['spawn', 'lodestone', 'recovery'] }), {
enabled: path => path.push('property').get() === 'minecraft:compass'
}),
wobble: Mod(Opt(BooleanNode()), {
enabled: path => path.push('property').get() === 'minecraft:time' || path.push('property').get() === 'minecraft:compass'
}),
remaining: Mod(Opt(BooleanNode()), {
enabled: path => path.push('property').get() === 'minecraft:use_duration'
}),
period: Mod(Opt(NumberNode()), {
enabled: path => path.push('property').get() === 'minecraft:use_cycle'
}),
scale: Opt(NumberNode()),
entries: ListNode(
ObjectNode({
threshold: NumberNode(),
model: Reference('item_model')
}),
),
fallback: Opt(Reference('item_model'))
}
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9440e2c

Please sign in to comment.