1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
|
// Protocol_1_13.cpp
/*
Implements the 1.13 protocol classes:
- release 1.13 protocol (#393)
- release 1.13.1 protocol (#401)
- release 1.13.2 protocol (#404)
*/
#include "Globals.h"
#include "Protocol_1_13.h"
#include "../Entities/Boat.h"
#include "../Entities/EnderCrystal.h"
#include "../Entities/Minecart.h"
#include "../Entities/Pickup.h"
#include "../Entities/Player.h"
#include "../Entities/ItemFrame.h"
#include "../Entities/ArrowEntity.h"
#include "../Entities/FireworkEntity.h"
#include "../Entities/SplashPotionEntity.h"
#include "../Mobs/IncludeAllMonsters.h"
#include "../CompositeChat.h"
#include "../ClientHandle.h"
#include "../Root.h"
#include "../Server.h"
#include "../World.h"
#include "../JsonUtils.h"
#include "../WorldStorage/FastNBT.h"
#include "WorldStorage/NamespaceSerializer.h"
#include "../Bindings/PluginManager.h"
#include "Palettes/Palette_1_13.h"
#include "Palettes/Palette_1_13_1.h"
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
do { \
if (!ByteBuf.Proc(Var))\
{\
return;\
} \
} while (false)
#define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
do { \
{ \
if (!ByteBuf.Proc(Var)) \
{ \
ByteBuf.CheckValid(); \
return false; \
} \
ByteBuf.CheckValid(); \
} \
} while (false)
////////////////////////////////////////////////////////////////////////////////
// cProtocol_1_13:
void cProtocol_1_13::SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cPacketizer Pkt(*this, pktBlockChange);
Pkt.WriteXYZPosition64(a_BlockPos);
Pkt.WriteVarInt32(GetProtocolBlockType(a_BlockType, a_BlockMeta));
}
void cProtocol_1_13::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, pktBlockChanges);
Pkt.WriteBEInt32(a_ChunkX);
Pkt.WriteBEInt32(a_ChunkZ);
Pkt.WriteVarInt32(static_cast<UInt32>(a_Changes.size()));
for (const auto & Change : a_Changes)
{
Int16 Coords = static_cast<Int16>(Change.m_RelY | (Change.m_RelZ << 8) | (Change.m_RelX << 12));
Pkt.WriteBEInt16(Coords);
Pkt.WriteVarInt32(GetProtocolBlockType(Change.m_BlockType, Change.m_BlockMeta));
}
}
void cProtocol_1_13::SendMapData(const cMap & a_Map, int a_DataStartX, int a_DataStartY)
{
// TODO
}
void cProtocol_1_13::SendPaintingSpawn(const cPainting & a_Painting)
{
// TODO
}
void cProtocol_1_13::SendParticleEffect(const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data)
{
// This packet is unchanged since 1.8
// However we are hardcoding a string-to-id mapping inside there
// TODO: make a virtual enum-to-id mapping
}
void cProtocol_1_13::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode)
{
// TODO
}
void cProtocol_1_13::SendStatistics(const StatisticsManager & a_Manager)
{
ASSERT(m_State == 3); // In game mode?
UInt32 Size = 0;
for (const auto & [Statistic, Value] : a_Manager.Custom)
{
// Client balks at out-of-range values so there is no good default value.
// We're forced to not send the statistics this protocol version doesn't support.
if (GetProtocolStatisticType(Statistic) != static_cast<UInt32>(-1))
{
Size++;
}
}
// No need to check Size != 0
// Assume that the vast majority of the time there's at least one statistic to send
cPacketizer Pkt(*this, pktStatistics);
Pkt.WriteVarInt32(Size);
for (const auto & [Statistic, Value] : a_Manager.Custom)
{
const auto ID = GetProtocolStatisticType(Statistic);
if (ID == static_cast<UInt32>(-1))
{
// Unsupported, don't send:
continue;
}
Pkt.WriteVarInt32(8); // "Custom" category.
Pkt.WriteVarInt32(ID);
Pkt.WriteVarInt32(static_cast<UInt32>(Value));
}
}
void cProtocol_1_13::SendTabCompletionResults(const AStringVector & a_Results)
{
// TODO
}
void cProtocol_1_13::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
{
ASSERT(m_State == 3); // In game mode?
Byte Action;
switch (a_BlockEntity.GetBlockType())
{
case E_BLOCK_CHEST:
case E_BLOCK_ENCHANTMENT_TABLE:
case E_BLOCK_END_PORTAL:
case E_BLOCK_TRAPPED_CHEST:
{
// The ones with a action of 0 is just a workaround to send the block entities to a client.
// Todo: 18.09.2020 - remove this when block entities are transmitted in the ChunkData packet - 12xx12
Action = 0;
break;
}
case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing
case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text
case E_BLOCK_BEACON: Action = 3; break; // Update beacon entity
case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity
// case E_BLOCK_CONDUIT: Action = 5; break; // Update Conduit entity
case E_BLOCK_STANDING_BANNER:
case E_BLOCK_WALL_BANNER: Action = 6; break; // Update banner entity
// case Structure Block: Action = 7; break; // Update Structure tile entity
case E_BLOCK_END_GATEWAY: Action = 8; break; // Update destination for a end gateway entity
case E_BLOCK_SIGN_POST: Action = 9; break; // Update sign entity
// case E_BLOCK_SHULKER_BOX: Action = 10; break; // sets shulker box - not used just here if anyone is confused from reading the protocol wiki
case E_BLOCK_BED: Action = 11; break; // Update bed color
default: return; // Block entities change between versions
}
cPacketizer Pkt(*this, pktUpdateBlockEntity);
Pkt.WriteXYZPosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ());
Pkt.WriteBEUInt8(Action);
cFastNBTWriter Writer;
WriteBlockEntity(Writer, a_BlockEntity);
Writer.Finish();
Pkt.WriteBuf(Writer.GetResult());
}
UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadata a_Metadata) const
{
const UInt8 Entity = 6;
const UInt8 Living = Entity + 5;
const UInt8 Insentient = Living + 1;
const UInt8 Ageable = Insentient + 1;
const UInt8 AbstractHorse = Ageable + 2;
const UInt8 ChestedHorse = AbstractHorse + 1;
const UInt8 TameableAnimal = Ageable + 2;
const UInt8 Minecart = Entity + 6;
switch (a_Metadata)
{
case EntityMetadata::EntityFlags: return 0;
case EntityMetadata::EntityAir: return 1;
case EntityMetadata::EntityCustomName: return 2;
case EntityMetadata::EntityCustomNameVisible: return 3;
case EntityMetadata::EntitySilent: return 4;
case EntityMetadata::EntityNoGravity: return 5;
case EntityMetadata::PotionThrown: return Entity;
case EntityMetadata::FallingBlockPosition: return Entity;
case EntityMetadata::AreaEffectCloudRadius: return Entity;
case EntityMetadata::AreaEffectCloudColor: return Entity + 1;
case EntityMetadata::AreaEffectCloudSinglePointEffect: return Entity + 2;
case EntityMetadata::AreaEffectCloudParticleId: return Entity + 3;
case EntityMetadata::ArrowFlags: return Entity;
case EntityMetadata::TippedArrowColor: return Entity + 1;
case EntityMetadata::BoatLastHitTime: return Entity;
case EntityMetadata::BoatForwardDirection: return Entity + 1;
case EntityMetadata::BoatDamageTaken: return Entity + 2;
case EntityMetadata::BoatType: return Entity + 3;
case EntityMetadata::BoatLeftPaddleTurning: return Entity + 4;
case EntityMetadata::BoatRightPaddleTurning: return Entity + 5;
case EntityMetadata::BoatSplashTimer: return Entity + 6;
case EntityMetadata::EnderCrystalBeamTarget: return Entity;
case EntityMetadata::EnderCrystalShowBottom: return Entity + 1;
case EntityMetadata::WitherSkullInvulnerable: return Entity;
case EntityMetadata::FireworkInfo: return Entity;
case EntityMetadata::FireworkBoostedEntityId: return Entity + 1;
case EntityMetadata::ItemFrameItem: return Entity;
case EntityMetadata::ItemFrameRotation: return Entity + 1;
case EntityMetadata::ItemItem: return Entity;
case EntityMetadata::LivingActiveHand: return Entity;
case EntityMetadata::LivingHealth: return Entity + 1;
case EntityMetadata::LivingPotionEffectColor: return Entity + 2;
case EntityMetadata::LivingPotionEffectAmbient: return Entity + 3;
case EntityMetadata::LivingNumberOfArrows: return Entity + 4;
case EntityMetadata::PlayerAdditionalHearts: return Living;
case EntityMetadata::PlayerScore: return Living + 1;
case EntityMetadata::PlayerDisplayedSkinParts: return Living + 2;
case EntityMetadata::PlayerMainHand: return Living + 3;
case EntityMetadata::ArmorStandStatus: return Living;
case EntityMetadata::ArmorStandHeadRotation: return Living + 1;
case EntityMetadata::ArmorStandBodyRotation: return Living + 2;
case EntityMetadata::ArmorStandLeftArmRotation: return Living + 3;
case EntityMetadata::ArmorStandRightArmRotation: return Living + 4;
case EntityMetadata::ArmorStandLeftLegRotation: return Living + 5;
case EntityMetadata::ArmorStandRightLegRotation: return Living + 6;
case EntityMetadata::InsentientFlags: return Living;
case EntityMetadata::BatHanging: return Insentient;
case EntityMetadata::AgeableIsBaby: return Insentient;
case EntityMetadata::AbstractHorseFlags: return Ageable;
case EntityMetadata::AbstractHorseOwner: return Ageable + 1;
case EntityMetadata::HorseVariant: return AbstractHorse;
case EntityMetadata::HorseArmour: return AbstractHorse + 1;
case EntityMetadata::ChestedHorseChested: return AbstractHorse;
case EntityMetadata::LlamaStrength: return ChestedHorse;
case EntityMetadata::LlamaCarpetColor: return ChestedHorse + 1;
case EntityMetadata::LlamaVariant: return ChestedHorse + 2;
case EntityMetadata::PigHasSaddle: return Ageable;
case EntityMetadata::PigTotalCarrotOnAStickBoost: return Ageable + 1;
case EntityMetadata::RabbitType: return Ageable;
case EntityMetadata::PolarBearStanding: return Ageable;
case EntityMetadata::SheepFlags: return Ageable;
case EntityMetadata::TameableAnimalFlags: return Ageable;
case EntityMetadata::TameableAnimalOwner: return Ageable + 1;
case EntityMetadata::OcelotType: return TameableAnimal;
case EntityMetadata::WolfDamageTaken: return TameableAnimal;
case EntityMetadata::WolfBegging: return TameableAnimal + 1;
case EntityMetadata::WolfCollarColour: return TameableAnimal + 2;
case EntityMetadata::VillagerProfession: return Ageable;
case EntityMetadata::IronGolemPlayerCreated: return Insentient;
case EntityMetadata::ShulkerFacingDirection: return Insentient;
case EntityMetadata::ShulkerAttachmentFallingBlockPosition: return Insentient + 1;
case EntityMetadata::ShulkerShieldHeight: return Insentient + 2;
case EntityMetadata::BlazeOnFire: return Insentient;
case EntityMetadata::CreeperState: return Insentient;
case EntityMetadata::CreeperPowered: return Insentient + 1;
case EntityMetadata::CreeperIgnited: return Insentient + 2;
case EntityMetadata::GuardianStatus: return Insentient;
case EntityMetadata::GuardianTarget: return Insentient + 1;
case EntityMetadata::IllagerFlags: return Insentient;
case EntityMetadata::SpeIlagerSpell: return Insentient + 1;
case EntityMetadata::VexFlags: return Insentient;
case EntityMetadata::AbstractSkeletonArmsSwinging: return Insentient;
case EntityMetadata::SpiderClimbing: return Insentient;
case EntityMetadata::WitchAggresive: return Insentient;
case EntityMetadata::WitherFirstHeadTarget: return Insentient;
case EntityMetadata::WitherSecondHeadTarget: return Insentient + 1;
case EntityMetadata::WitherThirdHeadTarget: return Insentient + 2;
case EntityMetadata::WitherInvulnerableTimer: return Insentient + 3;
case EntityMetadata::ZombieIsBaby: return Insentient;
case EntityMetadata::ZombieHandsRisedUp: return Insentient + 2;
case EntityMetadata::ZombieVillagerConverting: return Insentient + 4;
case EntityMetadata::ZombieVillagerProfession: return Insentient + 5;
case EntityMetadata::EndermanCarriedBlock: return Insentient;
case EntityMetadata::EndermanScreaming: return Insentient + 1;
case EntityMetadata::EnderDragonDragonPhase: return Insentient;
case EntityMetadata::GhastAttacking: return Insentient;
case EntityMetadata::SlimeSize: return Insentient;
case EntityMetadata::MinecartShakingPower: return Entity;
case EntityMetadata::MinecartShakingDirection: return Entity + 1;
case EntityMetadata::MinecartShakingMultiplier: return Entity + 2;
case EntityMetadata::MinecartBlockIDMeta: return Entity + 3;
case EntityMetadata::MinecartBlockY: return Entity + 4;
case EntityMetadata::MinecartShowBlock: return Entity + 5;
case EntityMetadata::MinecartCommandBlockCommand: return Minecart;
case EntityMetadata::MinecartCommandBlockLastOutput: return Minecart + 1;
case EntityMetadata::MinecartFurnacePowered: return Minecart;
case EntityMetadata::TNTPrimedFuseTime: return Entity;
case EntityMetadata::EntityPose:
case EntityMetadata::AreaEffectCloudParticleParameter1:
case EntityMetadata::AreaEffectCloudParticleParameter2:
case EntityMetadata::ZombieUnusedWasType: break;
default:
break;
}
UNREACHABLE("Retrieved invalid metadata for protocol");
}
UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadataType a_FieldType) const
{
switch (a_FieldType)
{
case EntityMetadataType::Byte: return 0;
case EntityMetadataType::VarInt: return 1;
case EntityMetadataType::Float: return 2;
case EntityMetadataType::String: return 3;
case EntityMetadataType::Chat: return 4;
case EntityMetadataType::OptChat: return 5;
case EntityMetadataType::Item: return 6;
case EntityMetadataType::Boolean: return 7;
case EntityMetadataType::Rotation: return 8;
case EntityMetadataType::Position: return 9;
case EntityMetadataType::OptPosition: return 10;
case EntityMetadataType::Direction: return 11;
case EntityMetadataType::OptUUID: return 12;
case EntityMetadataType::OptBlockID: return 13;
case EntityMetadataType::NBT: return 14;
case EntityMetadataType::Particle: return 15;
case EntityMetadataType::VillagerData: return 16;
case EntityMetadataType::OptVarInt: return 17;
case EntityMetadataType::Pose: return 18;
}
UNREACHABLE("Translated invalid metadata type for protocol");
}
std::pair<short, short> cProtocol_1_13::GetItemFromProtocolID(UInt32 a_ProtocolID) const
{
return PaletteUpgrade::ToItem(Palette_1_13::ToItem(a_ProtocolID));
}
UInt32 cProtocol_1_13::GetPacketID(ePacketType a_PacketType) const
{
switch (a_PacketType)
{
case pktAttachEntity: return 0x46;
case pktBlockChanges: return 0x0f;
case pktCameraSetTo: return 0x3c;
case pktChatRaw: return 0x0e;
case pktCollectEntity: return 0x4f;
case pktDestroyEntity: return 0x35;
case pktDisconnectDuringGame: return 0x1b;
case pktEditSign: return 0x2c;
case pktEntityEffect: return 0x53;
case pktEntityEquipment: return 0x42;
case pktEntityHeadLook: return 0x39;
case pktEntityLook: return 0x2a;
case pktEntityMeta: return 0x3f;
case pktEntityProperties: return 0x52;
case pktEntityRelMove: return 0x28;
case pktEntityRelMoveLook: return 0x29;
case pktEntityStatus: return 0x1c;
case pktEntityVelocity: return 0x41;
case pktExperience: return 0x43;
case pktExplosion: return 0x1e;
case pktGameMode: return 0x20;
case pktHeldItemChange: return 0x3d;
case pktInventorySlot: return 0x17;
case pktJoinGame: return 0x25;
case pktKeepAlive: return 0x21;
case pktLeashEntity: return 0x40;
case pktMapData: return 0x26;
case pktParticleEffect: return 0x24;
case pktPlayerAbilities: return 0x2e;
case pktPlayerList: return 0x30;
case pktPlayerListHeaderFooter: return 0x4e;
case pktPlayerMoveLook: return 0x32;
case pktPluginMessage: return 0x19;
case pktRemoveEntityEffect: return 0x36;
case pktRespawn: return 0x38;
case pktScoreboardObjective: return 0x45;
case pktSoundEffect: return 0x1a;
case pktSoundParticleEffect: return 0x23;
case pktSpawnPosition: return 0x49;
case pktTabCompletionResults: return 0x10;
case pktTeleportEntity: return 0x50;
case pktTimeUpdate: return 0x4a;
case pktTitle: return 0x4b;
case pktUnloadChunk: return 0x1f;
case pktUnlockRecipe: return 0x32;
case pktUpdateHealth: return 0x44;
case pktUpdateScore: return 0x48;
case pktUpdateSign: return GetPacketID(pktUpdateBlockEntity);
case pktUseBed: return 0x33;
case pktWeather: return 0x20;
case pktWindowClose: return 0x13;
case pktWindowItems: return 0x15;
case pktWindowOpen: return 0x14;
case pktWindowProperty: return 0x16;
default: return Super::GetPacketID(a_PacketType);
}
}
UInt32 cProtocol_1_13::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const
{
return Palette_1_13::From(PaletteUpgrade::FromBlock(a_BlockType, a_Meta));
}
signed char cProtocol_1_13::GetProtocolEntityStatus(const EntityAnimation a_Animation) const
{
switch (a_Animation)
{
case EntityAnimation::DolphinShowsHappiness: return 38;
default: return Super::GetProtocolEntityStatus(a_Animation);
}
}
UInt32 cProtocol_1_13::GetProtocolItemType(short a_ItemID, short a_ItemDamage) const
{
return Palette_1_13::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage));
}
UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType) const
{
switch (a_MobType)
{
// Map invalid type to Giant for easy debugging (if this ever spawns, something has gone very wrong)
case mtInvalidType: return 27;
case mtBat: return 3;
case mtCat: return 48;
case mtBlaze: return 4;
case mtCaveSpider: return 6;
case mtChicken: return 7;
case mtCod: return 8;
case mtCow: return 9;
case mtCreeper: return 10;
case mtDonkey: return 11;
case mtDolphin: return 12;
case mtDrowned: return 14;
case mtElderGuardian: return 15;
case mtEnderDragon: return 17;
case mtEnderman: return 18;
case mtEndermite: return 19;
case mtEvoker: return 21;
case mtGhast: return 26;
case mtGiant: return 27;
case mtGuardian: return 28;
case mtHorse: return 29;
case mtHusk: return 30;
case mtIllusioner: return 31;
case mtIronGolem: return 80;
case mtLlama: return 36;
case mtMagmaCube: return 38;
case mtMule: return 46;
case mtMooshroom: return 47;
case mtOcelot: return 48;
case mtParrot: return 50;
case mtPhantom: return 90;
case mtPig: return 51;
case mtPufferfish: return 52;
case mtPolarBear: return 54;
case mtRabbit: return 56;
case mtSalmon: return 57;
case mtSheep: return 58;
case mtShulker: return 59;
case mtSilverfish: return 61;
case mtSkeleton: return 62;
case mtSkeletonHorse: return 63;
case mtSlime: return 64;
case mtSnowGolem: return 66;
case mtSpider: return 69;
case mtSquid: return 70;
case mtStray: return 71;
case mtTropicalFish: return 72;
case mtTurtle: return 73;
case mtVex: return 78;
case mtVillager: return 79;
case mtVindicator: return 81;
case mtWitch: return 82;
case mtWither: return 83;
case mtWitherSkeleton: return 84;
case mtWolf: return 86;
case mtZombie: return 87;
case mtZombiePigman: return 53;
case mtZombieHorse: return 88;
case mtZombieVillager: return 89;
default: return 0;
}
}
UInt32 cProtocol_1_13::GetProtocolStatisticType(const CustomStatistic a_Statistic) const
{
return Palette_1_13::From(a_Statistic);
}
cProtocol::Version cProtocol_1_13::GetProtocolVersion() const
{
return Version::v1_13;
}
bool cProtocol_1_13::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
{
if (m_State != 3)
{
return Super::HandlePacket(a_ByteBuffer, a_PacketType);
}
// Game
switch (a_PacketType)
{
case 0x00: HandleConfirmTeleport(a_ByteBuffer); return true;
case 0x05: HandlePacketTabComplete(a_ByteBuffer); return true;
case 0x02: HandlePacketChatMessage(a_ByteBuffer); return true;
case 0x03: HandlePacketClientStatus(a_ByteBuffer); return true;
case 0x04: HandlePacketClientSettings(a_ByteBuffer); return true;
case 0x06: break; // Confirm transaction - not used in Cuberite
case 0x07: HandlePacketEnchantItem(a_ByteBuffer); return true;
case 0x08: HandlePacketWindowClick(a_ByteBuffer); return true;
case 0x09: HandlePacketWindowClose(a_ByteBuffer); return true;
case 0x0a: HandlePacketPluginMessage(a_ByteBuffer); return true;
case 0x0d: HandlePacketUseEntity(a_ByteBuffer); return true;
case 0x0e: HandlePacketKeepAlive(a_ByteBuffer); return true;
case 0x0f: HandlePacketPlayer(a_ByteBuffer); return true;
case 0x10: HandlePacketPlayerPos(a_ByteBuffer); return true;
case 0x11: HandlePacketPlayerPosLook(a_ByteBuffer); return true;
case 0x12: HandlePacketPlayerLook(a_ByteBuffer); return true;
case 0x13: HandlePacketVehicleMove(a_ByteBuffer); return true;
case 0x14: HandlePacketBoatSteer(a_ByteBuffer); return true;
case 0x15: break; // Pick item - not yet implemented
case 0x16: break; // Craft Recipe Request - not yet implemented
case 0x17: HandlePacketPlayerAbilities(a_ByteBuffer); return true;
case 0x18: HandlePacketBlockDig(a_ByteBuffer); return true;
case 0x19: HandlePacketEntityAction(a_ByteBuffer); return true;
case 0x1a: HandlePacketSteerVehicle(a_ByteBuffer); return true;
case 0x1b: HandlePacketCraftingBookData(a_ByteBuffer); return true;
case 0x1c: HandlePacketNameItem(a_ByteBuffer); return true;
case 0x1d: break; // Resource pack status - not yet implemented
case 0x1e: HandlePacketAdvancementTab(a_ByteBuffer); return true;
case 0x20: HandlePacketSetBeaconEffect(a_ByteBuffer); return true;
case 0x21: HandlePacketSlotSelect(a_ByteBuffer); return true;
case 0x24: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true;
case 0x26: HandlePacketUpdateSign(a_ByteBuffer); return true;
case 0x27: HandlePacketAnimation(a_ByteBuffer); return true;
case 0x28: HandlePacketSpectate(a_ByteBuffer); return true;
case 0x29: HandlePacketBlockPlace(a_ByteBuffer); return true;
case 0x2a: HandlePacketUseItem(a_ByteBuffer); return true;
}
return Super::HandlePacket(a_ByteBuffer, a_PacketType);
}
void cProtocol_1_13::HandlePacketNameItem(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, NewItemName);
LOGD("New item name : %s", NewItemName);
}
void cProtocol_1_13::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, NamespacedChannel);
const auto & [Namespace, Channel] = NamespaceSerializer::SplitNamespacedID(NamespacedChannel);
// If the plugin channel is recognized vanilla, handle it directly:
if (Namespace == NamespaceSerializer::Namespace::Minecraft)
{
HandleVanillaPluginMessage(a_ByteBuffer, Channel);
return;
}
ContiguousByteBuffer Data;
// Read the plugin message and relay to clienthandle:
a_ByteBuffer.ReadSome(Data, a_ByteBuffer.GetReadableSpace());
m_Client->HandlePluginMessage(NamespacedChannel, Data);
}
void cProtocol_1_13::HandlePacketSetBeaconEffect(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect1);
HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect2);
m_Client->HandleBeaconSelection(Effect1, Effect2);
}
void cProtocol_1_13::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const std::string_view a_Channel)
{
if (a_Channel == "brand")
{
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Brand);
m_Client->SetClientBrand(Brand);
m_Client->SendPluginMessage("brand", "\x08""Cuberite"); // Send back our brand, including the length.
}
}
bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) const
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemID);
if (ItemID == -1)
{
// The item is empty, no more data follows
a_Item.Empty();
return true;
}
const auto Translated = GetItemFromProtocolID(ToUnsigned(ItemID));
a_Item.m_ItemType = Translated.first;
a_Item.m_ItemDamage = Translated.second;
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, ItemCount);
a_Item.m_ItemCount = ItemCount;
if (ItemCount <= 0)
{
a_Item.Empty();
}
ContiguousByteBuffer Metadata;
if (!a_ByteBuffer.ReadSome(Metadata, a_ByteBuffer.GetReadableSpace() - a_KeepRemainingBytes) || Metadata.empty() || (Metadata[0] == std::byte(0)))
{
// No metadata
return true;
}
ParseItemMetadata(a_Item, Metadata);
return true;
}
void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const EntityMetadata a_Metadata, const EntityMetadataType a_FieldType) const
{
a_Pkt.WriteBEUInt8(GetEntityMetadataID(a_Metadata)); // Index
a_Pkt.WriteBEUInt8(GetEntityMetadataID(a_FieldType)); // Type
}
void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) const
{
// Common metadata:
Int8 Flags = 0;
if (a_Entity.IsOnFire())
{
Flags |= 0x01;
}
if (a_Entity.IsCrouched())
{
Flags |= 0x02;
}
if (a_Entity.IsSprinting())
{
Flags |= 0x08;
}
if (a_Entity.IsRclking())
{
Flags |= 0x10;
}
if (a_Entity.IsInvisible())
{
Flags |= 0x20;
}
WriteEntityMetadata(a_Pkt, EntityMetadata::EntityFlags, EntityMetadataType::Byte);
a_Pkt.WriteBEInt8(Flags);
switch (a_Entity.GetEntityType())
{
case cEntity::etPlayer:
{
auto & Player = static_cast<const cPlayer &>(a_Entity);
// TODO Set player custom name to their name.
// Then it's possible to move the custom name of mobs to the entities
// and to remove the "special" player custom name.
WriteEntityMetadata(a_Pkt, EntityMetadata::EntityCustomName, EntityMetadataType::String);
a_Pkt.WriteString(Player.GetName());
WriteEntityMetadata(a_Pkt, EntityMetadata::LivingHealth, EntityMetadataType::Float);
a_Pkt.WriteBEFloat(static_cast<float>(Player.GetHealth()));
WriteEntityMetadata(a_Pkt, EntityMetadata::PlayerDisplayedSkinParts, EntityMetadataType::Byte);
a_Pkt.WriteBEUInt8(static_cast<UInt8>(Player.GetSkinParts()));
WriteEntityMetadata(a_Pkt, EntityMetadata::PlayerMainHand, EntityMetadataType::Byte);
a_Pkt.WriteBEUInt8(Player.IsLeftHanded() ? 0 : 1);
break;
}
case cEntity::etPickup:
{
WriteEntityMetadata(a_Pkt, EntityMetadata::ItemItem, EntityMetadataType::Item);
WriteItem(a_Pkt, static_cast<const cPickup &>(a_Entity).GetItem());
break;
}
case cEntity::etMinecart:
{
WriteEntityMetadata(a_Pkt, EntityMetadata::MinecartShakingPower, EntityMetadataType::VarInt);
// The following expression makes Minecarts shake more with less health or higher damage taken
auto & Minecart = static_cast<const cMinecart &>(a_Entity);
auto maxHealth = a_Entity.GetMaxHealth();
auto curHealth = a_Entity.GetHealth();
a_Pkt.WriteVarInt32(static_cast<UInt32>((maxHealth - curHealth) * Minecart.LastDamage() * 4));
WriteEntityMetadata(a_Pkt, EntityMetadata::MinecartShakingDirection, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(1); // (doesn't seem to effect anything)
WriteEntityMetadata(a_Pkt, EntityMetadata::MinecartShakingMultiplier, EntityMetadataType::Float);
a_Pkt.WriteBEFloat(static_cast<float>(Minecart.LastDamage() + 10)); // or damage taken
if (Minecart.GetPayload() == cMinecart::mpNone)
{
auto & RideableMinecart = static_cast<const cRideableMinecart &>(Minecart);
const cItem & MinecartContent = RideableMinecart.GetContent();
if (!MinecartContent.IsEmpty())
{
WriteEntityMetadata(a_Pkt, EntityMetadata::MinecartBlockIDMeta, EntityMetadataType::VarInt);
int Content = MinecartContent.m_ItemType;
Content |= MinecartContent.m_ItemDamage << 8;
a_Pkt.WriteVarInt32(static_cast<UInt32>(Content));
WriteEntityMetadata(a_Pkt, EntityMetadata::MinecartBlockY, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(RideableMinecart.GetBlockHeight()));
WriteEntityMetadata(a_Pkt, EntityMetadata::MinecartShowBlock, EntityMetadataType::Boolean);
a_Pkt.WriteBool(true);
}
}
else if (Minecart.GetPayload() == cMinecart::mpFurnace)
{
WriteEntityMetadata(a_Pkt, EntityMetadata::MinecartFurnacePowered, EntityMetadataType::Boolean);
a_Pkt.WriteBool(static_cast<const cMinecartWithFurnace &>(Minecart).IsFueled());
}
break;
} // case etMinecart
case cEntity::etProjectile:
{
auto & Projectile = static_cast<const cProjectileEntity &>(a_Entity);
switch (Projectile.GetProjectileKind())
{
case cProjectileEntity::pkArrow:
{
WriteEntityMetadata(a_Pkt, EntityMetadata::ArrowFlags, EntityMetadataType::Byte);
a_Pkt.WriteBEInt8(static_cast<const cArrowEntity &>(Projectile).IsCritical() ? 1 : 0);
break;
}
case cProjectileEntity::pkFirework:
{
// TODO
break;
}
case cProjectileEntity::pkSplashPotion:
{
// TODO
}
default:
{
break;
}
}
break;
} // case etProjectile
case cEntity::etMonster:
{
WriteMobMetadata(a_Pkt, static_cast<const cMonster &>(a_Entity));
break;
}
case cEntity::etBoat:
{
auto & Boat = static_cast<const cBoat &>(a_Entity);
WriteEntityMetadata(a_Pkt, EntityMetadata::BoatLastHitTime, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Boat.GetLastDamage()));
WriteEntityMetadata(a_Pkt, EntityMetadata::BoatForwardDirection, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Boat.GetForwardDirection()));
WriteEntityMetadata(a_Pkt, EntityMetadata::BoatDamageTaken, EntityMetadataType::Float);
a_Pkt.WriteBEFloat(Boat.GetDamageTaken());
WriteEntityMetadata(a_Pkt, EntityMetadata::BoatType, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Boat.GetMaterial()));
WriteEntityMetadata(a_Pkt, EntityMetadata::BoatRightPaddleTurning, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Boat.IsRightPaddleUsed());
WriteEntityMetadata(a_Pkt, EntityMetadata::BoatLeftPaddleTurning, EntityMetadataType::Boolean);
a_Pkt.WriteBool(static_cast<bool>(Boat.IsLeftPaddleUsed()));
WriteEntityMetadata(a_Pkt, EntityMetadata::BoatSplashTimer, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(0);
break;
} // case etBoat
case cEntity::etItemFrame:
{
// TODO
break;
} // case etItemFrame
case cEntity::etEnderCrystal:
{
const auto & EnderCrystal = static_cast<const cEnderCrystal &>(a_Entity);
if (EnderCrystal.DisplaysBeam())
{
WriteEntityMetadata(a_Pkt, EntityMetadata::EnderCrystalBeamTarget, EntityMetadataType::OptPosition);
a_Pkt.WriteBool(true); // Dont do a second check if it should display the beam
a_Pkt.WriteXYZPosition64(EnderCrystal.GetBeamTarget());
}
WriteEntityMetadata(a_Pkt, EntityMetadata::EnderCrystalShowBottom, EntityMetadataType::Boolean);
a_Pkt.WriteBool(EnderCrystal.ShowsBottom());
break;
} // case etEnderCrystal
default:
{
break;
}
}
}
void cProtocol_1_13::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) const
{
short ItemType = a_Item.m_ItemType;
ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
if (ItemType <= 0)
{
// Fix, to make sure no invalid values are sent.
ItemType = -1;
}
if (a_Item.IsEmpty())
{
a_Pkt.WriteBEInt16(-1);
return;
}
// Normal item
a_Pkt.WriteBEInt16(static_cast<Int16>(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage)));
a_Pkt.WriteBEInt8(a_Item.m_ItemCount);
// TODO: NBT
a_Pkt.WriteBEInt8(0);
}
void cProtocol_1_13::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) const
{
// Living Enitiy Metadata
if (a_Mob.HasCustomName())
{
// TODO: As of 1.9 _all_ entities can have custom names; should this be moved up?
WriteEntityMetadata(a_Pkt, EntityMetadata::EntityCustomName, EntityMetadataType::OptChat);
a_Pkt.WriteBool(true);
a_Pkt.WriteString(a_Mob.GetCustomName());
WriteEntityMetadata(a_Pkt, EntityMetadata::EntityCustomNameVisible, EntityMetadataType::Boolean);
a_Pkt.WriteBool(a_Mob.IsCustomNameAlwaysVisible());
}
WriteEntityMetadata(a_Pkt, EntityMetadata::LivingHealth, EntityMetadataType::Float);
a_Pkt.WriteBEFloat(static_cast<float>(a_Mob.GetHealth()));
switch (a_Mob.GetMobType())
{
case mtBat:
{
auto & Bat = static_cast<const cBat &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::BatHanging, EntityMetadataType::Byte);
a_Pkt.WriteBEInt8(Bat.IsHanging() ? 1 : 0);
break;
} // case mtBat
case mtChicken:
{
auto & Chicken = static_cast<const cChicken &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Chicken.IsBaby());
break;
} // case mtChicken
case mtCow:
{
auto & Cow = static_cast<const cCow &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Cow.IsBaby());
break;
} // case mtCow
case mtCreeper:
{
auto & Creeper = static_cast<const cCreeper &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::CreeperState, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(Creeper.IsBlowing() ? 1 : static_cast<UInt32>(-1)); // (idle or "blowing")
WriteEntityMetadata(a_Pkt, EntityMetadata::CreeperPowered, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Creeper.IsCharged());
WriteEntityMetadata(a_Pkt, EntityMetadata::CreeperIgnited, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Creeper.IsBurnedWithFlintAndSteel());
break;
} // case mtCreeper
case mtEnderman:
{
auto & Enderman = static_cast<const cEnderman &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::EndermanCarriedBlock, EntityMetadataType::OptBlockID);
UInt32 Carried = 0;
Carried |= static_cast<UInt32>(Enderman.GetCarriedBlock() << 4);
Carried |= Enderman.GetCarriedMeta();
a_Pkt.WriteVarInt32(Carried);
WriteEntityMetadata(a_Pkt, EntityMetadata::EndermanScreaming, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Enderman.IsScreaming());
break;
} // case mtEnderman
case mtGhast:
{
auto & Ghast = static_cast<const cGhast &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::GhastAttacking, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Ghast.IsCharging());
break;
} // case mtGhast
case mtHorse:
{
// XXX This behaves incorrectly with different varients; horses have different entity IDs now
// Abstract horse
auto & Horse = static_cast<const cHorse &>(a_Mob);
Int8 Flags = 0;
if (Horse.IsTame())
{
Flags |= 0x02;
}
if (Horse.IsSaddled())
{
Flags |= 0x04;
}
if (Horse.IsInLoveCooldown())
{
Flags |= 0x08;
}
if (Horse.IsEating())
{
Flags |= 0x10;
}
if (Horse.IsRearing())
{
Flags |= 0x20;
}
if (Horse.IsMthOpen())
{
Flags |= 0x40;
}
WriteEntityMetadata(a_Pkt, EntityMetadata::AbstractHorseFlags, EntityMetadataType::Byte);
a_Pkt.WriteBEInt8(Flags);
// Regular horses
int Appearance = 0;
Appearance = Horse.GetHorseColor();
Appearance |= Horse.GetHorseStyle() << 8;
WriteEntityMetadata(a_Pkt, EntityMetadata::HorseVariant, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Appearance)); // Color / style
WriteEntityMetadata(a_Pkt, EntityMetadata::HorseArmour, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Horse.GetHorseArmour()));
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Horse.IsBaby());
break;
} // case mtHorse
case mtMagmaCube:
{
auto & MagmaCube = static_cast<const cMagmaCube &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::SlimeSize, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(MagmaCube.GetSize()));
break;
} // case mtMagmaCube
case mtOcelot:
{
auto & Ocelot = static_cast<const cOcelot &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Ocelot.IsBaby());
Int8 OcelotStatus = 0;
if (Ocelot.IsSitting())
{
OcelotStatus |= 0x1;
}
if (Ocelot.IsTame())
{
OcelotStatus |= 0x4;
}
WriteEntityMetadata(a_Pkt, EntityMetadata::TameableAnimalFlags, EntityMetadataType::Byte);
a_Pkt.WriteBEInt8(OcelotStatus);
WriteEntityMetadata(a_Pkt, EntityMetadata::OcelotType, EntityMetadataType::Byte);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Ocelot.GetOcelotType()));
break;
} // case mtOcelot
case mtPig:
{
auto & Pig = static_cast<const cPig &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Pig.IsBaby());
WriteEntityMetadata(a_Pkt, EntityMetadata::PigHasSaddle, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Pig.IsSaddled());
// PIG_TOTAL_CARROT_ON_A_STICK_BOOST in 1.11.1 only
break;
} // case mtPig
case mtRabbit:
{
auto & Rabbit = static_cast<const cRabbit &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Rabbit.IsBaby());
WriteEntityMetadata(a_Pkt, EntityMetadata::RabbitType, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Rabbit.GetRabbitType()));
break;
} // case mtRabbit
case mtSheep:
{
auto & Sheep = static_cast<const cSheep &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Sheep.IsBaby());
Int8 SheepMetadata = 0;
SheepMetadata = static_cast<Int8>(Sheep.GetFurColor());
if (Sheep.IsSheared())
{
SheepMetadata |= 0x10;
}
WriteEntityMetadata(a_Pkt, EntityMetadata::SheepFlags, EntityMetadataType::Byte);
a_Pkt.WriteBEInt8(SheepMetadata);
break;
} // case mtSheep
case mtSkeleton:
{
auto & Skeleton = static_cast<const cSkeleton &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::LivingActiveHand, EntityMetadataType::Byte);
a_Pkt.WriteBEUInt8(Skeleton.IsChargingBow() ? 0x01 : 0x00);
WriteEntityMetadata(a_Pkt, EntityMetadata::AbstractSkeletonArmsSwinging, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Skeleton.IsChargingBow());
break;
} // case mtSkeleton
case mtSlime:
{
auto & Slime = static_cast<const cSlime &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::SlimeSize, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Slime.GetSize()));
break;
} // case mtSlime
case mtVillager:
{
auto & Villager = static_cast<const cVillager &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Villager.IsBaby());
WriteEntityMetadata(a_Pkt, EntityMetadata::VillagerProfession, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Villager.GetVilType()));
break;
} // case mtVillager
case mtWitch:
{
auto & Witch = static_cast<const cWitch &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::WitchAggresive, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Witch.IsAngry());
break;
} // case mtWitch
case mtWither:
{
auto & Wither = static_cast<const cWither &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::WitherInvulnerableTimer, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(Wither.GetWitherInvulnerableTicks());
// TODO: Use boss bar packet for health
break;
} // case mtWither
case mtWolf:
{
auto & Wolf = static_cast<const cWolf &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Wolf.IsBaby());
Int8 WolfStatus = 0;
if (Wolf.IsSitting())
{
WolfStatus |= 0x1;
}
if (Wolf.IsAngry())
{
WolfStatus |= 0x2;
}
if (Wolf.IsTame())
{
WolfStatus |= 0x4;
}
WriteEntityMetadata(a_Pkt, EntityMetadata::TameableAnimalFlags, EntityMetadataType::Byte);
a_Pkt.WriteBEInt8(WolfStatus);
WriteEntityMetadata(a_Pkt, EntityMetadata::WolfDamageTaken, EntityMetadataType::Float);
a_Pkt.WriteBEFloat(static_cast<float>(a_Mob.GetHealth())); // TODO Not use the current health
WriteEntityMetadata(a_Pkt, EntityMetadata::WolfBegging, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Wolf.IsBegging());
WriteEntityMetadata(a_Pkt, EntityMetadata::WolfCollarColour, EntityMetadataType::VarInt);
a_Pkt.WriteVarInt32(static_cast<UInt32>(Wolf.GetCollarColor()));
break;
} // case mtWolf
case mtZombie:
{
// XXX Zombies were also split into new sublcasses; this doesn't handle that.
auto & Zombie = static_cast<const cZombie &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::ZombieIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(Zombie.IsBaby());
break;
} // case mtZombie
case mtZombiePigman:
{
auto & ZombiePigman = static_cast<const cZombiePigman &>(a_Mob);
WriteEntityMetadata(a_Pkt, EntityMetadata::AgeableIsBaby, EntityMetadataType::Boolean);
a_Pkt.WriteBool(ZombiePigman.IsBaby());
break;
} // case mtZombiePigman
case mtBlaze:
case mtEnderDragon:
case mtIronGolem:
case mtSnowGolem:
case mtSpider:
case mtZombieVillager:
case mtElderGuardian:
case mtGuardian:
{
// TODO: Mobs with extra fields that aren't implemented
break;
}
case mtCat:
case mtCod:
case mtDolphin:
case mtDonkey:
case mtDrowned:
case mtEndermite:
case mtEvoker:
case mtIllusioner:
case mtLlama:
case mtMule:
case mtParrot:
case mtPhantom:
case mtPolarBear:
case mtPufferfish:
case mtSalmon:
case mtShulker:
case mtStray:
case mtSkeletonHorse:
case mtZombieHorse:
case mtTropicalFish:
case mtTurtle:
case mtVex:
case mtVindicator:
case mtHusk:
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
ASSERT(!"cProtocol_1_13::WriteMobMetadata: received unimplemented type");
break;
}
case mtMooshroom:
case mtCaveSpider:
{
// Not mentioned on http://wiki.vg/Entities
break;
}
case mtGiant:
case mtSilverfish:
case mtSquid:
case mtWitherSkeleton:
{
// Mobs with no extra fields
break;
}
default: UNREACHABLE("cProtocol_1_13::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}
////////////////////////////////////////////////////////////////////////////////
// cProtocol_1_13_1:
void cProtocol_1_13_1::SendBossBarAdd(UInt32 a_UniqueID, const cCompositeChat & a_Title, float a_FractionFilled, BossBarColor a_Color, BossBarDivisionType a_DivisionType, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, pktBossBar);
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
Pkt.WriteBEUInt64(a_UniqueID);
Pkt.WriteVarInt32(0); // Add
Pkt.WriteString(a_Title.CreateJsonString());
Pkt.WriteBEFloat(a_FractionFilled);
Pkt.WriteVarInt32([a_Color]
{
switch (a_Color)
{
case BossBarColor::Pink: return 0U;
case BossBarColor::Blue: return 1U;
case BossBarColor::Red: return 2U;
case BossBarColor::Green: return 3U;
case BossBarColor::Yellow: return 4U;
case BossBarColor::Purple: return 5U;
case BossBarColor::White: return 6U;
}
UNREACHABLE("Unsupported boss bar property");
}());
Pkt.WriteVarInt32([a_DivisionType]
{
switch (a_DivisionType)
{
case BossBarDivisionType::None: return 0U;
case BossBarDivisionType::SixNotches: return 1U;
case BossBarDivisionType::TenNotches: return 2U;
case BossBarDivisionType::TwelveNotches: return 3U;
case BossBarDivisionType::TwentyNotches: return 4U;
}
UNREACHABLE("Unsupported boss bar property");
}());
{
UInt8 Flags = 0x00;
if (a_DarkenSky)
{
Flags |= 0x01;
}
if (a_PlayEndMusic)
{
Flags |= 0x02;
}
if (a_CreateFog)
{
Flags |= 0x04; // Only difference to 1.9 is fog now a separate flag
}
Pkt.WriteBEUInt8(Flags);
}
}
void cProtocol_1_13_1::SendBossBarUpdateFlags(UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, pktBossBar);
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0);
Pkt.WriteBEUInt64(a_UniqueID);
Pkt.WriteVarInt32(5); // Update Flags
{
UInt8 Flags = 0x00;
if (a_DarkenSky)
{
Flags |= 0x01;
}
if (a_PlayEndMusic)
{
Flags |= 0x02;
}
if (a_CreateFog)
{
Flags |= 0x04; // Only difference to 1.9 is fog now a separate flag
}
Pkt.WriteBEUInt8(Flags);
}
}
std::pair<short, short> cProtocol_1_13_1::GetItemFromProtocolID(UInt32 a_ProtocolID) const
{
return PaletteUpgrade::ToItem(Palette_1_13_1::ToItem(a_ProtocolID));
}
UInt32 cProtocol_1_13_1::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const
{
return Palette_1_13_1::From(PaletteUpgrade::FromBlock(a_BlockType, a_Meta));
}
UInt32 cProtocol_1_13_1::GetProtocolItemType(short a_ItemID, short a_ItemDamage) const
{
return Palette_1_13_1::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage));
}
UInt32 cProtocol_1_13_1::GetProtocolStatisticType(const CustomStatistic a_Statistic) const
{
return Palette_1_13_1::From(a_Statistic);
}
cProtocol::Version cProtocol_1_13_1::GetProtocolVersion() const
{
return Version::v1_13_1;
}
////////////////////////////////////////////////////////////////////////////////
// cProtocol_1_13_2:
cProtocol::Version cProtocol_1_13_2::GetProtocolVersion() const
{
return Version::v1_13_2;
}
bool cProtocol_1_13_2::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) const
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, Present);
if (!Present)
{
// The item is empty, no more data follows
a_Item.Empty();
return true;
}
HANDLE_PACKET_READ(a_ByteBuffer, ReadVarInt32, UInt32, ItemID);
const auto Translated = GetItemFromProtocolID(ItemID);
a_Item.m_ItemType = Translated.first;
a_Item.m_ItemDamage = Translated.second;
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt8, Int8, ItemCount);
a_Item.m_ItemCount = ItemCount;
if (ItemCount <= 0)
{
a_Item.Empty();
}
ContiguousByteBuffer Metadata;
if (!a_ByteBuffer.ReadSome(Metadata, a_ByteBuffer.GetReadableSpace() - a_KeepRemainingBytes) || Metadata.empty() || (Metadata[0] == std::byte(0)))
{
// No metadata
return true;
}
ParseItemMetadata(a_Item, Metadata);
return true;
}
void cProtocol_1_13_2::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) const
{
short ItemType = a_Item.m_ItemType;
ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
if (ItemType <= 0)
{
// Fix, to make sure no invalid values are sent.
ItemType = -1;
}
if (a_Item.IsEmpty())
{
a_Pkt.WriteBool(false);
return;
}
// Item present
a_Pkt.WriteBool(true);
// Normal item
a_Pkt.WriteVarInt32(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage));
a_Pkt.WriteBEInt8(a_Item.m_ItemCount);
// TODO: NBT
a_Pkt.WriteBEInt8(0);
}
|