Use ProtocolLib naming scheme. Use hasOwnProperty instead of equality

This commit is contained in:
roblabla 2014-03-16 18:06:57 +01:00
parent 0cd3ed13d9
commit 244ad8ed39
4 changed files with 70 additions and 69 deletions

View File

@ -14,6 +14,6 @@ client.on('chat', function(packet) {
var username = jsonMsg.with[0]; var username = jsonMsg.with[0];
var msg = jsonMsg.with[1]; var msg = jsonMsg.with[1];
if (username === client.username) return; if (username === client.username) return;
client.write('chat_message', {message: msg}); client.write('chat', {message: msg});
} }
}); });

View File

@ -38,7 +38,7 @@ server.on('login', function(client) {
onGround: true onGround: true
}); });
client.on('chat_message', function(data) { client.on('chat', function(data) {
var message = '<'+client.username+'>' + ' ' + data.message; var message = '<'+client.username+'>' + ' ' + data.message;
broadcast(message, client, client.username); broadcast(message, client, client.username);
console.log(message); console.log(message);

View File

@ -15,7 +15,7 @@ server.on('login', function(client) {
}); });
// send init data so client will start rendering world // send init data so client will start rendering world
client.write('join_game', { client.write('login', {
entityId: client.id, entityId: client.id,
levelType: 'default', levelType: 'default',
gameMode: 0, gameMode: 0,
@ -23,7 +23,7 @@ server.on('login', function(client) {
difficulty: 2, difficulty: 2,
maxPlayers: server.maxPlayers maxPlayers: server.maxPlayers
}); });
client.write('player_position', { client.write('position', {
x: 0, x: 0,
y: 1.62, y: 1.62,
z: 0, z: 0,

View File

@ -16,7 +16,7 @@ var packets = {
handshaking: { handshaking: {
toClient: {}, toClient: {},
toServer: { toServer: {
handshake: {id: 0x00, fields: [ set_protocol: {id: 0x00, fields: [
{ name: "protocolVersion", type: "varint" }, { name: "protocolVersion", type: "varint" },
{ name: "serverHost", type: "string" }, { name: "serverHost", type: "string" },
{ name: "serverPort", type: "ushort" }, { name: "serverPort", type: "ushort" },
@ -25,18 +25,19 @@ var packets = {
}, },
}, },
// TODO : protocollib names aren't the best around here
status: { status: {
toClient: { toClient: {
status_response: {id: 0x00, fields: [ server_info: {id: 0x00, fields: [
{ name: "response", type: "string" } { name: "response", type: "string" }
]}, ]},
status_ping: {id: 0x01, fields: [ ping: {id: 0x01, fields: [
{ name: "time", type: "long" } { name: "time", type: "long" }
]} ]}
}, },
toServer: { toServer: {
status_request: {id: 0x00, fields: []}, ping_start: {id: 0x00, fields: []},
status_ping: {id: 0x01, fields: [ ping: {id: 0x01, fields: [
{ name: "time", type: "long" } { name: "time", type: "long" }
]} ]}
} }
@ -44,15 +45,15 @@ var packets = {
login: { login: {
toClient: { toClient: {
login_disconnect: {id: 0x00, fields: [ disconnect: {id: 0x00, fields: [
{ name: "reason", type: "string" } { name: "reason", type: "string" }
]}, ]},
encryption_request: {id: 0x01, fields: [ encryption_begin: {id: 0x01, fields: [
{ name: "serverId", type: "string" }, { name: "serverId", type: "string" },
{ name: "publicKey", type: "byteArray16" }, { name: "publicKey", type: "byteArray16" },
{ name: "verifyToken", type: "byteArray16" } { name: "verifyToken", type: "byteArray16" }
]}, ]},
login_success: {id: 0x02, fields: [ success: {id: 0x02, fields: [
{ name: "uuid", type: "string" }, { name: "uuid", type: "string" },
{ name: "username", type: "string" } { name: "username", type: "string" }
]} ]}
@ -61,7 +62,7 @@ var packets = {
login_start: {id: 0x00, fields: [ login_start: {id: 0x00, fields: [
{ name: "username", type: "string" } { name: "username", type: "string" }
]}, ]},
encryption_response:{id: 0x01, fields: [ encryption_begin: {id: 0x01, fields: [
{ name: "sharedSecret", type: "byteArray16" }, { name: "sharedSecret", type: "byteArray16" },
{ name: "verifyToken", type: "byteArray16" } { name: "verifyToken", type: "byteArray16" }
]} ]}
@ -73,7 +74,7 @@ var packets = {
keep_alive: {id: 0x00, fields: [ keep_alive: {id: 0x00, fields: [
{ name: "keepAliveId", type: "int" }, { name: "keepAliveId", type: "int" },
]}, ]},
join_game: {id: 0x01, fields: [ login: {id: 0x01, fields: [
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "gameMode", type: "ubyte" }, { name: "gameMode", type: "ubyte" },
{ name: "dimension", type: "byte" }, { name: "dimension", type: "byte" },
@ -84,7 +85,7 @@ var packets = {
chat: {id: 0x02, fields: [ chat: {id: 0x02, fields: [
{ name: "message", type: "ustring" }, { name: "message", type: "ustring" },
]}, ]},
time_update: {id: 0x03, fields: [ update_time: {id: 0x03, fields: [
{ name: "age", type: "long" }, { name: "age", type: "long" },
{ name: "time", type: "long" }, { name: "time", type: "long" },
]}, ]},
@ -108,7 +109,7 @@ var packets = {
{ name: "gamemode", type: "ubyte" }, { name: "gamemode", type: "ubyte" },
{ name: "levelType", type: "string" } { name: "levelType", type: "string" }
]}, ]},
player_position: {id: 0x08, fields: [ position: {id: 0x08, fields: [
{ name: "x", type: "double" }, { name: "x", type: "double" },
{ name: "y", type: "double" }, { name: "y", type: "double" },
{ name: "z", type: "double" }, { name: "z", type: "double" },
@ -116,10 +117,10 @@ var packets = {
{ name: "pitch", type: "float" }, { name: "pitch", type: "float" },
{ name: "onGround", type: "bool" } { name: "onGround", type: "bool" }
]}, ]},
held_item_change: {id: 0x09, fields: [ held_item_slot: {id: 0x09, fields: [
{ name: "slot", type: "byte" } { name: "slot", type: "byte" }
]}, ]},
use_bed: {id: 0x0a, fields: [ bed: {id: 0x0a, fields: [
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "ubyte" }, { name: "y", type: "ubyte" },
@ -129,7 +130,7 @@ var packets = {
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "animation", type: "byte" } { name: "animation", type: "byte" }
]}, ]},
spawn_player: {id: 0x0c, fields: [ named_entity_spawn: {id: 0x0c, fields: [
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "playerUUID", type: "string" }, { name: "playerUUID", type: "string" },
{ name: "playerName", type: "string" }, { name: "playerName", type: "string" },
@ -141,11 +142,11 @@ var packets = {
{ name: "currentItem", type: "short" }, { name: "currentItem", type: "short" },
{ name: "metadata", type: "entityMetadata" } { name: "metadata", type: "entityMetadata" }
]}, ]},
collect_item: {id: 0x0d, fields: [ collect: {id: 0x0d, fields: [
{ name: "collectedEntityId", type: "int" }, { name: "collectedEntityId", type: "int" },
{ name: "collectorEntityId", type: "int" } { name: "collectorEntityId", type: "int" }
]}, ]},
spawn_object: {id: 0x0e, fields: [ spawn_entity: {id: 0x0e, fields: [
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "type", type: "byte" }, { name: "type", type: "byte" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
@ -155,7 +156,7 @@ var packets = {
{ name: "yaw", type: "byte" }, { name: "yaw", type: "byte" },
{ name: "objectData", type: "objectData" } { name: "objectData", type: "objectData" }
]}, ]},
spawn_mob: {id: 0x0f, fields: [ spawn_entity_living: {id: 0x0f, fields: [
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "type", type: "ubyte" }, { name: "type", type: "ubyte" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
@ -169,7 +170,7 @@ var packets = {
{ name: "velocityZ", type: "short" }, { name: "velocityZ", type: "short" },
{ name: "metadata", type: "entityMetadata" }, { name: "metadata", type: "entityMetadata" },
]}, ]},
spawn_painting: {id: 0x10, fields: [ spawn_entity_painting: {id: 0x10, fields: [
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "title", type: "string" }, { name: "title", type: "string" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
@ -177,7 +178,7 @@ var packets = {
{ name: "z", type: "int" }, { name: "z", type: "int" },
{ name: "direction", type: "int" } { name: "direction", type: "int" }
]}, ]},
spawn_experience_orb: {id: 0x11, fields: [ spawn_entity_experience_orb: {id: 0x11, fields: [
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "int" }, { name: "y", type: "int" },
@ -190,13 +191,13 @@ var packets = {
{ name: "velocityY", type: "short" }, { name: "velocityY", type: "short" },
{ name: "velocityZ", type: "short" } { name: "velocityZ", type: "short" }
]}, ]},
destroy_entities: {id: 0x13, fields: [ entity_destroy: {id: 0x13, fields: [
{ name: "entityIds", type: "intArray8" } { name: "entityIds", type: "intArray8" }
]}, ]},
entity: {id: 0x14, fields: [ entity: {id: 0x14, fields: [
{ name: "entityId", type: "int" } { name: "entityId", type: "int" }
]}, ]},
entity_relative_move: {id: 0x15, fields: [ rel_entity_move: {id: 0x15, fields: [
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "dX", type: "byte" }, { name: "dX", type: "byte" },
{ name: "dY", type: "byte" }, { name: "dY", type: "byte" },
@ -207,7 +208,7 @@ var packets = {
{ name: "yaw", type: "byte" }, { name: "yaw", type: "byte" },
{ name: "pitch", type: "byte" } { name: "pitch", type: "byte" }
]}, ]},
entity_look_and_relative_move: {id: 0x17, fields: [ entity_move_look: {id: 0x17, fields: [
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "dX", type: "byte" }, { name: "dX", type: "byte" },
{ name: "dY", type: "byte" }, { name: "dY", type: "byte" },
@ -223,7 +224,7 @@ var packets = {
{ name: "yaw", type: "byte" }, { name: "yaw", type: "byte" },
{ name: "pitch", type: "byte" } { name: "pitch", type: "byte" }
]}, ]},
entity_head_look: {id: 0x19, fields: [ entity_head_rotation: {id: 0x19, fields: [
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "headYaw", type: "byte" }, { name: "headYaw", type: "byte" },
]}, ]},
@ -250,16 +251,16 @@ var packets = {
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "effectId", type: "byte" } { name: "effectId", type: "byte" }
]}, ]},
set_experience: {id: 0x1f, fields: [ experience: {id: 0x1f, fields: [
{ name: "experienceBar", type: "float" }, { name: "experienceBar", type: "float" },
{ name: "level", type: "short" }, { name: "level", type: "short" },
{ name: "totalExperience", type: "short" } { name: "totalExperience", type: "short" }
]}, ]},
entity_properties: {id: 0x20, fields: [ update_attributes: {id: 0x20, fields: [
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "properties", type: "propertyArray" } { name: "properties", type: "propertyArray" }
]}, ]},
chunk_data: {id: 0x21, fields: [ map_chunk: {id: 0x21, fields: [
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "z", type: "int" }, { name: "z", type: "int" },
{ name: "groundUp", type: "bool" }, { name: "groundUp", type: "bool" },
@ -288,7 +289,7 @@ var packets = {
{ name: "byte2", type: "ubyte" }, { name: "byte2", type: "ubyte" },
{ name: "blockId", type: "varint" } { name: "blockId", type: "varint" }
]}, ]},
block_break_anim: {id: 0x25, fields: [ block_break_animation: {id: 0x25, fields: [
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "int" }, { name: "y", type: "int" },
@ -308,7 +309,7 @@ var packets = {
{ name: "playerMotionY", type: "float" }, { name: "playerMotionY", type: "float" },
{ name: "playerMotionZ", type: "float" } { name: "playerMotionZ", type: "float" }
]}, ]},
effect: {id: 0x28, fields: [ world_event: {id: 0x28, fields: [ // TODO : kinda wtf naming there
{ name: "effectId", type: "int" }, { name: "effectId", type: "int" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "byte" }, { name: "y", type: "byte" },
@ -316,7 +317,7 @@ var packets = {
{ name: "data", type: "int" }, { name: "data", type: "int" },
{ name: "global", type: "bool" } { name: "global", type: "bool" }
]}, ]},
sound_effect: {id: 0x29, fields: [ named_sound_effect: {id: 0x29, fields: [
{ name: "soundName", type: "string" }, { name: "soundName", type: "string" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "int" }, { name: "y", type: "int" },
@ -324,7 +325,7 @@ var packets = {
{ name: "volume", type: "float" }, { name: "volume", type: "float" },
{ name: "pitch", type: "ubyte" } { name: "pitch", type: "ubyte" }
]}, ]},
particle: {id: 0x2a, fields: [ world_particles: {id: 0x2a, fields: [
{ name: "particleName", type: "string" }, { name: "particleName", type: "string" },
{ name: "x", type: "float" }, { name: "x", type: "float" },
{ name: "y", type: "float" }, { name: "y", type: "float" },
@ -335,11 +336,11 @@ var packets = {
{ name: "particleSpeed", type: "float" }, { name: "particleSpeed", type: "float" },
{ name: "particles", type: "int" } { name: "particles", type: "int" }
]}, ]},
change_game_state: {id: 0x2b, fields: [ game_state_change: {id: 0x2b, fields: [
{ name: "reason", type: "ubyte" }, { name: "reason", type: "ubyte" },
{ name: "gameMode", type: "float" } { name: "gameMode", type: "float" }
]}, ]},
spawn_global_entity:{id: 0x2c, fields: [ spawn_entity_weather:{id: 0x2c, fields: [
{ name: "entityId", type: "varint" }, { name: "entityId", type: "varint" },
{ name: "type", type: "byte" }, { name: "type", type: "byte" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
@ -368,12 +369,12 @@ var packets = {
{ name: "windowId", type: "ubyte" }, { name: "windowId", type: "ubyte" },
{ name: "items", type: "slotArray" } { name: "items", type: "slotArray" }
]}, ]},
window_property: {id: 0x31, fields: [ craft_progress_bar: {id: 0x31, fields: [
{ name: "windowId", type: "ubyte" }, { name: "windowId", type: "ubyte" },
{ name: "property", type: "short" }, { name: "property", type: "short" },
{ name: "value", type: "short" } { name: "value", type: "short" }
]}, ]},
confirm_transaction:{id: 0x32, fields: [ transaction:{id: 0x32, fields: [
{ name: "windowId", type: "ubyte" }, { name: "windowId", type: "ubyte" },
{ name: "action", type: "short" }, { name: "action", type: "short" },
{ name: "accepted", type: "bool" } { name: "accepted", type: "bool" }
@ -387,18 +388,18 @@ var packets = {
{ name: "text3", type: "string" }, { name: "text3", type: "string" },
{ name: "text4", type: "string" } { name: "text4", type: "string" }
]}, ]},
maps: {id: 0x34, fields: [ map: {id: 0x34, fields: [
{ name: "itemDamage", type: "varint" }, { name: "itemDamage", type: "varint" },
{ name: "data", type: "byteArray16" }, { name: "data", type: "byteArray16" },
]}, ]},
update_block_entity:{id: 0x35, fields: [ tile_entity_data:{id: 0x35, fields: [
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "short" }, { name: "y", type: "short" },
{ name: "z", type: "int" }, { name: "z", type: "int" },
{ name: "action", type: "ubyte" }, { name: "action", type: "ubyte" },
{ name: "nbtData", type: "byteArray16" } { name: "nbtData", type: "byteArray16" }
]}, ]},
sign_editor_open: {id: 0x36, fields: [ open_sign_entity: {id: 0x36, fields: [
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "int" }, { name: "y", type: "int" },
{ name: "z", type: "int" } { name: "z", type: "int" }
@ -406,12 +407,12 @@ var packets = {
statistics: {id: 0x37, fields: [ statistics: {id: 0x37, fields: [
{ name: "count", type: "statisticArray" } { name: "count", type: "statisticArray" }
]}, ]},
player_list_item: {id: 0x38, fields: [ player_info: {id: 0x38, fields: [
{ name: "playerName", type: "string" }, { name: "playerName", type: "string" },
{ name: "online", type: "bool" }, { name: "online", type: "bool" },
{ name: "ping", type: "short" } { name: "ping", type: "short" }
]}, ]},
player_abilities: {id: 0x39, fields: [ abilities: {id: 0x39, fields: [
{ name: "flags", type: "byte" }, { name: "flags", type: "byte" },
{ name: "flyingSpeed", type: "float" }, { name: "flyingSpeed", type: "float" },
{ name: "walkingSpeed", type: "float" } { name: "walkingSpeed", type: "float" }
@ -424,7 +425,7 @@ var packets = {
{ name: "displayText", type: "string" }, { name: "displayText", type: "string" },
{ name: "action", type: "byte" } { name: "action", type: "byte" }
]}, ]},
update_score: {id: 0x3c, fields: [ scoreboard_score: {id: 0x3c, fields: [
{ name: "itemName", type: "string" }, { name: "itemName", type: "string" },
{ name: "remove", type: "bool" }, { name: "remove", type: "bool" },
{ name: "scoreName", type: "string", condition: function(field_values) { { name: "scoreName", type: "string", condition: function(field_values) {
@ -434,11 +435,11 @@ var packets = {
return !field_values['remove'] return !field_values['remove']
} } } }
]}, ]},
display_scoreboard: {id: 0x3d, fields: [ scoreboard_display_objective: {id: 0x3d, fields: [
{ name: "position", type: "byte" }, { name: "position", type: "byte" },
{ name: "name", type: "string" } { name: "name", type: "string" }
]}, ]},
teams: {id: 0x3e, fields: [ scoreboard_team: {id: 0x3e, fields: [
{ name: "team", type: "string" }, { name: "team", type: "string" },
{ name: "mode", type: "byte" }, { name: "mode", type: "byte" },
{ name: "name", type: "string", condition: function(field_values) { { name: "name", type: "string", condition: function(field_values) {
@ -457,11 +458,11 @@ var packets = {
return field_values['mode'] == 0 || field_values['mode'] == 3 || field_values['mode'] == 4; return field_values['mode'] == 0 || field_values['mode'] == 3 || field_values['mode'] == 4;
} } } }
]}, ]},
plugin_message: {id: 0x3f, fields: [ custom_payload: {id: 0x3f, fields: [
{ name: "channel", type: "string" }, { name: "channel", type: "string" },
{ name: "data", type: "byteArray16" } { name: "data", type: "byteArray16" }
]}, ]},
disconnect: {id: 0x40, fields: [ kick_disconnect: {id: 0x40, fields: [
{ name: "reason", type: "string" } { name: "reason", type: "string" }
]} ]}
}, },
@ -469,29 +470,29 @@ var packets = {
keep_alive: {id: 0x00, fields: [ keep_alive: {id: 0x00, fields: [
{ name: "keepAliveId", type: "int" } { name: "keepAliveId", type: "int" }
]}, ]},
chat_message: {id: 0x01, fields: [ chat: {id: 0x01, fields: [
{ name: "message", type: "string" } { name: "message", type: "string" }
]}, ]},
use_entity: {id: 0x02, fields: [ use_entity: {id: 0x02, fields: [
{ name: "target", type: "int" }, { name: "target", type: "int" },
{ name: "leftClick", type: "byte" } { name: "leftClick", type: "byte" }
]}, ]},
player: {id: 0x03, fields: [ flying: {id: 0x03, fields: [
{ name: "onGround", type: "bool" } { name: "onGround", type: "bool" }
]}, ]},
player_position: {id: 0x04, fields: [ position: {id: 0x04, fields: [
{ name: "x", type: "double" }, { name: "x", type: "double" },
{ name: "stance", type: "double" }, { name: "stance", type: "double" },
{ name: "y", type: "double" }, { name: "y", type: "double" },
{ name: "z", type: "double" }, { name: "z", type: "double" },
{ name: "onGround", type: "bool" } { name: "onGround", type: "bool" }
]}, ]},
player_look: {id: 0x05, fields: [ look: {id: 0x05, fields: [
{ name: "yaw", type: "float" }, { name: "yaw", type: "float" },
{ name: "pitch", type: "float" }, { name: "pitch", type: "float" },
{ name: "onGround", type: "bool" } { name: "onGround", type: "bool" }
]}, ]},
player_position_and_look: {id: 0x06, fields: [ position_look: {id: 0x06, fields: [
{ name: "x", type: "double" }, { name: "x", type: "double" },
{ name: "stance", type: "double" }, { name: "stance", type: "double" },
{ name: "y", type: "double" }, { name: "y", type: "double" },
@ -500,14 +501,14 @@ var packets = {
{ name: "pitch", type: "float" }, { name: "pitch", type: "float" },
{ name: "onGround", type: "bool" } { name: "onGround", type: "bool" }
]}, ]},
player_digging: {id: 0x07, fields: [ block_dig: {id: 0x07, fields: [
{ name: "status", type: "byte" }, { name: "status", type: "byte" },
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "ubyte" }, { name: "y", type: "ubyte" },
{ name: "z", type: "int" }, { name: "z", type: "int" },
{ name: "face", type: "byte" } { name: "face", type: "byte" }
]}, ]},
player_block_placement: {id: 0x08, fields: [ block_place: {id: 0x08, fields: [
{ name: "x", type: "int" }, { name: "x", type: "int" },
{ name: "y", type: "ubyte" }, { name: "y", type: "ubyte" },
{ name: "z", type: "int" }, { name: "z", type: "int" },
@ -517,10 +518,10 @@ var packets = {
{ name: "cursorY", type: "byte" }, { name: "cursorY", type: "byte" },
{ name: "cursorZ", type: "byte" } { name: "cursorZ", type: "byte" }
]}, ]},
held_item_change: {id: 0x09, fields: [ held_item_slot: {id: 0x09, fields: [
{ name: "slotId", type: "short" } { name: "slotId", type: "short" }
]}, ]},
animation: {id: 0x0a, fields: [ arm_animation: {id: 0x0a, fields: [
{ name: "entityId", type: "int" }, { name: "entityId", type: "int" },
{ name: "animation", type: "byte" } { name: "animation", type: "byte" }
]}, ]},
@ -538,7 +539,7 @@ var packets = {
close_window: {id: 0x0d, fields: [ close_window: {id: 0x0d, fields: [
{ name: "windowId", type: "byte" } { name: "windowId", type: "byte" }
]}, ]},
click_window: {id: 0x0e, fields: [ window_click: {id: 0x0e, fields: [
{ name: "windowId", type: "byte" }, { name: "windowId", type: "byte" },
{ name: "slot", type: "short" }, { name: "slot", type: "short" },
{ name: "mouseButton", type: "byte" }, { name: "mouseButton", type: "byte" },
@ -546,12 +547,12 @@ var packets = {
{ name: "mode", type: "byte" }, { name: "mode", type: "byte" },
{ name: "item", type: "slot" } { name: "item", type: "slot" }
]}, ]},
confirm_transaction: {id: 0x0f, fields: [ transaction: {id: 0x0f, fields: [
{ name: "windowId", type: "byte" }, { name: "windowId", type: "byte" },
{ name: "action", type: "short" }, { name: "action", type: "short" },
{ name: "accepted", type: "bool" } { name: "accepted", type: "bool" }
]}, ]},
creative_inventory_action: {id: 0x10, fields: [ set_creative_slot: {id: 0x10, fields: [
{ name: "slot", type: "short" }, { name: "slot", type: "short" },
{ name: "item", type: "slot" } { name: "item", type: "slot" }
]}, ]},
@ -568,7 +569,7 @@ var packets = {
{ name: "text3", type: "string" }, { name: "text3", type: "string" },
{ name: "text4", type: "string" } { name: "text4", type: "string" }
]}, ]},
player_abilities: {id: 0x13, fields: [ abilities: {id: 0x13, fields: [
{ name: "flags", type: "byte" }, { name: "flags", type: "byte" },
{ name: "flyingSpeed", type: "float" }, { name: "flyingSpeed", type: "float" },
{ name: "walkingSpeed", type: "float" } { name: "walkingSpeed", type: "float" }
@ -576,7 +577,7 @@ var packets = {
tab_complete: {id: 0x14, fields: [ tab_complete: {id: 0x14, fields: [
{ name: "text", type: "string" } { name: "text", type: "string" }
]}, ]},
client_settings: {id: 0x15, fields: [ settings: {id: 0x15, fields: [
{ name: "locale", type: "string" }, { name: "locale", type: "string" },
{ name: "viewDistance", type: "byte" }, { name: "viewDistance", type: "byte" },
{ name: "chatFlags", type: "byte" }, { name: "chatFlags", type: "byte" },
@ -584,10 +585,10 @@ var packets = {
{ name: "difficulty", type: "byte" }, { name: "difficulty", type: "byte" },
{ name: "showCape", type: "bool" } { name: "showCape", type: "bool" }
]}, ]},
client_status: {id: 0x16, fields: [ client_command: {id: 0x16, fields: [
{ name: "payload", type: "byte" } { name: "payload", type: "byte" }
]}, ]},
plugin_message: {id: 0x17, fields: [ custom_payload: {id: 0x17, fields: [
{ name: "channel", type: "string" }, { name: "channel", type: "string" },
{ name: "data", type: "byteArray16" } { name: "data", type: "byteArray16" }
]} ]}
@ -615,10 +616,10 @@ var packetStates = {toClient: {}, toServer: {}};
assert(id !== undefined, 'missing id for packet '+name); assert(id !== undefined, 'missing id for packet '+name);
assert(fields !== undefined, 'missing fields for packet '+name); assert(fields !== undefined, 'missing fields for packet '+name);
assert(packetNames[state][direction][id] === undefined, 'duplicate packet id '+id+' for '+name); assert(!packetNames[state][direction].hasOwnProperty(id), 'duplicate packet id '+id+' for '+name);
assert(packetIds[state][direction][name] === undefined, 'duplicate packet name '+name+' for '+id); assert(!packetIds[state][direction].hasOwnProperty(name), 'duplicate packet name '+name+' for '+id);
assert(packetFields[state][direction][id] === undefined, 'duplicate packet id '+id+' for '+name); assert(!packetFields[state][direction].hasOwnProperty(id), 'duplicate packet id '+id+' for '+name);
assert(packetStates[direction][name] === undefined, 'duplicate packet name '+name+' for '+id+', must be unique across all states'); assert(!packetStates[direction].hasOwnProperty(name), 'duplicate packet name '+name+' for '+id+', must be unique across all states');
packetNames[state][direction][id] = name; packetNames[state][direction][id] = name;
packetIds[state][direction][name] = id; packetIds[state][direction][name] = id;