Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24w10a #52

Merged
merged 10 commits into from
Mar 6, 2024
42 changes: 28 additions & 14 deletions java/1.20.5/src/Collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,39 @@ export function initCollections(collections: CollectionRegistry) {
'key.use'
])

collections.register('slot', [
collections.register('equipment_slot', [
'mainhand',
'offhand',
'head',
'chest',
'legs',
'feet'
'feet',
'body',
])

collections.register('equipment_slot_group', [
'any',
'mainhand',
'offhand',
'hand',
'head',
'chest',
'legs',
'feet',
'armor',
])

collections.register('slot_range', [
'container.*',
'hotbar.*',
'inventory.*',
'enderchest.*',
'villager.*',
'horse.*',
'weapon.*',
'armor.*',
'player.cursor',
'player.crafting.*',
])

collections.register('gamemode', [
Expand Down Expand Up @@ -536,18 +562,6 @@ export function initCollections(collections: CollectionRegistry) {
'jp',
])

collections.register('equipment_slot_group', [
'any',
'mainhand',
'offhand',
'hand',
'head',
'chest',
'legs',
'feet',
'armor',
])

collections.register('attribute_modifier_operation', [
'add_value',
'add_multiplied_base',
Expand Down
21 changes: 21 additions & 0 deletions java/1.20.5/src/schemas/BannerPattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
StringNode as RawStringNode,
Mod,
ObjectNode,
SchemaRegistry,
CollectionRegistry
} from '@mcschema/core'

export function initBannerPatternSchemas(schemas: SchemaRegistry, collections: CollectionRegistry) {
const StringNode = RawStringNode.bind(undefined, collections)

schemas.register('banner_pattern', Mod(ObjectNode({
asset_id: StringNode(),
translation_key: StringNode(),
}, { context: 'banner_pattern' }), {
default: () => ({
asset_id: 'minecraft:globe',
translation_key: 'block.minecraft.banner.globe'
})
}))
}
181 changes: 125 additions & 56 deletions java/1.20.5/src/schemas/Components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,30 @@ export function initComponentsSchemas(schemas: SchemaRegistry, collections: Coll
const Reference = RawReference.bind(undefined, schemas)
const StringNode = RawStringNode.bind(undefined, collections)

schemas.register('enchantments_component', ObjectNode({
levels: MapNode(
StringNode({ validator: 'resource', params: { pool: 'enchantment' } }),
NumberNode({ integer: true, min: 0, max: 255 }),
),
show_in_tooltip: Opt(BooleanNode()),
}, { context: 'enchantments' }))
schemas.register('enchantments_component', ChoiceNode([
{
type: 'simple',
match: () => true,
node: MapNode(
StringNode({ validator: 'resource', params: { pool: 'enchantment' } }),
NumberNode({ integer: true, min: 0, max: 255 }),
),
change: v => v.levels ?? {}
},
{
type: 'full',
match: v => typeof v === 'object' && typeof v?.levels === 'object',
node: ObjectNode({
levels: MapNode(
StringNode({ validator: 'resource', params: { pool: 'enchantment' } }),
NumberNode({ integer: true, min: 0, max: 255 }),
),
show_in_tooltip: Opt(BooleanNode()),
}),
change: v => ({ levels: v ?? {} }),
priority: 1,
}
], { context: 'enchantments' }))

schemas.register('adventure_mode_predicate', ChoiceNode([
{
Expand All @@ -51,6 +68,15 @@ export function initComponentsSchemas(schemas: SchemaRegistry, collections: Coll
},
], { context: 'adventure_mode_predicate' }))

schemas.register('attribute_modifiers_entry', ObjectNode({
type: StringNode({ validator: 'resource', params: { pool: 'attribute' } }),
uuid: StringNode({ validator: 'uuid' }),
name: StringNode(),
amount: NumberNode(),
operation: StringNode({ enum: 'attribute_modifier_operation' }),
slot: Opt(StringNode({ enum: 'equipment_slot_group' })),
}, { context: 'attribute_modifier' }))

schemas.register('map_decoration', ObjectNode({
type: StringNode({ enum: 'map_decoration' }),
x: NumberNode(),
Expand Down Expand Up @@ -142,6 +168,16 @@ export function initComponentsSchemas(schemas: SchemaRegistry, collections: Coll
has_twinkle: Opt(BooleanNode()),
}, { context: 'firework_explosion' }))

schemas.register('player_name', Mod(SizeLimitedString({ maxLength: 16 }), node => ({
validate: (path, value, errors, options) => {
value = node.validate(path, value, errors, options)
if (typeof value === 'string' && !value.split('').map(c => c.charCodeAt(0)).some(c => c <= 32 || c >= 127)) {
errors.add(path, 'error.invalid_player_name')
}
return value
}
})))

const Components: Record<string, INode> = {
'minecraft:damage': NumberNode({ integer: true, min: 0 }),
'minecraft:unbreakable': ObjectNode({
Expand All @@ -150,34 +186,51 @@ export function initComponentsSchemas(schemas: SchemaRegistry, collections: Coll
'minecraft:custom_name': StringNode(), // text component
'minecraft:lore': ListNode(
StringNode(), // text component
{ context: 'data_component.lore', maxLength: 64 },
{ context: 'data_component.lore', maxLength: 256 },
),
'minecraft:enchantments': Reference('enchantments_component'),
'minecraft:can_place_on': Reference('adventure_mode_predicate'),
'minecraft:can_break': Reference('adventure_mode_predicate'),
'minecraft:attribute_modifiers': ObjectNode({
modifiers: ListNode(
ObjectNode({
type: StringNode({ validator: 'resource', params: { pool: 'attribute' } }),
uuid: StringNode({ validator: 'uuid' }),
name: StringNode(),
amount: NumberNode(),
operation: StringNode({ enum: 'attribute_modifier_operation' }),
slot: Opt(StringNode({ enum: 'equipment_slot_group' })),
}, { context: 'attribute_modifier' }),
),
show_in_tooltip: Opt(BooleanNode()),
}, { context: 'data_component.attribute_modifiers' }),
'minecraft:attribute_modifiers': ChoiceNode([
{
type: 'list',
node: ListNode(
Reference('attribute_modifiers_entry'),
),
change: v => v.modifiers
},
{
type: 'object',
node: ObjectNode({
modifiers: ListNode(
Reference('attribute_modifiers_entry'),
),
show_in_tooltip: Opt(BooleanNode()),
}),
change: v => ({ modifiers: v })
}
], { context: 'data_component.attribute_modifiers' }),
'minecraft:custom_model_data': NumberNode({ integer: true }),
'minecraft:hide_additional_tooltip': ObjectNode({}),
'minecraft:repair_cost': NumberNode({ integer: true, min: 0 }),
'minecraft:enchantment_glint_override': BooleanNode(),
'minecraft:intangible_projectile': ObjectNode({}),
'minecraft:stored_enchantments': Reference('enchantments_component'),
'minecraft:dyed_color': ObjectNode({
rgb: NumberNode({ color: true }),
show_in_tooltip: Opt(BooleanNode()),
}, { context: 'data_component.dyed_color' }),
'minecraft:dyed_color': ChoiceNode([
{
type: 'number',
node: NumberNode({ color: true }),
change: v => v.rgb
},
{
type: 'object',
node: ObjectNode({
rgb: NumberNode({ color: true }),
show_in_tooltip: Opt(BooleanNode()),
}),
change: v => ({ rgb: v })
}
], { context: 'data_component.dyed_color' }),
'minecraft:map_color': NumberNode({ color: true }),
'minecraft:map_id': NumberNode({ integer: true }),
'minecraft:map_decorations': MapNode(
Expand All @@ -193,13 +246,24 @@ export function initComponentsSchemas(schemas: SchemaRegistry, collections: Coll
Reference('item_stack'),
{ context: 'data_component.bundle_contents', maxLength: 64 },
),
'minecraft:potion_contents': ObjectNode({
potion: Opt(StringNode({ validator: 'resource', params: { pool: 'potion' } })),
custom_color: Opt(NumberNode({ color: true })),
custom_effects: Opt(ListNode(
Reference('mob_effect_instance'),
)),
}, { context: 'data_component.potion_contents' }),
'minecraft:potion_contents': ChoiceNode([
{
type: 'string',
node: StringNode({ validator: 'resource', params: { pool: 'potion' } }),
change: v => v.potion
},
{
type: 'object',
node: ObjectNode({
potion: Opt(StringNode({ validator: 'resource', params: { pool: 'potion' } })),
custom_color: Opt(NumberNode({ color: true })),
custom_effects: Opt(ListNode(
Reference('mob_effect_instance'),
)),
}),
change: v => ({ potion: v})
}
], { context: 'data_component.potion_contents' }),
'minecraft:suspicious_stew_effects': ListNode(
Reference('suspicious_stew_effect_instance'),
{ context: 'data_component.suspicious_stew_effects' },
Expand Down Expand Up @@ -264,38 +328,43 @@ export function initComponentsSchemas(schemas: SchemaRegistry, collections: Coll
StringNode({ validator: 'resource', params: { pool: '$recipe' } }),
{ context: 'data_component.recipes' },
),
'minecraft:lodestone_target': ObjectNode({
dimension: StringNode({ validator: 'resource', params: { pool: '$dimension' } }),
pos: Reference('block_pos'),
'minecraft:lodestone_tracker': ObjectNode({
tracker: Opt(ObjectNode({
dimension: StringNode({ validator: 'resource', params: { pool: '$dimension' } }),
pos: Reference('block_pos'),
})),
tracked: Opt(BooleanNode()),
}, { context: 'data_component.lodestone_target' }),
}, { context: 'data_component.lodestone_tracker' }),
'minecraft:firework_explosion': Reference('firework_explosion'),
'minecraft:fireworks': ObjectNode({
flight_duration: Opt(NumberNode({ integer: true, min: 0, max: 255 })),
explosions: ListNode(
Reference('firework_explosion'),
{ maxLength: 16 },
{ maxLength: 256 },
),
}, { context: 'data_component.fireworks' }),
'minecraft:profile': ObjectNode({
name: Mod(SizeLimitedString({ maxLength: 16 }), node => ({
validate: (path, value, errors, options) => {
value = node.validate(path, value, errors, options)
if (typeof value === 'string' && !value.split('').map(c => c.charCodeAt(0)).some(c => c <= 32 || c >= 127)) {
errors.add(path, 'error.invalid_player_name')
}
return value
}
})),
id: ListNode(
NumberNode({ integer: true }),
{ minLength: 4, maxLength: 4 },
),
properties: MapNode( // TODO
StringNode(),
StringNode(),
),
}, { context: 'data_component.profile' }),
'minecraft:profile': ChoiceNode([
{
type: 'string',
node: Reference('player_name'),
change: v => v.name
},
{
type: 'object',
node: ObjectNode({
name: Opt(Reference('player_name')),
id: ListNode(
NumberNode({ integer: true }),
{ minLength: 4, maxLength: 4 },
),
properties: MapNode( // TODO
StringNode(),
StringNode(),
),
}),
change: v => ({ name: v })
}
], { context: 'data_component.profile' }),
'minecraft:note_block_sound': StringNode({ validator: 'resource', params: { pool: [], allowUnknown: true } }),
'minecraft:banner_patterns': ListNode(
ObjectNode({
Expand Down
6 changes: 5 additions & 1 deletion java/1.20.5/src/schemas/Predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ export function initPredicatesSchemas(schemas: SchemaRegistry, collections: Coll
location: Opt(Reference('location_predicate')),
stepping_on: Opt(Reference('location_predicate')),
distance: Opt(Reference('distance_predicate')),
slots: Opt(MapNode(
StringNode({ enum: 'slot_range', additional: true }),
Reference('item_predicate')
)),
flags: Opt(ObjectNode({
is_on_fire: Opt(BooleanNode()),
is_sneaking: Opt(BooleanNode()),
Expand All @@ -220,7 +224,7 @@ export function initPredicatesSchemas(schemas: SchemaRegistry, collections: Coll
is_baby: Opt(BooleanNode())
})),
equipment: Opt(MapNode(
StringNode({ enum: 'slot' }),
StringNode({ enum: 'equipment_slot' }),
Reference('item_predicate')
)),
vehicle: Opt(Reference('entity_predicate')),
Expand Down
Loading
Loading