11'use strict'
22
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' )
64const { ProtoDefCompiler } = require ( 'protodef' ) . Compiler
75
86const nbt = require ( 'prismarine-nbt' )
97const minecraft = require ( '../datatypes/minecraft' )
108const states = require ( '../states' )
119const merge = require ( 'lodash.merge' )
12- const get = require ( 'lodash.get' )
1310
1411const minecraftData = require ( 'minecraft-data' )
1512const protocols = { }
1613
1714function createProtocol ( state , direction , version , customPackets , compiled = true ) {
18- const key = state + ';' + direction + ';' + version + ( compiled ? ';c' : '' )
15+ const key = ` ${ state } ; ${ direction } ; ${ version } ${ compiled ? ';c' : '' } `
1916 if ( protocols [ key ] ) { return protocols [ key ] }
2017
2118 const mcData = minecraftData ( version )
@@ -27,10 +24,12 @@ function createProtocol (state, direction, version, customPackets, compiled = tr
2724 throw new Error ( `Unsupported protocol version '${ versionInfo . version } ' (attempted to use '${ mcData . version . version } ' data); try updating your packages with 'npm update'` )
2825 }
2926
27+ const mergedProtocol = merge ( mcData . protocol , customPackets ?. [ mcData . version . majorVersion ] ?? { } )
28+
3029 if ( compiled ) {
3130 const compiler = new ProtoDefCompiler ( )
3231 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 ] )
3433 nbt . addTypesToCompiler ( 'big' , compiler )
3534 const proto = compiler . compileProtoDefSync ( )
3635 protocols [ key ] = proto
@@ -39,7 +38,7 @@ function createProtocol (state, direction, version, customPackets, compiled = tr
3938
4039 const proto = new ProtoDef ( false )
4140 proto . addTypes ( minecraft )
42- proto . addProtocol ( merge ( mcData . protocol , get ( customPackets , [ mcData . version . majorVersion ] ) ) , [ state , direction ] )
41+ proto . addProtocol ( mergedProtocol , [ state , direction ] )
4342 nbt . addTypesToInterperter ( 'big' , proto )
4443 protocols [ key ] = proto
4544 return proto
@@ -50,7 +49,7 @@ function createSerializer ({ state = states.HANDSHAKING, isServer = false, versi
5049}
5150
5251function 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 )
5453}
5554
5655module . exports = {
0 commit comments