Cuberite
A lightweight, fast and extensible game server for Minecraft
Protocol_1_12.cpp
Go to the documentation of this file.
1 
2 // Protocol_1_12.cpp
3 
4 /*
5 Implements the 1.12 protocol classes:
6 - release 1.12 protocol (#335)
7 - release 1.12.1 protocol (#338)
8 - release 1.12.2 protocol (#340)
9 */
10 
11 #include "Globals.h"
12 #include "Protocol_1_12.h"
13 #include "Packetizer.h"
14 
15 #include "../Entities/Boat.h"
16 #include "../Entities/EnderCrystal.h"
17 #include "../Entities/Minecart.h"
18 #include "../Entities/Pickup.h"
19 #include "../Entities/Player.h"
20 #include "../Entities/ItemFrame.h"
21 #include "../Entities/ArrowEntity.h"
22 #include "../Entities/FireworkEntity.h"
23 #include "../Entities/SplashPotionEntity.h"
24 
25 #include "../Mobs/IncludeAllMonsters.h"
26 
27 #include "../Root.h"
28 #include "../Server.h"
29 #include "../ClientHandle.h"
30 #include "../CraftingRecipes.h"
31 #include "../Bindings/PluginManager.h"
32 #include "../JsonUtils.h"
33 
34 
35 
36 
37 
38 // The disabled error is intended, since the Metadata have overlapping indexes
39 // based on the type of the Entity.
40 //
41 // IMPORTANT: The enum is used to automate the sequential counting of the
42 // Metadata indexes. Adding a new enum value causes the following values to
43 // increase their index. Therefore the ordering of the enum values is VERY important!
44 #ifdef __clang__
45 #pragma clang diagnostic push
46 #pragma clang diagnostic ignored "-Wduplicate-enum"
47 #endif
48 
49 namespace Metadata_1_12
50 {
52  {
53  // Entity
60  _ENTITY_NEXT, // Used by descendants
61 
62  // Potion
63  POTION_THROWN = _ENTITY_NEXT,
64 
65  // FallingBlock
66  FALLING_BLOCK_POSITION = _ENTITY_NEXT,
67 
68  // AreaEffectCloud
69  AREA_EFFECT_CLOUD_RADIUS = _ENTITY_NEXT,
75 
76  // Arrow
77  ARROW_CRITICAL = _ENTITY_NEXT,
78  _ARROW_NEXT,
79 
80  // TippedArrow
81  TIPPED_ARROW_COLOR = _ARROW_NEXT,
82 
83  // Boat
84  BOAT_LAST_HIT_TIME = _ENTITY_NEXT,
90 
91  // EnderCrystal
92  ENDER_CRYSTAL_BEAM_TARGET = _ENTITY_NEXT,
94 
95  // Fireball
96  _FIREBALL_NEXT = _ENTITY_NEXT,
97 
98  // WitherSkull
99  WITHER_SKULL_INVULNERABLE = _FIREBALL_NEXT,
100 
101  // Fireworks
102  FIREWORK_INFO = _ENTITY_NEXT,
104 
105  // Hanging
106  _HANGING_NEXT = _ENTITY_NEXT,
107 
108  // ItemFrame
109  ITEM_FRAME_ITEM = _HANGING_NEXT,
111 
112  // Item
113  ITEM_ITEM = _ENTITY_NEXT,
114 
115  // Living
116  LIVING_ACTIVE_HAND = _ENTITY_NEXT,
121  _LIVING_NEXT,
122 
123  // Player
128 
129  // ArmorStand
130  ARMOR_STAND_STATUS = _LIVING_NEXT,
137 
138  // Insentient
139  INSENTIENT_STATUS = _LIVING_NEXT,
140  _INSENTIENT_NEXT,
141 
142  // Ambient
143  _AMBIENT_NEXT = _INSENTIENT_NEXT,
144 
145  // Bat
146  BAT_HANGING = _AMBIENT_NEXT,
147 
148  // Creature
149  _CREATURE_NEXT = _INSENTIENT_NEXT,
150 
151  // Ageable
152  AGEABLE_BABY = _CREATURE_NEXT,
153  _AGEABLE_NEXT,
154 
155  // PolarBear
156  POLAR_BEAR_STANDING = _AGEABLE_NEXT,
157 
158  // Animal
159  _ANIMAL_NEXT = _AGEABLE_NEXT,
160 
161  // Abstract horse
162  ABSTRACT_HORSE_STATUS = _ANIMAL_NEXT,
164  _ABSTRACT_HORSE_NEXT,
165 
166  // Horse
167  HORSE_VARIANT = _ABSTRACT_HORSE_NEXT,
169 
170  // Chested horse
171  CHESTED_HORSE_CHESTED = _ABSTRACT_HORSE_NEXT,
172  _CHESTED_HORSE_NEXT,
173 
174  // Llama
175  LLAMA_STRENGTH = _CHESTED_HORSE_NEXT,
178 
179  // Pig
180  PIG_HAS_SADDLE = _ANIMAL_NEXT,
182 
183  // Rabbit
184  RABBIT_TYPE = _ANIMAL_NEXT,
185 
186  // Sheep
187  SHEEP_STATUS = _ANIMAL_NEXT,
188 
189  // TameableAnimal
190  TAMEABLE_ANIMAL_STATUS = _ANIMAL_NEXT,
192  _TAMEABLE_NEXT,
193 
194  // Ocelot
195  OCELOT_TYPE = _TAMEABLE_NEXT,
196 
197  // Wolf
198  WOLF_DAMAGE_TAKEN = _TAMEABLE_NEXT,
201 
202  // Villager
203  VILLAGER_PROFESSION = _AGEABLE_NEXT,
204 
205  // Golem
206  _GOLEM_NEXT = _CREATURE_NEXT,
207 
208  // IronGolem
210 
211  // Shulker
215 
216  // Monster
217  _MONSTER_NEXT = _CREATURE_NEXT,
218 
219  // Blaze
220  BLAZE_ON_FIRE = _MONSTER_NEXT,
221 
222  // Creeper
223  CREEPER_STATE = _MONSTER_NEXT,
226 
227  // Guardian
228  GUARDIAN_STATUS = _MONSTER_NEXT,
230 
231  // Abstract Skeleton
233 
234  // Spider
235  SPIDER_CLIMBING = _MONSTER_NEXT,
236 
237  // Witch
238  WITCH_AGGRESIVE = _MONSTER_NEXT,
239 
240  // Wither
241  WITHER_FIRST_HEAD_TARGET = _MONSTER_NEXT,
245 
246  // Zombie
247  ZOMBIE_IS_BABY = _MONSTER_NEXT,
248  ZOMBIE_UNUSED, // Was type
250  _ZOMBIE_NEXT,
251 
252  // Zombie villager
255 
256  // Enderman
257  ENDERMAN_CARRIED_BLOCK = _MONSTER_NEXT,
259 
260  // Evocation illager
261  EVOKER_SPELL = _MONSTER_NEXT,
262 
263  // Vex
264  VEX_FLAGS = _MONSTER_NEXT,
265 
266  // Vindication illager
267  VINDICATOR_FLAGS = _MONSTER_NEXT,
268 
269  // EnderDragon
270  ENDER_DRAGON_DRAGON_PHASE = _INSENTIENT_NEXT,
271 
272  // Flying
273  _FLYING_NEXT = _INSENTIENT_NEXT,
274 
275  // Ghast
276  GHAST_ATTACKING = _FLYING_NEXT,
277 
278  // Slime
279  SLIME_SIZE = _INSENTIENT_NEXT,
280 
281  // Minecart
282  MINECART_SHAKING_POWER = _ENTITY_NEXT,
288  _MINECART_NEXT,
289 
290  // MinecartCommandBlock
293 
294  // MinecartFurnace
295  MINECART_FURNACE_POWERED = _MINECART_NEXT,
296 
297  // TNTPrimed
298  TNT_PRIMED_FUSE_TIME = _ENTITY_NEXT,
299  };
300 }
301 
302 #ifdef __clang__
303 #pragma clang diagnostic pop // Restore ignored clang errors
304 #endif
305 
306 
307 
308 
309 
311 // cProtocol_1_12:
312 
313 void cProtocol_1_12::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) const
314 {
315  using namespace Metadata_1_12;
316 
317  // Common metadata:
318  Int8 Flags = 0;
319  if (a_Entity.IsOnFire())
320  {
321  Flags |= 0x01;
322  }
323  if (a_Entity.IsCrouched())
324  {
325  Flags |= 0x02;
326  }
327  if (a_Entity.IsSprinting())
328  {
329  Flags |= 0x08;
330  }
331  if (a_Entity.IsRclking())
332  {
333  Flags |= 0x10;
334  }
335  if (a_Entity.IsInvisible())
336  {
337  Flags |= 0x20;
338  }
339  if (a_Entity.IsElytraFlying())
340  {
341  Flags |= 0x80;
342  }
343  a_Pkt.WriteBEUInt8(ENTITY_FLAGS); // Index
344  a_Pkt.WriteBEUInt8(METADATA_TYPE_BYTE); // Type
345  a_Pkt.WriteBEInt8(Flags);
346 
347  switch (a_Entity.GetEntityType())
348  {
349  case cEntity::etPlayer:
350  {
351  auto & Player = static_cast<const cPlayer &>(a_Entity);
352 
353  // TODO Set player custom name to their name.
354  // Then it's possible to move the custom name of mobs to the entities
355  // and to remove the "special" player custom name.
358  a_Pkt.WriteString(Player.GetName());
359 
362  a_Pkt.WriteBEFloat(static_cast<float>(Player.GetHealth()));
363 
366  a_Pkt.WriteBEUInt8(static_cast<UInt8>(Player.GetSkinParts()));
367 
370  a_Pkt.WriteBEUInt8(Player.IsLeftHanded() ? 0 : 1);
371  break;
372  }
373  case cEntity::etPickup:
374  {
375  a_Pkt.WriteBEUInt8(ITEM_ITEM);
377  WriteItem(a_Pkt, static_cast<const cPickup &>(a_Entity).GetItem());
378  break;
379  }
380  case cEntity::etMinecart:
381  {
384 
385  // The following expression makes Minecarts shake more with less health or higher damage taken
386  auto & Minecart = static_cast<const cMinecart &>(a_Entity);
387  auto maxHealth = a_Entity.GetMaxHealth();
388  auto curHealth = a_Entity.GetHealth();
389  a_Pkt.WriteVarInt32(static_cast<UInt32>((maxHealth - curHealth) * Minecart.LastDamage() * 4));
390 
391  a_Pkt.WriteBEUInt8(MINECART_SHAKING_DIRECTION); // (doesn't seem to effect anything)
393  a_Pkt.WriteVarInt32(1);
394 
395  a_Pkt.WriteBEUInt8(MINECART_SHAKING_MULTIPLIER); // or damage taken
397  a_Pkt.WriteBEFloat(static_cast<float>(Minecart.LastDamage() + 10));
398 
399  if (Minecart.GetPayload() == cMinecart::mpNone)
400  {
401  auto & RideableMinecart = static_cast<const cRideableMinecart &>(Minecart);
402  const cItem & MinecartContent = RideableMinecart.GetContent();
403  if (!MinecartContent.IsEmpty())
404  {
407  int Content = MinecartContent.m_ItemType;
408  Content |= MinecartContent.m_ItemDamage << 8;
409  a_Pkt.WriteVarInt32(static_cast<UInt32>(Content));
410 
413  a_Pkt.WriteVarInt32(static_cast<UInt32>(RideableMinecart.GetBlockHeight()));
414 
417  a_Pkt.WriteBool(true);
418  }
419  }
420  else if (Minecart.GetPayload() == cMinecart::mpFurnace)
421  {
424  a_Pkt.WriteBool(static_cast<const cMinecartWithFurnace &>(Minecart).IsFueled());
425  }
426  break;
427  } // case etMinecart
428 
430  {
431  auto & Projectile = static_cast<const cProjectileEntity &>(a_Entity);
432  switch (Projectile.GetProjectileKind())
433  {
435  {
438  a_Pkt.WriteBEInt8(static_cast<const cArrowEntity &>(Projectile).IsCritical() ? 1 : 0);
439  break;
440  }
442  {
443  a_Pkt.WriteBEUInt8(FIREWORK_INFO); // Firework item used for this firework
445  WriteItem(a_Pkt, static_cast<const cFireworkEntity &>(Projectile).GetItem());
446 
447  // FIREWORK_BOOSTED_ENTITY_ID, in 1.11.1 only
448  break;
449  }
451  {
452  a_Pkt.WriteBEUInt8(POTION_THROWN); // Potion item which was thrown
454  WriteItem(a_Pkt, static_cast<const cSplashPotionEntity &>(Projectile).GetItem());
455  }
456  default:
457  {
458  break;
459  }
460  }
461  break;
462  } // case etProjectile
463 
464  case cEntity::etMonster:
465  {
466  WriteMobMetadata(a_Pkt, static_cast<const cMonster &>(a_Entity));
467  break;
468  }
469 
470  case cEntity::etBoat:
471  {
472  auto & Boat = static_cast<const cBoat &>(a_Entity);
473 
476  a_Pkt.WriteVarInt32(static_cast<UInt32>(Boat.GetLastDamage()));
477 
480  a_Pkt.WriteVarInt32(static_cast<UInt32>(Boat.GetForwardDirection()));
481 
484  a_Pkt.WriteBEFloat(Boat.GetDamageTaken());
485 
486  a_Pkt.WriteBEInt8(BOAT_TYPE);
488  a_Pkt.WriteVarInt32(static_cast<UInt32>(Boat.GetMaterial()));
489 
492  a_Pkt.WriteBool(Boat.IsRightPaddleUsed());
493 
496  a_Pkt.WriteBool(Boat.IsLeftPaddleUsed());
497 
498  break;
499  } // case etBoat
500 
502  {
503  auto & Frame = static_cast<const cItemFrame &>(a_Entity);
506  WriteItem(a_Pkt, Frame.GetItem());
509  a_Pkt.WriteVarInt32(Frame.GetItemRotation());
510  break;
511  } // case etItemFrame
512 
514  {
515  const auto & EnderCrystal = static_cast<const cEnderCrystal &>(a_Entity);
516  if (EnderCrystal.DisplaysBeam())
517  {
520  a_Pkt.WriteBool(true); // Dont do a second check if it should display the beam
521  a_Pkt.WriteXYZPosition64(EnderCrystal.GetBeamTarget());
522  }
525  a_Pkt.WriteBool(EnderCrystal.ShowsBottom());
526  break;
527  } // case etEnderCrystal
528 
529  default:
530  {
531  break;
532  }
533  }
534 }
535 
536 
537 
538 
539 
540 void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) const
541 {
542  using namespace Metadata_1_12;
543 
544  // Living entity metadata
545  if (a_Mob.HasCustomName())
546  {
547  // TODO: As of 1.9 _all_ entities can have custom names; should this be moved up?
550  a_Pkt.WriteString(a_Mob.GetCustomName());
551 
552  a_Pkt.WriteBEUInt8(ENTITY_CUSTOM_NAME_VISIBLE); // Custom name always visible
554  a_Pkt.WriteBool(a_Mob.IsCustomNameAlwaysVisible());
555  }
556 
559  a_Pkt.WriteBEFloat(static_cast<float>(a_Mob.GetHealth()));
560 
561  switch (a_Mob.GetMobType())
562  {
563  case mtBat:
564  {
565  auto & Bat = static_cast<const cBat &>(a_Mob);
566  a_Pkt.WriteBEUInt8(BAT_HANGING);
568  a_Pkt.WriteBEInt8(Bat.IsHanging() ? 1 : 0);
569  break;
570  } // case mtBat
571 
572  case mtChicken:
573  {
574  auto & Chicken = static_cast<const cChicken &>(a_Mob);
575 
576  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
578  a_Pkt.WriteBool(Chicken.IsBaby());
579  break;
580  } // case mtChicken
581 
582  case mtCow:
583  {
584  auto & Cow = static_cast<const cCow &>(a_Mob);
585 
586  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
588  a_Pkt.WriteBool(Cow.IsBaby());
589  break;
590  } // case mtCow
591 
592  case mtCreeper:
593  {
594  auto & Creeper = static_cast<const cCreeper &>(a_Mob);
595  a_Pkt.WriteBEUInt8(CREEPER_STATE); // (idle or "blowing")
597  a_Pkt.WriteVarInt32(Creeper.IsBlowing() ? 1 : static_cast<UInt32>(-1));
598 
601  a_Pkt.WriteBool(Creeper.IsCharged());
602 
605  a_Pkt.WriteBool(Creeper.IsBurnedWithFlintAndSteel());
606  break;
607  } // case mtCreeper
608 
609  case mtEnderman:
610  {
611  auto & Enderman = static_cast<const cEnderman &>(a_Mob);
614  UInt32 Carried = 0;
615  Carried |= static_cast<UInt32>(Enderman.GetCarriedBlock() << 4);
616  Carried |= Enderman.GetCarriedMeta();
617  a_Pkt.WriteVarInt32(Carried);
618 
621  a_Pkt.WriteBool(Enderman.IsScreaming());
622  break;
623  } // case mtEnderman
624 
625  case mtGhast:
626  {
627  auto & Ghast = static_cast<const cGhast &>(a_Mob);
630  a_Pkt.WriteBool(Ghast.IsCharging());
631  break;
632  } // case mtGhast
633 
634  case mtHorse:
635  {
636  // XXX This behaves incorrectly with different variants; horses have different entity IDs now
637 
638  // Abstract horse
639  auto & Horse = static_cast<const cHorse &>(a_Mob);
640  Int8 Flags = 0;
641  if (Horse.IsTame())
642  {
643  Flags |= 0x02;
644  }
645  if (Horse.IsSaddled())
646  {
647  Flags |= 0x04;
648  }
649  if (Horse.IsChested())
650  {
651  Flags |= 0x08;
652  }
653  if (Horse.IsEating())
654  {
655  Flags |= 0x20;
656  }
657  if (Horse.IsRearing())
658  {
659  Flags |= 0x40;
660  }
661  if (Horse.IsMthOpen())
662  {
663  Flags |= 0x80;
664  }
667  a_Pkt.WriteBEInt8(Flags);
668 
669  // This doesn't exist any more; it'll cause horses to all be the normal type
670  // a_Pkt.WriteBEUInt8(HORSE_TYPE);
671  // a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT);
672  // a_Pkt.WriteVarInt32(static_cast<UInt32>(Horse.GetHorseType()));
673 
674  // Regular horses
675  a_Pkt.WriteBEUInt8(HORSE_VARIANT); // Color / style
677  int Appearance = 0;
678  Appearance = Horse.GetHorseColor();
679  Appearance |= Horse.GetHorseStyle() << 8;
680  a_Pkt.WriteVarInt32(static_cast<UInt32>(Appearance));
681 
682  a_Pkt.WriteBEUInt8(HORSE_ARMOR);
684  a_Pkt.WriteVarInt32(static_cast<UInt32>(Horse.GetHorseArmour()));
685 
686  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
688  a_Pkt.WriteBool(Horse.IsBaby());
689  break;
690  } // case mtHorse
691 
692  case mtMagmaCube:
693  {
694  auto & MagmaCube = static_cast<const cMagmaCube &>(a_Mob);
695  a_Pkt.WriteBEUInt8(SLIME_SIZE);
697  a_Pkt.WriteVarInt32(static_cast<UInt32>(MagmaCube.GetSize()));
698  break;
699  } // case mtMagmaCube
700 
701  case mtOcelot:
702  {
703  auto & Ocelot = static_cast<const cOcelot &>(a_Mob);
704 
705  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
707  a_Pkt.WriteBool(Ocelot.IsBaby());
708 
709  Int8 OcelotStatus = 0;
710  if (Ocelot.IsSitting())
711  {
712  OcelotStatus |= 0x1;
713  }
714  if (Ocelot.IsTame())
715  {
716  OcelotStatus |= 0x4;
717  }
720  a_Pkt.WriteBEInt8(OcelotStatus);
721 
722  a_Pkt.WriteBEUInt8(OCELOT_TYPE);
724  a_Pkt.WriteVarInt32(static_cast<UInt32>(Ocelot.GetOcelotType()));
725 
726  break;
727  } // case mtOcelot
728 
729  case mtPig:
730  {
731  auto & Pig = static_cast<const cPig &>(a_Mob);
732 
733  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
735  a_Pkt.WriteBool(Pig.IsBaby());
736 
739  a_Pkt.WriteBool(Pig.IsSaddled());
740 
741  // PIG_TOTAL_CARROT_ON_A_STICK_BOOST in 1.11.1 only
742  break;
743  } // case mtPig
744 
745  case mtRabbit:
746  {
747  auto & Rabbit = static_cast<const cRabbit &>(a_Mob);
748  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
750  a_Pkt.WriteBool(Rabbit.IsBaby());
751 
752  a_Pkt.WriteBEUInt8(RABBIT_TYPE);
754  a_Pkt.WriteVarInt32(static_cast<UInt32>(Rabbit.GetRabbitType()));
755  break;
756  } // case mtRabbit
757 
758  case mtSheep:
759  {
760  auto & Sheep = static_cast<const cSheep &>(a_Mob);
761 
762  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
764  a_Pkt.WriteBool(Sheep.IsBaby());
765 
766  a_Pkt.WriteBEUInt8(SHEEP_STATUS);
768  Int8 SheepMetadata = 0;
769  SheepMetadata = static_cast<Int8>(Sheep.GetFurColor());
770  if (Sheep.IsSheared())
771  {
772  SheepMetadata |= 0x10;
773  }
774  a_Pkt.WriteBEInt8(SheepMetadata);
775  break;
776  } // case mtSheep
777 
778  case mtSkeleton:
779  {
780  auto & Skeleton = static_cast<const cSkeleton &>(a_Mob);
783  a_Pkt.WriteBEUInt8(Skeleton.IsChargingBow() ? 0x01 : 0x00);
784 
787  a_Pkt.WriteBool(Skeleton.IsChargingBow());
788  break;
789  } // case mtSkeleton
790 
791  case mtSlime:
792  {
793  auto & Slime = static_cast<const cSlime &>(a_Mob);
794  a_Pkt.WriteBEUInt8(SLIME_SIZE);
796  a_Pkt.WriteVarInt32(static_cast<UInt32>(Slime.GetSize()));
797  break;
798  } // case mtSlime
799 
800  case mtVillager:
801  {
802  auto & Villager = static_cast<const cVillager &>(a_Mob);
803  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
805  a_Pkt.WriteBool(Villager.IsBaby());
806 
809  a_Pkt.WriteVarInt32(static_cast<UInt32>(Villager.GetVilType()));
810  break;
811  } // case mtVillager
812 
813  case mtWitch:
814  {
815  auto & Witch = static_cast<const cWitch &>(a_Mob);
818  a_Pkt.WriteBool(Witch.IsAngry());
819  break;
820  } // case mtWitch
821 
822  case mtWither:
823  {
824  auto & Wither = static_cast<const cWither &>(a_Mob);
827  a_Pkt.WriteVarInt32(Wither.GetWitherInvulnerableTicks());
828 
829  // TODO: Use boss bar packet for health
830  break;
831  } // case mtWither
832 
833  case mtWolf:
834  {
835  auto & Wolf = static_cast<const cWolf &>(a_Mob);
836  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
838  a_Pkt.WriteBool(Wolf.IsBaby());
839 
840  Int8 WolfStatus = 0;
841  if (Wolf.IsSitting())
842  {
843  WolfStatus |= 0x1;
844  }
845  if (Wolf.IsAngry())
846  {
847  WolfStatus |= 0x2;
848  }
849  if (Wolf.IsTame())
850  {
851  WolfStatus |= 0x4;
852  }
855  a_Pkt.WriteBEInt8(WolfStatus);
856 
859  a_Pkt.WriteBEFloat(static_cast<float>(a_Mob.GetHealth())); // TODO Not use the current health
860 
861  a_Pkt.WriteBEUInt8(WOLF_BEGGING);
863  a_Pkt.WriteBool(Wolf.IsBegging());
864 
867  a_Pkt.WriteVarInt32(static_cast<UInt32>(Wolf.GetCollarColor()));
868  break;
869  } // case mtWolf
870 
871  case mtZombie:
872  {
873  // XXX Zombies were also split into new subclasses; this doesn't handle that.
874  auto & Zombie = static_cast<const cZombie &>(a_Mob);
877  a_Pkt.WriteBool(Zombie.IsBaby());
878 
879  // These don't exist
880  // a_Pkt.WriteBEUInt8(ZOMBIE_TYPE);
881  // a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT);
882  // a_Pkt.WriteVarInt32(Zombie.IsVillagerZombie() ? 1 : 0);
883 
884  break;
885  } // case mtZombie
886 
887  case mtZombiePigman:
888  {
889  auto & ZombiePigman = static_cast<const cZombiePigman &>(a_Mob);
890  a_Pkt.WriteBEUInt8(AGEABLE_BABY);
892  a_Pkt.WriteBool(ZombiePigman.IsBaby());
893  break;
894  } // case mtZombiePigman
895 
896  case mtZombieVillager:
897  {
898  auto & ZombieVillager = reinterpret_cast<const cZombieVillager &>(a_Mob);
901  a_Pkt.WriteBool(ZombieVillager.IsBaby());
902 
905  a_Pkt.WriteVarInt32(static_cast<UInt32>(ZombieVillager.ConversionTime()));
906 
909  a_Pkt.WriteVarInt32(static_cast<UInt32>(ZombieVillager.GetProfession()));
910  break;
911  } // case mtZombieVillager
912 
913  case mtBlaze:
914  case mtCaveSpider:
915  case mtElderGuardian:
916  case mtEnderDragon:
917  case mtGuardian:
918  case mtIronGolem:
919  case mtSnowGolem:
920  case mtSpider:
921  case mtWitherSkeleton:
922  {
923  // TODO: Mobs with extra fields that aren't implemented
924  break;
925  }
926 
927  case mtMooshroom:
928  {
929  // Not mentioned on http://wiki.vg/Entities
930  break;
931  }
932 
933  case mtCat:
934 
935  case mtDonkey:
936  case mtMule:
937 
938  case mtEvoker:
939 
940  case mtHusk:
941 
942  case mtIllusioner:
943 
944  case mtLlama:
945 
946  case mtParrot:
947 
948  case mtPolarBear:
949 
950  case mtShulker:
951 
952  case mtSkeletonHorse:
953  case mtZombieHorse:
954 
955  case mtStray:
956 
957  case mtVex:
958 
959  case mtVindicator:
960  {
961  // Todo: Mobs not added yet. Grouped ones have the same metadata
962  ASSERT(!"cProtocol_1_12::WriteMobMetadata: received unimplemented type");
963  break;
964  }
965 
966  case mtEndermite:
967  case mtGiant:
968  case mtSilverfish:
969  case mtSquid:
970  {
971  // Mobs with no extra fields
972  break;
973  }
974 
975  default: UNREACHABLE("cProtocol_1_12::WriteMobMetadata: received mob of invalid type");
976  } // switch (a_Mob.GetType())
977 }
978 
979 
980 
981 
982 
984 {
985  switch (a_Packet)
986  {
987  case pktAttachEntity: return 0x42;
988  case pktCameraSetTo: return 0x38;
989  case pktCollectEntity: return 0x4a;
990  case pktDestroyEntity: return 0x31;
991  case pktDisplayObjective: return 0x3a;
992  case pktEntityEffect: return 0x4e;
993  case pktEntityEquipment: return 0x3e;
994  case pktEntityHeadLook: return 0x35;
995  case pktEntityLook: return 0x28;
996  case pktEntityMeta: return 0x3b;
997  case pktEntityProperties: return 0x4d;
998  case pktEntityRelMove: return 0x26;
999  case pktEntityRelMoveLook: return 0x27;
1000  case pktEntityVelocity: return 0x3d;
1001  case pktExperience: return 0x3f;
1002  case pktHeldItemChange: return 0x39;
1003  case pktLeashEntity: return 0x3c;
1004  case pktRemoveEntityEffect: return 0x32;
1005  case pktResourcePack: return 0x33;
1006  case pktRespawn: return 0x34;
1007  case pktScoreboardObjective: return 0x41;
1008  case pktSpawnPosition: return 0x45;
1009  case pktTeleportEntity: return 0x4b;
1010  case pktTimeUpdate: return 0x46;
1011  case pktTitle: return 0x47;
1012  case pktUnlockRecipe: return 0x30;
1013  case pktUpdateBlockEntity: return 0x09;
1014  case pktUpdateHealth: return 0x40;
1015  case pktUpdateScore: return 0x44;
1016 
1017  default: return Super::GetPacketID(a_Packet);
1018  }
1019 }
1020 
1021 
1022 
1023 
1024 
1026 {
1027  HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, WindowID);
1028  HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, RecipeID);
1029  HANDLE_READ(a_ByteBuffer, ReadBool, bool, MakeAll);
1030  auto CuberiteRecipeId = cRoot::Get()->GetRecipeMapper()->GetCuberiteRecipeId(RecipeID, m_Client->GetProtocolVersion());
1031  if (CuberiteRecipeId.has_value())
1032  {
1033  m_Client->HandleCraftRecipe(CuberiteRecipeId.value());
1034  }
1035 }
1036 
1037 
1038 
1039 
1040 
1042 {
1043  // TODO not yet used, not sure if it is needed
1044  // https://wiki.vg/index.php?title=Protocol&oldid=14204#Crafting_Book_Data
1045  a_ByteBuffer.SkipRead(a_ByteBuffer.GetReadableSpace());
1046 }
1047 
1048 
1049 
1050 
1051 
1053 {
1054  a_ByteBuffer.SkipRead(a_ByteBuffer.GetReadableSpace());
1055  m_Client->GetPlayer()->SendMessageInfo("The new advancements are not implemented.");
1056 }
1057 
1058 
1059 
1060 
1061 
1063 {
1064  switch (a_Animation)
1065  {
1066  case EntityAnimation::PawnBurns: return 37;
1067  case EntityAnimation::PawnDrowns: return 36;
1068  default: return Super::GetProtocolEntityStatus(a_Animation);
1069  }
1070 }
1071 
1072 
1073 
1074 
1075 
1077 {
1078  switch (a_MobType)
1079  {
1080  case mtIllusioner: return 37;
1081  case mtParrot: return 105;
1082  default: return Super::GetProtocolMobType(a_MobType);
1083  }
1084 }
1085 
1086 
1087 
1088 
1089 
1091 {
1092  return Version::v1_12;
1093 }
1094 
1095 
1096 
1097 
1098 
1099 bool cProtocol_1_12::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
1100 {
1101  switch (m_State)
1102  {
1103  case State::Status:
1104  {
1105  switch (a_PacketType)
1106  {
1107  case 0x00: HandlePacketStatusRequest(a_ByteBuffer); return true;
1108  case 0x01: HandlePacketStatusPing(a_ByteBuffer); return true;
1109  }
1110  break;
1111  }
1112 
1113  case State::Login:
1114  {
1115  switch (a_PacketType)
1116  {
1117  case 0x00: HandlePacketLoginStart(a_ByteBuffer); return true;
1118  case 0x01: HandlePacketLoginEncryptionResponse(a_ByteBuffer); return true;
1119  }
1120  break;
1121  }
1122 
1123  case State::Game:
1124  {
1125  switch (a_PacketType)
1126  {
1127  case 0x00: HandleConfirmTeleport(a_ByteBuffer); return true;
1128  case 0x01: break; // Prepare Crafting Grid, not yet implemented
1129  case 0x02: HandlePacketTabComplete(a_ByteBuffer); return true;
1130  case 0x03: HandlePacketChatMessage(a_ByteBuffer); return true;
1131  case 0x04: HandlePacketClientStatus(a_ByteBuffer); return true;
1132  case 0x05: HandlePacketClientSettings(a_ByteBuffer); return true;
1133  case 0x06: break; // Confirm transaction - not used in Cuberite
1134  case 0x07: HandlePacketEnchantItem(a_ByteBuffer); return true;
1135  case 0x08: HandlePacketWindowClick(a_ByteBuffer); return true;
1136  case 0x09: HandlePacketWindowClose(a_ByteBuffer); return true;
1137  case 0x0a: HandlePacketPluginMessage(a_ByteBuffer); return true;
1138  case 0x0b: HandlePacketUseEntity(a_ByteBuffer); return true;
1139  case 0x0c: HandlePacketKeepAlive(a_ByteBuffer); return true;
1140  case 0x0d: HandlePacketPlayer(a_ByteBuffer); return true;
1141  case 0x0e: HandlePacketPlayerPos(a_ByteBuffer); return true;
1142  case 0x0f: HandlePacketPlayerPosLook(a_ByteBuffer); return true;
1143  case 0x10: HandlePacketPlayerLook(a_ByteBuffer); return true;
1144  case 0x11: HandlePacketVehicleMove(a_ByteBuffer); return true;
1145  case 0x12: HandlePacketBoatSteer(a_ByteBuffer); return true;
1146  case 0x13: HandlePacketPlayerAbilities(a_ByteBuffer); return true;
1147  case 0x14: HandlePacketBlockDig(a_ByteBuffer); return true;
1148  case 0x15: HandlePacketEntityAction(a_ByteBuffer); return true;
1149  case 0x16: HandlePacketSteerVehicle(a_ByteBuffer); return true;
1150  case 0x17: HandlePacketCraftingBookData(a_ByteBuffer); return true;
1151  case 0x18: HandlePacketResourcePackStatus(a_ByteBuffer); return true;
1152  case 0x19: HandlePacketAdvancementTab(a_ByteBuffer); return true;
1153  case 0x1a: HandlePacketSlotSelect(a_ByteBuffer); return true;
1154  case 0x1b: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true;
1155  case 0x1c: HandlePacketUpdateSign(a_ByteBuffer); return true;
1156  case 0x1d: HandlePacketAnimation(a_ByteBuffer); return true;
1157  case 0x1e: HandlePacketSpectate(a_ByteBuffer); return true;
1158  case 0x1f: HandlePacketBlockPlace(a_ByteBuffer); return true;
1159  case 0x20: HandlePacketUseItem(a_ByteBuffer); return true;
1160  }
1161  break;
1162  }
1163  } // switch (m_State)
1164 
1165  // Unknown packet type, report to the ClientHandle:
1166  m_Client->PacketUnknown(a_PacketType);
1167  return false;
1168 }
1169 
1170 
1171 
1172 
1173 
1175 // cProtocol_1_12_1:
1176 
1178 {
1179  switch (a_Packet)
1180  {
1181  case pktAttachEntity: return 0x43;
1182  case pktCameraSetTo: return 0x39;
1183  case pktCollectEntity: return 0x4b;
1184  case pktDestroyEntity: return 0x32;
1185  case pktDisplayObjective: return 0x3b;
1186  case pktEntityEffect: return 0x4f;
1187  case pktEntityEquipment: return 0x3f;
1188  case pktEntityHeadLook: return 0x36;
1189  case pktEntityMeta: return 0x3c;
1190  case pktEntityProperties: return 0x4e;
1191  case pktEntityVelocity: return 0x3e;
1192  case pktExperience: return 0x40;
1193  case pktHeldItemChange: return 0x3a;
1194  case pktLeashEntity: return 0x3d;
1195  case pktPlayerList: return 0x2e;
1196  case pktPlayerListHeaderFooter: return 0x4a;
1197  case pktPlayerAbilities: return 0x2c;
1198  case pktPlayerMoveLook: return 0x2f;
1199  case pktRemoveEntityEffect: return 0x33;
1200  case pktResourcePack: return 0x34;
1201  case pktRespawn: return 0x35;
1202  case pktScoreboardObjective: return 0x42;
1203  case pktSpawnPosition: return 0x46;
1204  case pktUnlockRecipe: return 0x31;
1205  case pktUpdateHealth: return 0x41;
1206  case pktUpdateScore: return 0x45;
1207  case pktUseBed: return 0x30;
1208  case pktTeleportEntity: return 0x4c;
1209  case pktTimeUpdate: return 0x47;
1210  case pktTitle: return 0x48;
1211 
1212  default: return Super::GetPacketID(a_Packet);
1213  }
1214 }
1215 
1216 
1217 
1218 
1219 
1221 {
1222  return Version::v1_12_1;
1223 }
1224 
1225 
1226 
1227 
1228 
1229 bool cProtocol_1_12_1::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
1230 {
1231  switch (m_State)
1232  {
1233  case State::Status:
1234  {
1235  switch (a_PacketType)
1236  {
1237  case 0x00: HandlePacketStatusRequest(a_ByteBuffer); return true;
1238  case 0x01: HandlePacketStatusPing(a_ByteBuffer); return true;
1239  }
1240  break;
1241  }
1242 
1243  case State::Login:
1244  {
1245  switch (a_PacketType)
1246  {
1247  case 0x00: HandlePacketLoginStart(a_ByteBuffer); return true;
1248  case 0x01: HandlePacketLoginEncryptionResponse(a_ByteBuffer); return true;
1249  }
1250  break;
1251  }
1252 
1253  case State::Game:
1254  {
1255  switch (a_PacketType)
1256  {
1257  case 0x00: HandleConfirmTeleport(a_ByteBuffer); return true;
1258  case 0x01: HandlePacketTabComplete(a_ByteBuffer); return true;
1259  case 0x02: HandlePacketChatMessage(a_ByteBuffer); return true;
1260  case 0x03: HandlePacketClientStatus(a_ByteBuffer); return true;
1261  case 0x04: HandlePacketClientSettings(a_ByteBuffer); return true;
1262  case 0x05: break; // Confirm transaction - not used in Cuberite
1263  case 0x06: HandlePacketEnchantItem(a_ByteBuffer); return true;
1264  case 0x07: HandlePacketWindowClick(a_ByteBuffer); return true;
1265  case 0x08: HandlePacketWindowClose(a_ByteBuffer); return true;
1266  case 0x09: HandlePacketPluginMessage(a_ByteBuffer); return true;
1267  case 0x0a: HandlePacketUseEntity(a_ByteBuffer); return true;
1268  case 0x0b: HandlePacketKeepAlive(a_ByteBuffer); return true;
1269  case 0x0c: HandlePacketPlayer(a_ByteBuffer); return true;
1270  case 0x0d: HandlePacketPlayerPos(a_ByteBuffer); return true;
1271  case 0x0e: HandlePacketPlayerPosLook(a_ByteBuffer); return true;
1272  case 0x0f: HandlePacketPlayerLook(a_ByteBuffer); return true;
1273  case 0x10: HandlePacketVehicleMove(a_ByteBuffer); return true;
1274  case 0x11: HandlePacketBoatSteer(a_ByteBuffer); return true;
1275  case 0x12: HandleCraftRecipe(a_ByteBuffer); return true;
1276  case 0x13: HandlePacketPlayerAbilities(a_ByteBuffer); return true;
1277  case 0x14: HandlePacketBlockDig(a_ByteBuffer); return true;
1278  case 0x15: HandlePacketEntityAction(a_ByteBuffer); return true;
1279  case 0x16: HandlePacketSteerVehicle(a_ByteBuffer); return true;
1280  case 0x17: HandlePacketCraftingBookData(a_ByteBuffer); return true;
1281  case 0x18: HandlePacketResourcePackStatus(a_ByteBuffer); return true;
1282  case 0x19: HandlePacketAdvancementTab(a_ByteBuffer); return true;
1283  case 0x1a: HandlePacketSlotSelect(a_ByteBuffer); return true;
1284  case 0x1b: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true;
1285  case 0x1c: HandlePacketUpdateSign(a_ByteBuffer); return true;
1286  case 0x1d: HandlePacketAnimation(a_ByteBuffer); return true;
1287  case 0x1e: HandlePacketSpectate(a_ByteBuffer); return true;
1288  case 0x1f: HandlePacketBlockPlace(a_ByteBuffer); return true;
1289  case 0x20: HandlePacketUseItem(a_ByteBuffer); return true;
1290  }
1291  break;
1292  }
1293  } // switch (m_State)
1294 
1295  // Unknown packet type, report to the ClientHandle:
1296  m_Client->PacketUnknown(a_PacketType);
1297  return false;
1298 }
1299 
1300 
1301 
1302 
1304 // cProtocol_1_12_2::
1305 
1307 {
1308  return Version::v1_12_2;
1309 }
1310 
1311 
1312 
1313 
1314 
1316 {
1317  HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, KeepAliveID);
1318  if (
1319  (KeepAliveID <= std::numeric_limits<UInt32>::max()) &&
1320  (KeepAliveID >= 0)
1321  )
1322  {
1323  // The server will only send a UInt32 so any value out of that range shouldn't keep the client alive.
1324  m_Client->HandleKeepAlive(static_cast<UInt32>(KeepAliveID));
1325  }
1326 }
1327 
1328 
1329 
1330 
1331 
1333 {
1334  // Drop the packet if the protocol is not in the Game state yet (caused a client crash):
1335  if (m_State != 3)
1336  {
1337  LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State);
1338  return;
1339  }
1340 
1341  cPacketizer Pkt(*this, pktKeepAlive);
1342  Pkt.WriteBEInt64(a_PingID);
1343 }
1344 
1345 
1346 
1347 
1348 
1350 {
1351  ASSERT(m_State == 3); // In game mode?
1352 
1353  auto ProtocolRecipeId = cRoot::Get()->GetRecipeMapper()->GetProtocolRecipeId(a_RecipeID, m_Client->GetProtocolVersion());
1354  if (ProtocolRecipeId.has_value())
1355  {
1356  cPacketizer Pkt(*this, pktUnlockRecipe);
1357  Pkt.WriteVarInt32(1);
1358  Pkt.WriteBool(true);
1359  Pkt.WriteBool(false);
1360  Pkt.WriteVarInt32(1);
1361  Pkt.WriteVarInt32(ProtocolRecipeId.value());
1362  }
1363 }
1364 
1365 
1366 
1367 
1368 
1370 {
1371  ASSERT(m_State == 3); // In game mode?
1372 
1373  auto ProtocolRecipeId = cRoot::Get()->GetRecipeMapper()->GetProtocolRecipeId(a_RecipeID, m_Client->GetProtocolVersion());
1374  if (!ProtocolRecipeId.has_value())
1375  {
1376  return;
1377  }
1378 
1379  cPacketizer Pkt(*this, pktUnlockRecipe);
1380  Pkt.WriteVarInt32(0);
1381  Pkt.WriteBool(true);
1382  Pkt.WriteBool(false);
1383  if (a_RecipeID == 0)
1384  {
1385  Pkt.WriteVarInt32(0);
1386  Pkt.WriteVarInt32(0);
1387  }
1388  else
1389  {
1390  Pkt.WriteVarInt32(1);
1391  Pkt.WriteVarInt32(ProtocolRecipeId.value());
1392  Pkt.WriteVarInt32(1);
1393  Pkt.WriteVarInt32(ProtocolRecipeId.value());
1394  }
1395 }
EntityAnimation
Definition: Defines.h:458
#define UNREACHABLE(x)
Definition: Globals.h:288
unsigned int UInt32
Definition: Globals.h:157
signed long long Int64
Definition: Globals.h:151
signed char Int8
Definition: Globals.h:154
unsigned char UInt8
Definition: Globals.h:159
#define ASSERT(x)
Definition: Globals.h:276
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
eMonsterType
Identifies individual monster type.
Definition: MonsterTypes.h:11
@ mtZombieVillager
Definition: MonsterTypes.h:82
@ mtVindicator
Definition: MonsterTypes.h:72
@ mtElderGuardian
Definition: MonsterTypes.h:25
@ mtSkeleton
Definition: MonsterTypes.h:59
@ mtSheep
Definition: MonsterTypes.h:56
@ mtEndermite
Definition: MonsterTypes.h:28
@ mtPolarBear
Definition: MonsterTypes.h:51
@ mtMagmaCube
Definition: MonsterTypes.h:40
@ mtWolf
Definition: MonsterTypes.h:77
@ mtStray
Definition: MonsterTypes.h:65
@ mtRabbit
Definition: MonsterTypes.h:53
@ mtCat
Definition: MonsterTypes.h:16
@ mtZombie
Definition: MonsterTypes.h:79
@ mtOcelot
Definition: MonsterTypes.h:43
@ mtDonkey
Definition: MonsterTypes.h:23
@ mtVex
Definition: MonsterTypes.h:70
@ mtEnderman
Definition: MonsterTypes.h:27
@ mtHusk
Definition: MonsterTypes.h:36
@ mtCaveSpider
Definition: MonsterTypes.h:17
@ mtEvoker
Definition: MonsterTypes.h:29
@ mtShulker
Definition: MonsterTypes.h:57
@ mtWither
Definition: MonsterTypes.h:75
@ mtSkeletonHorse
Definition: MonsterTypes.h:60
@ mtPig
Definition: MonsterTypes.h:47
@ mtVillager
Definition: MonsterTypes.h:71
@ mtHorse
Definition: MonsterTypes.h:34
@ mtZombieHorse
Definition: MonsterTypes.h:80
@ mtWitch
Definition: MonsterTypes.h:74
@ mtCow
Definition: MonsterTypes.h:20
@ mtEnderDragon
Definition: MonsterTypes.h:26
@ mtMooshroom
Definition: MonsterTypes.h:41
@ mtSquid
Definition: MonsterTypes.h:64
@ mtBat
Definition: MonsterTypes.h:14
@ mtIllusioner
Definition: MonsterTypes.h:37
@ mtChicken
Definition: MonsterTypes.h:18
@ mtGiant
Definition: MonsterTypes.h:32
@ mtSnowGolem
Definition: MonsterTypes.h:62
@ mtBlaze
Definition: MonsterTypes.h:15
@ mtLlama
Definition: MonsterTypes.h:39
@ mtIronGolem
Definition: MonsterTypes.h:38
@ mtCreeper
Definition: MonsterTypes.h:21
@ mtSpider
Definition: MonsterTypes.h:63
@ mtMule
Definition: MonsterTypes.h:42
@ mtGhast
Definition: MonsterTypes.h:31
@ mtParrot
Definition: MonsterTypes.h:45
@ mtSilverfish
Definition: MonsterTypes.h:58
@ mtZombiePigman
Definition: MonsterTypes.h:85
@ mtSlime
Definition: MonsterTypes.h:61
@ mtWitherSkeleton
Definition: MonsterTypes.h:76
@ mtGuardian
Definition: MonsterTypes.h:33
#define HANDLE_READ(ByteBuf, Proc, Type, Var)
Macros used to read packets more easily.
Definition: Packetizer.h:28
@ Rabbit
@ Chicken
@ Minecart
@ AREA_EFFECT_CLOUD_PARTICLE_PARAMETER2
@ MINECART_COMMAND_BLOCK_LAST_OUTPUT
@ AREA_EFFECT_CLOUD_PARTICLE_ID
@ ARMOR_STAND_RIGHT_ARM_ROTATION
@ AREA_EFFECT_CLOUD_PARTICLE_PARAMETER1
@ SHULKER_ATTACHMENT_FALLING_BLOCK_POSITION
@ ABSTRACT_SKELETON_ARMS_SWINGING
@ MINECART_COMMAND_BLOCK_COMMAND
@ ARMOR_STAND_RIGHT_LEG_ROTATION
@ PIG_TOTAL_CARROT_ON_A_STICK_BOOST
@ AREA_EFFECT_CLOUD_SINGLE_POINT_EFFECT
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes ar...
Definition: ByteBuffer.h:32
bool SkipRead(size_t a_Count)
Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer.
Definition: ByteBuffer.cpp:961
size_t GetReadableSpace(void) const
Returns the number of bytes that are currently available for reading (may be less than UsedSpace due ...
Definition: ByteBuffer.cpp:198
void PacketUnknown(UInt32 a_PacketType)
void HandleKeepAlive(UInt32 a_KeepAliveID)
UInt32 GetProtocolVersion(void) const
Returns the protocol version number of the protocol that the client is talking.
Definition: ClientHandle.h:422
cPlayer * GetPlayer(void)
Definition: ClientHandle.h:78
void HandleCraftRecipe(UInt32 a_RecipeId)
Called when a recipe from the recipe book is selected.
bool IsCritical(void) const
Returns true if the arrow is set as critical.
Definition: ArrowEntity.h:70
Definition: Boat.h:20
Definition: Entity.h:76
virtual bool IsElytraFlying(void) const
Definition: Entity.h:487
virtual bool IsRclking(void) const
Definition: Entity.h:490
virtual bool IsCrouched(void) const
Definition: Entity.h:486
float GetMaxHealth(void) const
Definition: Entity.h:407
eEntityType GetEntityType(void) const
Definition: Entity.h:156
virtual bool IsOnFire(void) const
Definition: Entity.h:489
virtual bool IsInvisible(void) const
Definition: Entity.h:488
float GetHealth(void) const
Returns the health of this entity.
Definition: Entity.h:367
@ etPickup
Definition: Entity.h:93
@ etProjectile
Definition: Entity.h:99
@ etItemFrame
Definition: Entity.h:102
@ etMinecart
Definition: Entity.h:96
@ etEnderCrystal
Definition: Entity.h:91
@ etMonster
Definition: Entity.h:94
@ etBoat
Definition: Entity.h:97
@ etPlayer
Definition: Entity.h:92
virtual bool IsSprinting(void) const
Definition: Entity.h:492
@ mpNone
Definition: Minecart.h:31
@ mpFurnace
Definition: Minecart.h:33
bool IsFueled(void) const
Definition: Minecart.h:201
Definition: Pickup.h:20
Definition: Player.h:29
void SendMessageInfo(const AString &a_Message)
Definition: Player.cpp:1191
Definition: Item.h:37
bool IsEmpty(void) const
Returns true if the item represents an empty stack - either the type is invalid, or count is zero.
Definition: Item.h:69
short m_ItemType
Definition: Item.h:163
short m_ItemDamage
Definition: Item.h:165
Definition: Bat.h:12
Definition: Cow.h:12
Definition: Ghast.h:12
Definition: Horse.h:14
bool HasCustomName(void) const
Returns true if the monster has a custom name.
Definition: Monster.h:165
const AString & GetCustomName(void) const
Gets the custom name of the monster.
Definition: Monster.h:168
bool IsCustomNameAlwaysVisible(void) const
Is the custom name of this monster always visible? If not, you only see the name when you sight the m...
Definition: Monster.h:175
eMonsterType GetMobType(void) const
Definition: Monster.h:70
Definition: Ocelot.h:13
Definition: Pig.h:12
Definition: Rabbit.h:27
Definition: Sheep.h:12
Definition: Slime.h:12
Definition: Witch.h:12
Definition: Wither.h:12
Definition: Wolf.h:14
Definition: Zombie.h:11
Composes an individual packet in the protocol's m_OutPacketBuffer; sends it just before being destruc...
Definition: Packetizer.h:60
void WriteVarInt32(UInt32 a_Value)
Definition: Packetizer.h:141
void WriteBool(bool a_Value)
Definition: Packetizer.h:76
void WriteXYZPosition64(int a_BlockX, int a_BlockY, int a_BlockZ)
Writes the specified block position as a single encoded 64-bit BigEndian integer.
Definition: Packetizer.h:161
void WriteBEFloat(float a_Value)
Definition: Packetizer.h:129
void WriteString(const AString &a_Value)
Definition: Packetizer.h:147
void WriteBEUInt8(UInt8 a_Value)
Definition: Packetizer.h:81
void WriteBEInt64(Int64 a_Value)
Definition: Packetizer.h:117
void WriteBEInt8(Int8 a_Value)
Definition: Packetizer.h:87
ePacketType
Logical types of outgoing packets.
Definition: Protocol.h:57
@ pktEntityHeadLook
Definition: Protocol.h:77
@ pktEntityRelMove
Definition: Protocol.h:81
@ pktEntityVelocity
Definition: Protocol.h:84
@ pktEntityMeta
Definition: Protocol.h:79
@ pktAttachEntity
Definition: Protocol.h:58
@ pktDisplayObjective
Definition: Protocol.h:71
@ pktUseBed
Definition: Protocol.h:129
@ pktResourcePack
Definition: Protocol.h:104
@ pktKeepAlive
Definition: Protocol.h:92
@ pktCameraSetTo
Definition: Protocol.h:64
@ pktEntityEffect
Definition: Protocol.h:75
@ pktTeleportEntity
Definition: Protocol.h:120
@ pktUpdateBlockEntity
Definition: Protocol.h:125
@ pktPlayerMoveLook
Definition: Protocol.h:101
@ pktSpawnPosition
Definition: Protocol.h:115
@ pktTimeUpdate
Definition: Protocol.h:121
@ pktPlayerList
Definition: Protocol.h:99
@ pktEntityRelMoveLook
Definition: Protocol.h:82
@ pktDestroyEntity
Definition: Protocol.h:67
@ pktUpdateHealth
Definition: Protocol.h:126
@ pktUpdateScore
Definition: Protocol.h:127
@ pktEntityEquipment
Definition: Protocol.h:76
@ pktRespawn
Definition: Protocol.h:105
@ pktEntityProperties
Definition: Protocol.h:80
@ pktScoreboardObjective
Definition: Protocol.h:106
@ pktCollectEntity
Definition: Protocol.h:66
@ pktRemoveEntityEffect
Definition: Protocol.h:103
@ pktUnlockRecipe
Definition: Protocol.h:124
@ pktHeldItemChange
Definition: Protocol.h:88
@ pktPlayerListHeaderFooter
Definition: Protocol.h:100
@ pktEntityLook
Definition: Protocol.h:78
@ pktTitle
Definition: Protocol.h:122
@ pktPlayerAbilities
Definition: Protocol.h:98
@ pktExperience
Definition: Protocol.h:85
@ pktLeashEntity
Definition: Protocol.h:93
Version
The protocol version number, received from the client in the Handshake packet.
Definition: Protocol.h:335
cClientHandle * m_Client
Definition: Protocol.h:472
virtual void HandlePacketResourcePackStatus(cByteBuffer &a_ByteBuffer) override
virtual signed char GetProtocolEntityStatus(EntityAnimation a_Animation) const override
Converts an animation into an ID suitable for use with the Entity Status packet.
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) const override
Converts eMonsterType to protocol-specific mob types.
virtual void HandlePacketBlockPlace(cByteBuffer &a_ByteBuffer) override
virtual void HandleCraftRecipe(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketAdvancementTab(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketCraftingBookData(cByteBuffer &a_ByteBuffer)
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual void WriteMobMetadata(cPacketizer &a_Pkt, const cMonster &a_Mob) const override
Writes the mob-specific metadata for the specified mob.
virtual signed char GetProtocolEntityStatus(EntityAnimation a_Animation) const override
Converts an animation into an ID suitable for use with the Entity Status packet.
virtual UInt32 GetPacketID(ePacketType a_Packet) const override
Get the packet ID for a given packet.
virtual void WriteEntityMetadata(cPacketizer &a_Pkt, const cEntity &a_Entity) const override
Writes the metadata for the specified entity, not including the terminating 0x7f.
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) const override
Converts eMonsterType to protocol-specific mob types.
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual UInt32 GetPacketID(ePacketType a_Packet) const override
Get the packet ID for a given packet.
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer) override
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual void SendKeepAlive(UInt32 a_PingID) override
virtual void SendInitRecipes(UInt32 a_RecipeID) override
virtual void SendUnlockRecipe(UInt32 a_RecipeID) override
virtual void HandlePacketPlayer(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketStatusPing(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketLoginEncryptionResponse(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketEnchantItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketLoginStart(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketCreativeInventoryAction(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketWindowClose(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketPluginMessage(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketPlayerAbilities(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketChatMessage(cByteBuffer &a_ByteBuffer)
State m_State
State of the protocol.
Definition: Protocol_1_8.h:143
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketPlayerLook(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketClientStatus(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSlotSelect(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSpectate(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSteerVehicle(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketUseEntity(cByteBuffer &a_ByteBuffer) override
virtual void WriteItem(cPacketizer &a_Pkt, const cItem &a_Item) const override
Writes the item data into a packet.
virtual void HandlePacketPlayerPos(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketUseItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketWindowClick(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketClientSettings(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketEntityAction(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketPlayerPosLook(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketBoatSteer(cByteBuffer &a_ByteBuffer)
virtual void HandleConfirmTeleport(cByteBuffer &a_ByteBuffer)
@ METADATA_TYPE_OPTIONAL_POSITION
Definition: Protocol_1_9.h:116
virtual void HandlePacketUpdateSign(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketBlockDig(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketAnimation(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketVehicleMove(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketTabComplete(cByteBuffer &a_ByteBuffer) override
virtual UInt32 GetPacketID(ePacketType a_Packet) const override
Get the packet ID for a given packet.
std::optional< UInt32 > GetProtocolRecipeId(UInt32 a_RecipeId, UInt32 a_ProtocolVersion)
Translates the cuberite RecipeId to the protocol specific RecipeId.
std::optional< UInt32 > GetCuberiteRecipeId(UInt32 a_ProtocolRecipeId, UInt32 a_ProtocolVersion)
Translates the protocol specific RecipeId to the cuberite RecipeId.
static cRoot * Get()
Definition: Root.h:52
cRecipeMapper * GetRecipeMapper(void)
Definition: Root.h:93