@@ -80,7 +80,7 @@ public Protocol18Handler(TcpClient Client, int protocolVersion, IMinecraftComHan
80
80
this . pTerrain = new Protocol18Terrain ( protocolVersion , dataTypes , handler ) ;
81
81
this . packetPalette = new PacketTypeHandler ( protocolVersion ) . GetTypeHandler ( ) ;
82
82
83
- if ( handler . GetTerrainEnabled ( ) && protocolversion > MC1152Version )
83
+ if ( handler . GetTerrainEnabled ( ) && protocolversion > MC1164Version )
84
84
{
85
85
Translations . WriteLineFormatted ( "extra.terrainandmovement_disabled" ) ;
86
86
handler . SetTerrainEnabled ( false ) ;
@@ -101,9 +101,11 @@ public Protocol18Handler(TcpClient Client, int protocolVersion, IMinecraftComHan
101
101
// Block palette
102
102
if ( protocolversion >= MC113Version )
103
103
{
104
- if ( protocolVersion > MC1152Version && handler . GetTerrainEnabled ( ) )
104
+ if ( protocolVersion > MC1164Version && handler . GetTerrainEnabled ( ) )
105
105
throw new NotImplementedException ( Translations . Get ( "exception.palette.block" ) ) ;
106
- if ( protocolVersion >= MC115Version )
106
+ if ( protocolVersion >= MC116Version )
107
+ Block . Palette = new Palette116 ( ) ;
108
+ else if ( protocolVersion >= MC115Version )
107
109
Block . Palette = new Palette115 ( ) ;
108
110
else if ( protocolVersion >= MC114Version )
109
111
Block . Palette = new Palette114 ( ) ;
@@ -398,6 +400,8 @@ internal bool HandlePacket(int packetID, Queue<byte> packetData)
398
400
int chunkX = dataTypes . ReadNextInt ( packetData ) ;
399
401
int chunkZ = dataTypes . ReadNextInt ( packetData ) ;
400
402
bool chunksContinuous = dataTypes . ReadNextBool ( packetData ) ;
403
+ if ( protocolversion >= MC116Version && protocolversion <= MC1161Version )
404
+ dataTypes . ReadNextBool ( packetData ) ; // Ignore old data - 1.16 to 1.16.1 only
401
405
ushort chunkMask = protocolversion >= MC19Version
402
406
? ( ushort ) dataTypes . ReadNextVarInt ( packetData )
403
407
: dataTypes . ReadNextUShort ( packetData ) ;
@@ -413,8 +417,23 @@ internal bool HandlePacket(int packetID, Queue<byte> packetData)
413
417
{
414
418
if ( protocolversion >= MC114Version )
415
419
dataTypes . ReadNextNbt ( packetData ) ; // Heightmaps - 1.14 and above
420
+ int biomesLength = 0 ;
421
+ if ( protocolversion >= MC1162Version )
422
+ if ( chunksContinuous )
423
+ biomesLength = dataTypes . ReadNextVarInt ( packetData ) ; // Biomes length - 1.16.2 and above
416
424
if ( protocolversion >= MC115Version && chunksContinuous )
417
- dataTypes . ReadData ( 1024 * 4 , packetData ) ; // Biomes - 1.15 and above
425
+ {
426
+ if ( protocolversion >= MC1162Version )
427
+ {
428
+ for ( int i = 0 ; i < biomesLength ; i ++ )
429
+ {
430
+ // Biomes - 1.16.2 and above
431
+ // Don't use ReadNextVarInt because it cost too much time
432
+ dataTypes . SkipNextVarInt ( packetData ) ;
433
+ }
434
+ }
435
+ else dataTypes . ReadData ( 1024 * 4 , packetData ) ; // Biomes - 1.15 and above
436
+ }
418
437
int dataSize = dataTypes . ReadNextVarInt ( packetData ) ;
419
438
pTerrain . ProcessChunkColumnData ( chunkX , chunkZ , chunkMask , 0 , false , chunksContinuous , currentDimension , packetData ) ;
420
439
}
@@ -514,35 +533,62 @@ internal bool HandlePacket(int packetID, Queue<byte> packetData)
514
533
case PacketTypesIn . MultiBlockChange :
515
534
if ( handler . GetTerrainEnabled ( ) )
516
535
{
517
- int chunkX = dataTypes . ReadNextInt ( packetData ) ;
518
- int chunkZ = dataTypes . ReadNextInt ( packetData ) ;
519
- int recordCount = protocolversion < MC18Version
520
- ? ( int ) dataTypes . ReadNextShort ( packetData )
521
- : dataTypes . ReadNextVarInt ( packetData ) ;
522
-
523
- for ( int i = 0 ; i < recordCount ; i ++ )
536
+ if ( protocolversion >= MC1162Version )
524
537
{
525
- byte locationXZ ;
526
- ushort blockIdMeta ;
527
- int blockY ;
528
-
529
- if ( protocolversion < MC18Version )
538
+ long chunkSection = dataTypes . ReadNextLong ( packetData ) ;
539
+ int sectionX = ( int ) ( chunkSection >> 42 ) ;
540
+ int sectionY = ( int ) ( ( chunkSection << 44 ) >> 44 ) ;
541
+ int sectionZ = ( int ) ( ( chunkSection << 22 ) >> 42 ) ;
542
+ dataTypes . ReadNextBool ( packetData ) ; // Useless boolean
543
+ int blocksSize = dataTypes . ReadNextVarInt ( packetData ) ;
544
+ for ( int i = 0 ; i < blocksSize ; i ++ )
530
545
{
531
- blockIdMeta = dataTypes . ReadNextUShort ( packetData ) ;
532
- blockY = ( ushort ) dataTypes . ReadNextByte ( packetData ) ;
533
- locationXZ = dataTypes . ReadNextByte ( packetData ) ;
546
+ ulong block = ( ulong ) dataTypes . ReadNextVarLong ( packetData ) ;
547
+ int blockId = ( int ) ( block >> 12 ) ;
548
+ int localX = ( int ) ( ( block >> 8 ) & 0x0F ) ;
549
+ int localZ = ( int ) ( ( block >> 4 ) & 0x0F ) ;
550
+ int localY = ( int ) ( block & 0x0F ) ;
551
+
552
+ Block b = new Block ( ( ushort ) blockId ) ;
553
+ int blockX = ( sectionX * 16 ) + localX ;
554
+ int blockY = ( sectionY * 16 ) + localY ;
555
+ int blockZ = ( sectionZ * 16 ) + localZ ;
556
+ var l = new Location ( blockX , blockY , blockZ ) ;
557
+ handler . GetWorld ( ) . SetBlock ( l , b ) ;
534
558
}
535
- else
559
+ }
560
+ else
561
+ {
562
+ int chunkX = dataTypes . ReadNextInt ( packetData ) ;
563
+ int chunkZ = dataTypes . ReadNextInt ( packetData ) ;
564
+ int recordCount = protocolversion < MC18Version
565
+ ? ( int ) dataTypes . ReadNextShort ( packetData )
566
+ : dataTypes . ReadNextVarInt ( packetData ) ;
567
+
568
+ for ( int i = 0 ; i < recordCount ; i ++ )
536
569
{
537
- locationXZ = dataTypes . ReadNextByte ( packetData ) ;
538
- blockY = ( ushort ) dataTypes . ReadNextByte ( packetData ) ;
539
- blockIdMeta = ( ushort ) dataTypes . ReadNextVarInt ( packetData ) ;
540
- }
570
+ byte locationXZ ;
571
+ ushort blockIdMeta ;
572
+ int blockY ;
541
573
542
- int blockX = locationXZ >> 4 ;
543
- int blockZ = locationXZ & 0x0F ;
544
- Block block = new Block ( blockIdMeta ) ;
545
- handler . GetWorld ( ) . SetBlock ( new Location ( chunkX , chunkZ , blockX , blockY , blockZ ) , block ) ;
574
+ if ( protocolversion < MC18Version )
575
+ {
576
+ blockIdMeta = dataTypes . ReadNextUShort ( packetData ) ;
577
+ blockY = ( ushort ) dataTypes . ReadNextByte ( packetData ) ;
578
+ locationXZ = dataTypes . ReadNextByte ( packetData ) ;
579
+ }
580
+ else
581
+ {
582
+ locationXZ = dataTypes . ReadNextByte ( packetData ) ;
583
+ blockY = ( ushort ) dataTypes . ReadNextByte ( packetData ) ;
584
+ blockIdMeta = ( ushort ) dataTypes . ReadNextVarInt ( packetData ) ;
585
+ }
586
+
587
+ int blockX = locationXZ >> 4 ;
588
+ int blockZ = locationXZ & 0x0F ;
589
+ Block block = new Block ( blockIdMeta ) ;
590
+ handler . GetWorld ( ) . SetBlock ( new Location ( chunkX , chunkZ , blockX , blockY , blockZ ) , block ) ;
591
+ }
546
592
}
547
593
}
548
594
break ;
0 commit comments