Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/bedrock/0.15/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@
"0x3c": "request_chunk_radius",
"0x3d": "chunk_radius_update",
"0x3a": "spawn_experience_orb",
"0x3f": "replace_selected_item"
"0x3f": "replace_selected_item",
"0x55": "transfer"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion data/bedrock/1.16.201/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ packet_boss_event:
_: type?
if register_player or unregister_player:
player_id: zigzag64
if show:
if show_bar:
title: string
bar_progress: lf32
if update_properties:
Expand Down
2 changes: 1 addition & 1 deletion data/bedrock/1.16.201/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -5248,7 +5248,7 @@
}
]
],
"show": [
"show_bar": [
"container",
[
{
Expand Down
2 changes: 1 addition & 1 deletion data/bedrock/1.16.210/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ packet_boss_event:
_: type?
if register_player or unregister_player:
player_id: zigzag64
if show:
if show_bar:
title: string
bar_progress: lf32
if update_properties:
Expand Down
2 changes: 1 addition & 1 deletion data/bedrock/1.16.210/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -5547,7 +5547,7 @@
}
]
],
"show": [
"show_bar": [
"container",
[
{
Expand Down
1 change: 1 addition & 0 deletions data/pc/1.20.5/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@
- minecraft:crafting_special_firework_star_fade
- minecraft:crafting_special_tippedarrow
- minecraft:crafting_special_bannerduplicate
- minecraft:crafting_special_banneraddpattern
- minecraft:crafting_special_shielddecoration
- minecraft:crafting_special_shulkerboxcoloring
- minecraft:crafting_special_suspiciousstew
Expand Down
25 changes: 13 additions & 12 deletions data/pc/1.20.5/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -6891,18 +6891,19 @@
"8": "minecraft:crafting_special_firework_star_fade",
"9": "minecraft:crafting_special_tippedarrow",
"10": "minecraft:crafting_special_bannerduplicate",
"11": "minecraft:crafting_special_shielddecoration",
"12": "minecraft:crafting_special_shulkerboxcoloring",
"13": "minecraft:crafting_special_suspiciousstew",
"14": "minecraft:crafting_special_repairitem",
"15": "minecraft:smelting",
"16": "minecraft:blasting",
"17": "minecraft:smoking",
"18": "minecraft:campfire_cooking",
"19": "minecraft:stonecutting",
"20": "minecraft:smithing_transform",
"21": "minecraft:smithing_trim",
"22": "minecraft:crafting_decorated_pot"
"11": "minecraft:crafting_special_banneraddpattern",
"12": "minecraft:crafting_special_shielddecoration",
"13": "minecraft:crafting_special_shulkerboxcoloring",
"14": "minecraft:crafting_special_suspiciousstew",
"15": "minecraft:crafting_special_repairitem",
"16": "minecraft:smelting",
"17": "minecraft:blasting",
"18": "minecraft:smoking",
"19": "minecraft:campfire_cooking",
"20": "minecraft:stonecutting",
"21": "minecraft:smithing_transform",
"22": "minecraft:smithing_trim",
"23": "minecraft:crafting_decorated_pot"
}
}
]
Expand Down
1 change: 1 addition & 0 deletions data/pc/1.21.1/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,7 @@
- minecraft:crafting_special_firework_star_fade
- minecraft:crafting_special_tippedarrow
- minecraft:crafting_special_bannerduplicate
- minecraft:crafting_special_banneraddpattern
- minecraft:crafting_special_shielddecoration
- minecraft:crafting_special_shulkerboxcoloring
- minecraft:crafting_special_suspiciousstew
Expand Down
25 changes: 13 additions & 12 deletions data/pc/1.21.1/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -7071,18 +7071,19 @@
"8": "minecraft:crafting_special_firework_star_fade",
"9": "minecraft:crafting_special_tippedarrow",
"10": "minecraft:crafting_special_bannerduplicate",
"11": "minecraft:crafting_special_shielddecoration",
"12": "minecraft:crafting_special_shulkerboxcoloring",
"13": "minecraft:crafting_special_suspiciousstew",
"14": "minecraft:crafting_special_repairitem",
"15": "minecraft:smelting",
"16": "minecraft:blasting",
"17": "minecraft:smoking",
"18": "minecraft:campfire_cooking",
"19": "minecraft:stonecutting",
"20": "minecraft:smithing_transform",
"21": "minecraft:smithing_trim",
"22": "minecraft:crafting_decorated_pot"
"11": "minecraft:crafting_special_banneraddpattern",
"12": "minecraft:crafting_special_shielddecoration",
"13": "minecraft:crafting_special_shulkerboxcoloring",
"14": "minecraft:crafting_special_suspiciousstew",
"15": "minecraft:crafting_special_repairitem",
"16": "minecraft:smelting",
"17": "minecraft:blasting",
"18": "minecraft:smoking",
"19": "minecraft:campfire_cooking",
"20": "minecraft:stonecutting",
"21": "minecraft:smithing_transform",
"22": "minecraft:smithing_trim",
"23": "minecraft:crafting_decorated_pot"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion data/pc/26.1/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
"96": "cow/sound_variant",
"97": "chicken/variant",
"98": "chicken/sound_variant",
"99": "zomie_nautilus/variant",
"99": "zombie_nautilus/variant",
"100": "frog/variant",
"101": "horse/variant",
"102": "painting/variant",
Expand Down
2 changes: 1 addition & 1 deletion data/pc/latest/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
- cow/sound_variant
- chicken/variant
- chicken/sound_variant
- zomie_nautilus/variant
- zombie_nautilus/variant
- frog/variant
- horse/variant
- painting/variant
Expand Down
63 changes: 63 additions & 0 deletions tools/js/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,68 @@ after('the test suite stays fast', function () {
assert.ok(ms < 40 * 1000, `the test suite took ${Math.round(ms)}ms, expected < 40s`)
})

function resolveType (type, types, seen = new Set()) {
if (typeof type === 'string' && types[type] && !seen.has(type)) {
seen.add(type)
return resolveType(types[type], types, seen)
}
return type
}

function checkProtocolSwitches (protocol, versionString) {
const issues = []

function visitType (type, scope, location, active = new Set()) {
if (!Array.isArray(type) || active.has(type)) return
active.add(type)
const [kind, options] = type
if (kind === 'container' && Array.isArray(options)) {
const fields = { ...scope }
for (const field of options) {
if (!field || typeof field !== 'object') continue
const fieldType = resolveType(field.type, protocol.types)
if (Array.isArray(fieldType) && fieldType[0] === 'mapper') {
fields[field.name] = new Set(Object.values(fieldType[1].mappings || {}))
}
visitType(fieldType, fields, location + '/' + (field.name || '?'), active)
}
} else if (kind === 'switch' && options) {
const mapper = scope[options.compareTo]
if (mapper) {
for (const value of Object.keys(options.fields || {})) {
if (!mapper.has(value)) issues.push(`${location}: ${options.compareTo} -> ${value}`)
}
} else if (options.compareTo) {
console.log(`${versionString}: unable to find ${options.compareTo} for switch at ${location}`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Thinking about it it would make sense to put this into protodef-validator itself. But for now this seems like good stopgap fixing present protocol def bugs

}
for (const [value, fieldType] of Object.entries(options.fields || {})) {
visitType(fieldType, scope, location + '/' + value, active)
}
if (options.default) visitType(options.default, scope, location + '/default', active)
} else if (kind === 'array' || kind === 'option') {
visitType(options && options.type, scope, location + '/type', active)
} else if (kind === 'registryEntryHolder') {
visitType(options && options.otherwise && options.otherwise.type, scope, location + '/otherwise', active)
}
active.delete(type)
}

function visit (value, location) {
if (Array.isArray(value)) {
if (typeof value[0] === 'string' && ['container', 'switch', 'array', 'option', 'mapper', 'registryEntryHolder'].includes(value[0])) {
visitType(value, {}, location)
} else {
value.forEach((item, index) => visit(item, location + '/' + index))
}
} else if (value && typeof value === 'object') {
Object.entries(value).forEach(([key, item]) => visit(item, location + '/' + key))
}
}

visit(protocol, versionString)
assert.deepEqual(issues, [], `${versionString} has switches with undefined mapper values:\n${issues.join('\n')}`)
}

const data = ['attributes', 'biomes', 'commands', 'instruments', 'items', 'materials', 'blocks', 'blockCollisionShapes', 'recipes', 'windows', 'entities', 'protocol', 'version', 'effects', 'enchantments', 'language', 'foods', 'particles', 'blockLoot', 'entityLoot', 'mapIcons', 'tints', 'blockMappings', 'sounds', 'blockStates']

require('./version_iterator')(function (p, versionString) {
Expand All @@ -44,6 +106,7 @@ require('./version_iterator')(function (p, versionString) {
validator.addType('entityMetadataItem', require('../../../schemas/protocol_types/entity_metadata_item.json'))
validator.addType('entityMetadataLoop', require('../../../schemas/protocol_types/entity_metadata_loop.json'))
validator.validateProtocol(instance)
checkProtocolSwitches(instance, versionString)
} else {
const schema = require('../../../schemas/' + dataName + '_schema.json')
const valid = v.validate(schema, instance)
Expand Down
Loading