mcdevs-wiki-extractor 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +14 -0
- package/.github/workflows/ci.yml +25 -0
- package/.github/workflows/commands.yml +22 -0
- package/.github/workflows/publish.yml +34 -0
- package/README.md +40 -3
- package/bin/entities_to_json.js +12 -12
- package/bin/protocol_comments_to_json.js +15 -0
- package/bin/protocol_to_json.js +11 -11
- package/index.js +4 -4
- package/lib/common/table_parser.js +75 -95
- package/lib/common/toOldNames.js +98 -0
- package/lib/entities_extractor.js +54 -47
- package/lib/protocol_extractor.js +309 -373
- package/lib/relink.js +10 -0
- package/package.json +8 -4
- package/test/test_protocol_extractor.js +220 -221
- package/.npmignore +0 -1
- package/circle.yml +0 -3
|
@@ -1,465 +1,401 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const WikiTextParser = require('parse-wikitext')
|
|
2
|
+
const async = require('async')
|
|
3
|
+
const R = require('ramda')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const pandoc = require('pdc')
|
|
6
|
+
const path = require('path')
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
const wikiTextParser = new WikiTextParser('wiki.vg')
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const parseWikiTable = require('./common/table_parser').parseWikiTable
|
|
11
|
+
const getFirstTable = require('./common/table_parser').getFirstTable
|
|
12
|
+
const tableToRows = require('./common/table_parser').tableToRows
|
|
13
|
+
const toOldNames = require('./common/toOldNames').transformPacketName
|
|
10
14
|
|
|
11
15
|
module.exports = {
|
|
12
|
-
tableToRows:tableToRows,
|
|
13
|
-
parseWikiTable:parseWikiTable,
|
|
14
|
-
tableToPacket:tableToPacket,
|
|
15
|
-
writeProtocol:writeProtocol
|
|
16
|
-
|
|
16
|
+
tableToRows: tableToRows,
|
|
17
|
+
parseWikiTable: parseWikiTable,
|
|
18
|
+
tableToPacket: tableToPacket,
|
|
19
|
+
writeProtocol: writeProtocol,
|
|
20
|
+
writeComments: writeComments
|
|
21
|
+
}
|
|
17
22
|
|
|
18
|
-
function
|
|
19
|
-
{
|
|
23
|
+
function writeComments (protocolFilePath, cb) {
|
|
20
24
|
async.waterfall([
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
25
|
+
getProtocolComments
|
|
26
|
+
],
|
|
27
|
+
function (err, protocol) {
|
|
28
|
+
if (err) { return cb(err) }
|
|
29
|
+
// console.log(JSON.stringify(protocol,null,2));
|
|
30
|
+
fs.writeFile(protocolFilePath, JSON.stringify(protocol, null, 2), cb)
|
|
31
|
+
}
|
|
32
|
+
)
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
function writeProtocol (protocolFilePath, cb) {
|
|
36
|
+
async.waterfall([
|
|
37
|
+
getProtocol
|
|
38
|
+
],
|
|
39
|
+
function (err, protocol) {
|
|
40
|
+
if (err) { return cb(err) }
|
|
41
|
+
// console.log(JSON.stringify(protocol,null,2));
|
|
42
|
+
fs.writeFile(protocolFilePath, JSON.stringify(protocol, null, 2), cb)
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
}
|
|
32
46
|
|
|
33
|
-
function retrieveProtocol(cb)
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
cb(err);
|
|
39
|
-
return;
|
|
47
|
+
function retrieveProtocol (cb) {
|
|
48
|
+
wikiTextParser.getArticle('Protocol', function (err, data) {
|
|
49
|
+
if (err) {
|
|
50
|
+
cb(err)
|
|
51
|
+
return
|
|
40
52
|
}
|
|
41
|
-
|
|
42
|
-
cb(err,sectionObject)
|
|
43
|
-
})
|
|
53
|
+
const sectionObject = wikiTextParser.pageToSectionObject(data)
|
|
54
|
+
cb(err, sectionObject)
|
|
55
|
+
})
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
function getProtocol(cb) {
|
|
58
|
+
function getProtocol (cb) {
|
|
47
59
|
async.waterfall([
|
|
48
60
|
retrieveProtocol,
|
|
49
|
-
extractProtocol,
|
|
50
|
-
transformProtocol
|
|
51
|
-
],cb)
|
|
61
|
+
extractProtocol.bind(null, parsePacket),
|
|
62
|
+
transformProtocol.bind(null, initialPacket, appendPacketToProto, transformPacket, toOldNames)
|
|
63
|
+
], cb)
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
function getProtocolComments (cb) {
|
|
67
|
+
async.waterfall([
|
|
68
|
+
retrieveProtocol,
|
|
69
|
+
extractProtocol.bind(null, commentsForPacket),
|
|
70
|
+
transformProtocol.bind(null, function () { return {} }, function (obj, name, v) { obj[name] = v; return obj }, function (v) { return v }, toOldNames)
|
|
71
|
+
], cb)
|
|
72
|
+
}
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.filter(function(key) {
|
|
61
|
-
return notStates.indexOf(key) == -1;
|
|
62
|
-
})
|
|
63
|
-
.reduce(function(protocol, state) {
|
|
64
|
-
protocol[state] = Object
|
|
65
|
-
.keys(sectionObject[state])
|
|
66
|
-
.filter(function(key) {
|
|
67
|
-
return key != "content"
|
|
68
|
-
})
|
|
69
|
-
.reduce(function(stateO, direction) {
|
|
70
|
-
stateO[direction] = Object
|
|
71
|
-
.keys(sectionObject[state][direction])
|
|
72
|
-
.filter(function(key) {
|
|
73
|
-
return key != "content"
|
|
74
|
-
})
|
|
75
|
-
.reduce(function(packetsO, packetName) {
|
|
76
|
-
packetsO[packetName] = parsePacket(sectionObject[state][direction][packetName]['content']);
|
|
77
|
-
return packetsO;
|
|
78
|
-
}, {});
|
|
79
|
-
return stateO;
|
|
80
|
-
}, {});
|
|
81
|
-
return protocol;
|
|
82
|
-
}, {});
|
|
74
|
+
function extractProtocol (fnPacket, sectionObject, cb) {
|
|
75
|
+
const notStates = R.omit(['content', 'Definitions', 'Packet format'])
|
|
83
76
|
|
|
84
|
-
|
|
77
|
+
async.mapValues(notStates(sectionObject), function (state, stateName, cb) {
|
|
78
|
+
async.mapValues(notStates(state), function (direction, directionName, cb) {
|
|
79
|
+
async.mapValues(notStates(direction), function (packet, packetName, cb) {
|
|
80
|
+
fnPacket(packet.content, cb)
|
|
81
|
+
}, cb)
|
|
82
|
+
}, cb)
|
|
83
|
+
}, cb)
|
|
85
84
|
}
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
function commentsForPacket (packetText, cb) {
|
|
87
|
+
let afterFirstTable = false
|
|
88
|
+
let inTable = false
|
|
89
|
+
const table = parseWikiTable(getFirstTable(packetText))
|
|
90
|
+
const id = table.length > 0 && table[0]['Packet ID'] && table[0]['Packet ID'].toLowerCase()
|
|
91
|
+
const packet = packetText.reduce(function (acc, line) {
|
|
92
|
+
if (!afterFirstTable && line === '{| class="wikitable"') { inTable = true } else if (inTable && line === ' |}') {
|
|
93
|
+
inTable = false
|
|
94
|
+
afterFirstTable = true
|
|
95
|
+
} else if (afterFirstTable) { acc.after.push(line) } else if (!inTable) { acc.before.push(line) }
|
|
96
|
+
return acc
|
|
97
|
+
}, { before: [], after: [], id: id })
|
|
98
|
+
pandoc(packet.before.join('\n'), 'mediawiki', 'markdown_github', ['-F', path.join(__dirname, 'relink.js')], function (err, result) {
|
|
99
|
+
if (err) return cb(err)
|
|
100
|
+
packet.before = result.split('\n')
|
|
101
|
+
pandoc(packet.after.join('\n'), 'mediawiki', 'markdown_github', ['-F', path.join(__dirname, 'relink.js')], function (err, result) {
|
|
102
|
+
if (err) return cb(err)
|
|
103
|
+
packet.after = result.split('\n')
|
|
104
|
+
return cb(null, packet)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
91
107
|
}
|
|
92
108
|
|
|
109
|
+
function parsePacket (packetText, cb) {
|
|
110
|
+
cb(null, tableToPacket(parseWikiTable(getFirstTable(packetText))))
|
|
111
|
+
}
|
|
93
112
|
|
|
94
|
-
function tableToPacket(table)
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
.filter(function(value){
|
|
102
|
-
return !value["Field Name"] || value["Field Name"]!="''no fields''"
|
|
113
|
+
function tableToPacket (table) {
|
|
114
|
+
const packet = {}
|
|
115
|
+
if (table.length === 0 || table[0]['Packet ID'] === undefined) { return null }
|
|
116
|
+
packet.id = table[0]['Packet ID']
|
|
117
|
+
packet.fields = table
|
|
118
|
+
.filter(function (value) {
|
|
119
|
+
return !value['Field Name'] || value['Field Name'] !== "''no fields''"
|
|
103
120
|
})
|
|
104
|
-
.map(function(value){
|
|
105
|
-
|
|
106
|
-
//console.log(value);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
.map(function (value) {
|
|
122
|
+
if (value['Field Name'] === undefined || value['Field Type'] === undefined) {
|
|
123
|
+
// console.log(value);
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
name: value['Field Name'],
|
|
128
|
+
type: value['Field Type']
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
return packet
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function initialPacket () {
|
|
135
|
+
return {
|
|
136
|
+
types: {
|
|
137
|
+
packet: ['container', [
|
|
138
|
+
{
|
|
139
|
+
name: 'name',
|
|
140
|
+
type: ['mapper', {
|
|
141
|
+
type: 'varint',
|
|
142
|
+
mappings: {}
|
|
143
|
+
}]
|
|
144
|
+
}, {
|
|
145
|
+
name: 'params',
|
|
146
|
+
type: ['switch', {
|
|
147
|
+
compareTo: 'name',
|
|
148
|
+
fields: {}
|
|
149
|
+
}]
|
|
150
|
+
}
|
|
151
|
+
]]
|
|
112
152
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function appendPacketToProto (state, name, packet) {
|
|
157
|
+
state.types['packet_' + name] = ['container', packet.fields]
|
|
158
|
+
state.types.packet[1][0].type[1].mappings[packet.id] = name
|
|
159
|
+
state.types.packet[1][1].type[1].fields[name] = 'packet_' + name
|
|
160
|
+
return state
|
|
115
161
|
}
|
|
116
162
|
|
|
117
163
|
// transforms
|
|
118
|
-
function transformProtocol(protocol,cb)
|
|
119
|
-
|
|
120
|
-
var transformedProtocol = Object
|
|
164
|
+
function transformProtocol (initialState, addToPacket, transformPacket, transformPacketName, protocol, cb) {
|
|
165
|
+
let transformedProtocol = Object
|
|
121
166
|
.keys(protocol)
|
|
122
|
-
.reduce(function(transformedProtocol, state) {
|
|
123
|
-
|
|
167
|
+
.reduce(function (transformedProtocol, state) {
|
|
168
|
+
const transformedState = transformState(state)
|
|
124
169
|
transformedProtocol[transformedState] = Object
|
|
125
170
|
.keys(protocol[state])
|
|
126
|
-
.reduce(function(stateO, direction) {
|
|
127
|
-
|
|
171
|
+
.reduce(function (stateO, direction) {
|
|
172
|
+
const transformedDirection = transformDirection(direction)
|
|
128
173
|
stateO[transformedDirection] = Object
|
|
129
174
|
.keys(protocol[state][direction])
|
|
130
|
-
.reduce(function(packetsO, packetName) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
packetsO
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
cb(null,transformedProtocol);
|
|
175
|
+
.reduce(function (packetsO, packetName) {
|
|
176
|
+
const transformedPacket = transformPacket(protocol[state][direction][packetName], transformedState, transformedDirection)
|
|
177
|
+
const transformedPacketName = transformPacketName(packetName, transformedState, transformedDirection, transformedPacket ? transformedPacket.id : null)
|
|
178
|
+
return addToPacket(packetsO, transformedPacketName, transformedPacket)
|
|
179
|
+
}, initialState())
|
|
180
|
+
return stateO
|
|
181
|
+
}, {})
|
|
182
|
+
return transformedProtocol
|
|
183
|
+
}, {})
|
|
184
|
+
transformedProtocol = reorder(['handshaking', 'status', 'login', 'play'], transformedProtocol)
|
|
185
|
+
cb(null, transformedProtocol)
|
|
142
186
|
}
|
|
143
187
|
|
|
144
188
|
function reorder (order, obj) {
|
|
145
|
-
return order.reduce
|
|
146
|
-
rslt[prop] = obj[prop]
|
|
147
|
-
return rslt
|
|
148
|
-
}, {})
|
|
189
|
+
return order.reduce(function (rslt, prop) {
|
|
190
|
+
rslt[prop] = obj[prop]
|
|
191
|
+
return rslt
|
|
192
|
+
}, {})
|
|
149
193
|
}
|
|
150
194
|
|
|
151
|
-
function transformPacket(packet,state,direction)
|
|
152
|
-
{
|
|
153
|
-
|
|
154
|
-
return null;
|
|
155
|
-
var transformedId=transformId(packet["id"]);
|
|
195
|
+
function transformPacket (packet, state, direction) {
|
|
196
|
+
if (!packet) { return null }
|
|
197
|
+
const transformedId = transformId(packet.id)
|
|
156
198
|
return {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function transformId(id)
|
|
163
|
-
{
|
|
164
|
-
return id ? id.toLowerCase() : null;
|
|
199
|
+
id: transformedId,
|
|
200
|
+
fields: packet.fields ? packet.fields.map(function (field) { return transformField(field, state, direction, transformedId) }) : null
|
|
201
|
+
}
|
|
165
202
|
}
|
|
166
203
|
|
|
167
|
-
function
|
|
168
|
-
|
|
169
|
-
return field ? {
|
|
170
|
-
"name":transformFieldName(field["name"],state,direction,id),
|
|
171
|
-
"type":transformFieldType(field["type"])
|
|
172
|
-
} : null;
|
|
204
|
+
function transformId (id) {
|
|
205
|
+
return id ? id.toLowerCase() : null
|
|
173
206
|
}
|
|
174
207
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
{
|
|
178
|
-
|
|
208
|
+
function transformField (field, state, direction, id) {
|
|
209
|
+
return field
|
|
210
|
+
? {
|
|
211
|
+
name: transformFieldName(field.name, state, direction, id),
|
|
212
|
+
type: transformFieldType(field.type)
|
|
213
|
+
}
|
|
214
|
+
: null
|
|
179
215
|
}
|
|
180
216
|
|
|
181
|
-
function
|
|
182
|
-
|
|
183
|
-
if(direction=="Serverbound") return "toServer";
|
|
184
|
-
if(direction=="Clientbound") return "toClient";
|
|
217
|
+
function transformState (state) {
|
|
218
|
+
return state.toLowerCase()
|
|
185
219
|
}
|
|
186
220
|
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
|
|
221
|
+
function transformDirection (direction) {
|
|
222
|
+
if (direction === 'Serverbound') return 'toServer'
|
|
223
|
+
if (direction === 'Clientbound') return 'toClient'
|
|
190
224
|
}
|
|
191
225
|
|
|
192
|
-
function toCamelCase(name)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
words[
|
|
196
|
-
|
|
197
|
-
return words.join("");
|
|
226
|
+
function toCamelCase (name) {
|
|
227
|
+
const words = name.split(' ')
|
|
228
|
+
words[0] = words[0].toLowerCase()
|
|
229
|
+
for (let i = 1; i < words.length; i++) words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase()
|
|
230
|
+
return words.join('')
|
|
198
231
|
}
|
|
199
232
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
"toClient": {
|
|
217
|
-
"0x01":"encryption_begin",
|
|
218
|
-
"0x02":"success",
|
|
219
|
-
"0x03":"compress"
|
|
220
|
-
},
|
|
221
|
-
"toServer": {
|
|
222
|
-
"0x01":"encryption_begin"
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
"play": {
|
|
226
|
-
"toClient":{
|
|
227
|
-
"0x01":"login",
|
|
228
|
-
"0x02":"chat",
|
|
229
|
-
"0x03":"update_time",
|
|
230
|
-
"0x08":"position",
|
|
231
|
-
"0x09":"held_item_slot",
|
|
232
|
-
"0x0a":"bed",
|
|
233
|
-
"0x0c":"named_entity_spawn",
|
|
234
|
-
"0x0d":"collect",
|
|
235
|
-
"0x0e":"spawn_entity",
|
|
236
|
-
"0x0f":"spawn_entity_living",
|
|
237
|
-
"0x10":"spawn_entity_painting",
|
|
238
|
-
"0x11":"spawn_entity_experience_orb",
|
|
239
|
-
"0x13":"entity_destroy",
|
|
240
|
-
"0x15":"rel_entity_move",
|
|
241
|
-
"0x17":"entity_move_look",
|
|
242
|
-
"0x19":"entity_head_rotation",
|
|
243
|
-
"0x1f":"experience",
|
|
244
|
-
"0x20":"update_attributes",
|
|
245
|
-
"0x21":"map_chunk",
|
|
246
|
-
"0x28":"world_event",
|
|
247
|
-
"0x29":"named_sound_effect",
|
|
248
|
-
"0x2a":"world_particles",
|
|
249
|
-
"0x2b":"game_state_change",
|
|
250
|
-
"0x2c":"spawn_entity_weather",
|
|
251
|
-
"0x31":"craft_progress_bar",
|
|
252
|
-
"0x32":"transaction",
|
|
253
|
-
"0x34":"map",
|
|
254
|
-
"0x35":"tile_entity_data",
|
|
255
|
-
"0x36":"open_sign_entity",
|
|
256
|
-
"0x38":"player_info",
|
|
257
|
-
"0x39":"abilities",
|
|
258
|
-
"0x3a":"tab_complete",
|
|
259
|
-
"0x3c":"scoreboard_score",
|
|
260
|
-
"0x3d":"scoreboard_display_objective",
|
|
261
|
-
"0x3e":"scoreboard_team",
|
|
262
|
-
"0x3f":"custom_payload",
|
|
263
|
-
"0x40":"kick_disconnect",
|
|
264
|
-
"0x41":"difficulty",
|
|
265
|
-
"0x47":"playerlist_header"
|
|
266
|
-
},
|
|
267
|
-
"toServer": {
|
|
268
|
-
"0x01":"chat",
|
|
269
|
-
"0x03":"flying",
|
|
270
|
-
"0x04":"position",
|
|
271
|
-
"0x05":"look",
|
|
272
|
-
"0x06":"position_look",
|
|
273
|
-
"0x07":"block_dig",
|
|
274
|
-
"0x08":"block_place",
|
|
275
|
-
"0x09":"held_item_slot",
|
|
276
|
-
"0x0a":"arm_animation",
|
|
277
|
-
"0x0e":"window_click",
|
|
278
|
-
"0x0f":"transaction",
|
|
279
|
-
"0x10":"set_creative_slot",
|
|
280
|
-
"0x13":"abilities",
|
|
281
|
-
"0x14":"tab_complete",
|
|
282
|
-
"0x15":"settings",
|
|
283
|
-
"0x16":"client_command",
|
|
284
|
-
"0x17":"custom_payload",
|
|
285
|
-
"0x19":"resource_pack_receive"
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
function toOldNames(name,state,direction,id)
|
|
291
|
-
{
|
|
292
|
-
return oldNames[state] && oldNames[state][direction] && oldNames[state][direction][id] ? oldNames[state][direction][id] : name;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function transformPacketName(packetName,state,direction,id)
|
|
296
|
-
{
|
|
297
|
-
return toOldNames(toSnakeCase(packetName),state,direction,id);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function transformFieldType(fieldType)
|
|
301
|
-
{
|
|
302
|
-
fieldType=fieldType.toLowerCase().replace("unsigned ","u").replace("boolean","bool").replace("[[chat]]","string")
|
|
303
|
-
.replace("angle","byte").replace("uuid","UUID");
|
|
304
|
-
if(fieldType.indexOf("slot")!=-1) return "slot";
|
|
305
|
-
if(fieldType.indexOf("entity metadata")!=-1) return "entityMetadata";
|
|
306
|
-
if(fieldType.indexOf("nbt")!=-1) return "restBuffer";
|
|
307
|
-
return fieldType;
|
|
233
|
+
function transformFieldType (fieldType) {
|
|
234
|
+
fieldType = fieldType.toLowerCase().replace('unsigned ', 'u').replace('boolean', 'bool').replace('[[chat]]', 'string')
|
|
235
|
+
.replace('angle', 'byte').replace('uuid', 'UUID')
|
|
236
|
+
if (fieldType.indexOf('varint') !== -1) return 'varint'
|
|
237
|
+
if (fieldType.indexOf('slot') !== -1) return 'slot'
|
|
238
|
+
if (fieldType.indexOf('entity metadata') !== -1) return 'entityMetadata'
|
|
239
|
+
if (fieldType.indexOf('nbt') !== -1) return 'restBuffer'
|
|
240
|
+
if (fieldType.indexOf('ubyte') !== -1) return 'u8'
|
|
241
|
+
if (fieldType.indexOf('byte') !== -1) return 'i8'
|
|
242
|
+
if (fieldType.indexOf('ushort') !== -1) return 'u16'
|
|
243
|
+
if (fieldType.indexOf('short') !== -1) return 'i16'
|
|
244
|
+
if (fieldType.indexOf('uint') !== -1) return 'u32'
|
|
245
|
+
if (fieldType.indexOf('int') !== -1) return 'i32'
|
|
246
|
+
if (fieldType.indexOf('ulong') !== -1) return 'u64'
|
|
247
|
+
if (fieldType.indexOf('long') !== -1) return 'i64'
|
|
248
|
+
return fieldType
|
|
308
249
|
}
|
|
309
250
|
|
|
310
251
|
// specific has priority over general
|
|
311
252
|
|
|
312
253
|
// specific
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
254
|
+
const newToOldFieldNamesSpecific = {
|
|
255
|
+
status: {
|
|
256
|
+
toClient: {
|
|
257
|
+
'0x01': {
|
|
258
|
+
payload: 'time'
|
|
318
259
|
}
|
|
319
260
|
},
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
261
|
+
toServer: {
|
|
262
|
+
'0x01': {
|
|
263
|
+
payload: 'time'
|
|
323
264
|
}
|
|
324
265
|
}
|
|
325
266
|
},
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
267
|
+
login: {
|
|
268
|
+
toServer: {
|
|
269
|
+
'0x00': {
|
|
270
|
+
name: 'username'
|
|
330
271
|
}
|
|
331
272
|
}
|
|
332
273
|
},
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
274
|
+
play: {
|
|
275
|
+
toClient: {
|
|
276
|
+
'0x01': {
|
|
277
|
+
gamemode: 'gameMode'
|
|
337
278
|
},
|
|
338
|
-
|
|
339
|
-
|
|
279
|
+
'0x0e': {
|
|
280
|
+
data: 'objectData'
|
|
340
281
|
},
|
|
341
|
-
|
|
342
|
-
|
|
282
|
+
'0x21': {
|
|
283
|
+
data: 'chunkData'
|
|
343
284
|
},
|
|
344
|
-
|
|
345
|
-
|
|
285
|
+
'0x2b': {
|
|
286
|
+
value: 'gameMode'
|
|
346
287
|
},
|
|
347
|
-
|
|
348
|
-
|
|
288
|
+
'0x2f': {
|
|
289
|
+
slotData: 'item'
|
|
349
290
|
},
|
|
350
|
-
|
|
351
|
-
|
|
291
|
+
'0x30': {
|
|
292
|
+
slotData: 'items'
|
|
352
293
|
},
|
|
353
|
-
|
|
354
|
-
|
|
294
|
+
'0x32': {
|
|
295
|
+
actionNumber: 'action'
|
|
355
296
|
},
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
297
|
+
'0x3b': {
|
|
298
|
+
mode: 'action',
|
|
299
|
+
objectiveName: 'name'
|
|
359
300
|
},
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
301
|
+
'0x3c': {
|
|
302
|
+
scoreName: 'itemName',
|
|
303
|
+
objectiveName: 'scoreName'
|
|
363
304
|
},
|
|
364
|
-
|
|
365
|
-
|
|
305
|
+
'0x3d': {
|
|
306
|
+
scoreName: 'name'
|
|
366
307
|
}
|
|
367
308
|
},
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
309
|
+
toServer: {
|
|
310
|
+
'0x02': {
|
|
311
|
+
type: 'mouse'
|
|
371
312
|
},
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
313
|
+
'0x08': {
|
|
314
|
+
face: 'direction',
|
|
315
|
+
cursorPositionX: 'cursorX',
|
|
316
|
+
cursorPositionY: 'cursorY',
|
|
317
|
+
cursorPositionZ: 'cursorZ'
|
|
377
318
|
},
|
|
378
|
-
|
|
379
|
-
|
|
319
|
+
'0x09': {
|
|
320
|
+
slot: 'slotId'
|
|
380
321
|
},
|
|
381
|
-
|
|
382
|
-
|
|
322
|
+
'0x0b': {
|
|
323
|
+
payload: 'actionId'
|
|
383
324
|
},
|
|
384
|
-
|
|
385
|
-
|
|
325
|
+
'0x0c': {
|
|
326
|
+
flags: 'jump'
|
|
386
327
|
},
|
|
387
|
-
|
|
388
|
-
|
|
328
|
+
'0x0e': {
|
|
329
|
+
actionNumber: 'action'
|
|
389
330
|
},
|
|
390
|
-
|
|
391
|
-
|
|
331
|
+
'0x0f': {
|
|
332
|
+
actionNumber: 'action'
|
|
392
333
|
},
|
|
393
|
-
|
|
394
|
-
|
|
334
|
+
'0x16': {
|
|
335
|
+
actionId: 'payload'
|
|
395
336
|
}
|
|
396
337
|
}
|
|
397
338
|
}
|
|
398
|
-
}
|
|
339
|
+
}
|
|
399
340
|
|
|
400
341
|
// should probably be converted entirely in the specific format
|
|
401
342
|
// general
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
function toOldFieldName(fieldName,state,direction,id)
|
|
450
|
-
{
|
|
451
|
-
if(newToOldFieldNamesSpecific[state]
|
|
452
|
-
&& newToOldFieldNamesSpecific[state][direction]
|
|
453
|
-
&& newToOldFieldNamesSpecific[state][direction][id]
|
|
454
|
-
&& newToOldFieldNamesSpecific[state][direction][id][fieldName])
|
|
455
|
-
return newToOldFieldNamesSpecific[state][direction][id][fieldName];
|
|
456
|
-
if(newToOldFieldNamesGeneral[fieldName])
|
|
457
|
-
return newToOldFieldNamesGeneral[fieldName];
|
|
458
|
-
return fieldName;
|
|
343
|
+
const newToOldFieldNamesGeneral = {
|
|
344
|
+
serverAddress: 'serverHost',
|
|
345
|
+
jsonResponse: 'response',
|
|
346
|
+
jsonData: 'message',
|
|
347
|
+
worldAge: 'age',
|
|
348
|
+
timeOfDay: 'time',
|
|
349
|
+
playerUuid: 'playerUUID',
|
|
350
|
+
deltaX: 'dX',
|
|
351
|
+
deltaY: 'dY',
|
|
352
|
+
deltaZ: 'dZ',
|
|
353
|
+
chunkX: 'x',
|
|
354
|
+
chunkZ: 'z',
|
|
355
|
+
'ground-upContinuous': 'groundUp',
|
|
356
|
+
primaryBitMask: 'bitMap',
|
|
357
|
+
size: 'chunkDataLength',
|
|
358
|
+
blockId: 'type',
|
|
359
|
+
blockType: 'blockId',
|
|
360
|
+
recordCount: 'count',
|
|
361
|
+
records: 'affectedBlockOffsets',
|
|
362
|
+
disableRelativeVolume: 'global',
|
|
363
|
+
effectPositionX: 'x',
|
|
364
|
+
effectPositionY: 'y',
|
|
365
|
+
effectPositionZ: 'z',
|
|
366
|
+
particleCount: 'particles',
|
|
367
|
+
windowType: 'inventoryType',
|
|
368
|
+
numberOfSlots: 'slotCount',
|
|
369
|
+
line1: 'text1',
|
|
370
|
+
line2: 'text2',
|
|
371
|
+
line3: 'text3',
|
|
372
|
+
line4: 'text4',
|
|
373
|
+
objectiveValue: 'displayText',
|
|
374
|
+
teamName: 'team',
|
|
375
|
+
teamDisplayName: 'name',
|
|
376
|
+
teamPrefix: 'prefix',
|
|
377
|
+
teamSuffix: 'suffix',
|
|
378
|
+
targetX: 'x',
|
|
379
|
+
targetY: 'y',
|
|
380
|
+
targetZ: 'z',
|
|
381
|
+
feetY: 'y',
|
|
382
|
+
button: 'mouseButton',
|
|
383
|
+
clickedItem: 'item',
|
|
384
|
+
lookedAtBlock: 'block',
|
|
385
|
+
chatMode: 'chatFlags',
|
|
386
|
+
displayedSkinParts: 'skinParts',
|
|
387
|
+
targetPlayer: 'target'
|
|
459
388
|
}
|
|
460
389
|
|
|
461
|
-
function
|
|
462
|
-
|
|
463
|
-
|
|
390
|
+
function toOldFieldName (fieldName, state, direction, id) {
|
|
391
|
+
if (newToOldFieldNamesSpecific[state] &&
|
|
392
|
+
newToOldFieldNamesSpecific[state][direction] &&
|
|
393
|
+
newToOldFieldNamesSpecific[state][direction][id] &&
|
|
394
|
+
newToOldFieldNamesSpecific[state][direction][id][fieldName]) { return newToOldFieldNamesSpecific[state][direction][id][fieldName] }
|
|
395
|
+
if (newToOldFieldNamesGeneral[fieldName]) { return newToOldFieldNamesGeneral[fieldName] }
|
|
396
|
+
return fieldName
|
|
464
397
|
}
|
|
465
398
|
|
|
399
|
+
function transformFieldName (fieldName, state, direction, id) {
|
|
400
|
+
return toOldFieldName(toCamelCase(fieldName), state, direction, id)
|
|
401
|
+
}
|