1
1
'use strict'
2
2
3
- const ProtoDef = require ( 'protodef' ) . ProtoDef
4
- const Serializer = require ( 'protodef' ) . Serializer
5
- const Parser = require ( 'protodef' ) . FullPacketParser
3
+ const { ProtoDef, Serializer, FullPacketParser } = require ( 'protodef' )
6
4
const { ProtoDefCompiler } = require ( 'protodef' ) . Compiler
7
5
8
6
const nbt = require ( 'prismarine-nbt' )
9
7
const minecraft = require ( '../datatypes/minecraft' )
10
8
const states = require ( '../states' )
11
9
const merge = require ( 'lodash.merge' )
12
- const get = require ( 'lodash.get' )
13
10
14
11
const minecraftData = require ( 'minecraft-data' )
15
12
const protocols = { }
16
13
17
14
function createProtocol ( state , direction , version , customPackets , compiled = true ) {
18
- const key = state + ';' + direction + ';' + version + ( compiled ? ';c' : '' )
15
+ const key = ` ${ state } ; ${ direction } ; ${ version } ${ compiled ? ';c' : '' } `
19
16
if ( protocols [ key ] ) { return protocols [ key ] }
20
17
21
18
const mcData = minecraftData ( version )
@@ -27,10 +24,12 @@ function createProtocol (state, direction, version, customPackets, compiled = tr
27
24
throw new Error ( `Unsupported protocol version '${ versionInfo . version } ' (attempted to use '${ mcData . version . version } ' data); try updating your packages with 'npm update'` )
28
25
}
29
26
27
+ const mergedProtocol = merge ( mcData . protocol , customPackets ?. [ mcData . version . majorVersion ] ?? { } )
28
+
30
29
if ( compiled ) {
31
30
const compiler = new ProtoDefCompiler ( )
32
31
compiler . addTypes ( require ( '../datatypes/compiler-minecraft' ) )
33
- compiler . addProtocol ( merge ( mcData . protocol , get ( customPackets , [ mcData . version . majorVersion ] ) ) , [ state , direction ] )
32
+ compiler . addProtocol ( mergedProtocol , [ state , direction ] )
34
33
nbt . addTypesToCompiler ( 'big' , compiler )
35
34
const proto = compiler . compileProtoDefSync ( )
36
35
protocols [ key ] = proto
@@ -39,7 +38,7 @@ function createProtocol (state, direction, version, customPackets, compiled = tr
39
38
40
39
const proto = new ProtoDef ( false )
41
40
proto . addTypes ( minecraft )
42
- proto . addProtocol ( merge ( mcData . protocol , get ( customPackets , [ mcData . version . majorVersion ] ) ) , [ state , direction ] )
41
+ proto . addProtocol ( mergedProtocol , [ state , direction ] )
43
42
nbt . addTypesToInterperter ( 'big' , proto )
44
43
protocols [ key ] = proto
45
44
return proto
@@ -50,7 +49,7 @@ function createSerializer ({ state = states.HANDSHAKING, isServer = false, versi
50
49
}
51
50
52
51
function createDeserializer ( { state = states . HANDSHAKING , isServer = false , version, customPackets, compiled = true , noErrorLogging = false } = { } ) {
53
- return new Parser ( createProtocol ( state , isServer ? 'toServer' : 'toClient' , version , customPackets , compiled ) , 'packet' , noErrorLogging )
52
+ return new FullPacketParser ( createProtocol ( state , isServer ? 'toServer' : 'toClient' , version , customPackets , compiled ) , 'packet' , noErrorLogging )
54
53
}
55
54
56
55
module . exports = {
0 commit comments