diff options
Diffstat (limited to 'src/Protocol/Protocol18x.cpp')
-rw-r--r-- | src/Protocol/Protocol18x.cpp | 136 |
1 files changed, 75 insertions, 61 deletions
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 63fa91b01..f4f32dfdb 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -715,60 +715,31 @@ void cProtocol180::SendPaintingSpawn(const cPainting & a_Painting) -void cProtocol180::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) +void cProtocol180::SendMapData(const cMap & a_Map, int a_DataStartX, int a_DataStartY) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x34); - Pkt.WriteVarInt32(a_ID); - Pkt.WriteBEUInt8(m_Scale); + Pkt.WriteVarInt32(a_Map.GetID()); + Pkt.WriteBEUInt8(a_Map.GetScale()); - Pkt.WriteVarInt32(0); - Pkt.WriteBEUInt8(1); - Pkt.WriteBEUInt8(a_Length); - Pkt.WriteBEUInt8(a_X); - Pkt.WriteBEUInt8(a_Y); - - Pkt.WriteVarInt32(a_Length); - for (unsigned int i = 0; i < a_Length; ++i) + Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetDecorators().size())); + for (const auto Decorator : a_Map.GetDecorators()) { - Pkt.WriteBEUInt8(a_Colors[i]); + Pkt.WriteBEUInt8(static_cast<Byte>((static_cast<int>(Decorator.GetType()) << 4) | (Decorator.GetRot() & 0xF))); + Pkt.WriteBEUInt8(Decorator.GetPixelX()); + Pkt.WriteBEUInt8(Decorator.GetPixelZ()); } -} - - - - - -void cProtocol180::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x34); - Pkt.WriteVarInt32(a_ID); - Pkt.WriteBEUInt8(m_Scale); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Decorators.size())); - for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) + Pkt.WriteBEUInt8(128); + Pkt.WriteBEUInt8(128); + Pkt.WriteBEUInt8(a_DataStartX); + Pkt.WriteBEUInt8(a_DataStartY); + Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetData().size())); + for (auto itr = a_Map.GetData().cbegin(); itr != a_Map.GetData().cend(); ++itr) { - Pkt.WriteBEUInt8((it->GetType() << 4) | (it->GetRot() & 0xf)); - Pkt.WriteBEUInt8(it->GetPixelX()); - Pkt.WriteBEUInt8(it->GetPixelZ()); + Pkt.WriteBEUInt8(*itr); } - - Pkt.WriteBEUInt8(0); -} - - - - - -void cProtocol180::SendMapInfo(int a_ID, unsigned int a_Scale) -{ - UNUSED(a_ID); - UNUSED(a_Scale); - - // This packet was removed in 1.8 } @@ -2898,6 +2869,10 @@ void cProtocol180::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) a_Item.m_Lore = Lore; } + else if ((NBT.GetType(displaytag) == TAG_Int) && (NBT.GetName(displaytag) == "color")) + { + a_Item.m_ItemColor.m_Color = static_cast<unsigned int>(NBT.GetInt(displaytag)); + } } } else if ((TagName == "Fireworks") || (TagName == "Explosion")) @@ -3047,12 +3022,13 @@ void cProtocol180::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) a_Pkt.WriteBEInt8(a_Item.m_ItemCount); a_Pkt.WriteBEInt16(a_Item.m_ItemDamage); - if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (a_Item.m_ItemType != E_ITEM_FIREWORK_ROCKET) && (a_Item.m_ItemType != E_ITEM_FIREWORK_STAR)) + if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (a_Item.m_ItemType != E_ITEM_FIREWORK_ROCKET) && (a_Item.m_ItemType != E_ITEM_FIREWORK_STAR) && !a_Item.m_ItemColor.IsValid()) { a_Pkt.WriteBEInt8(0); return; } + // Send the enchantments and custom names: cFastNBTWriter Writer; if (a_Item.m_RepairCost != 0) @@ -3064,9 +3040,14 @@ void cProtocol180::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench"; EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, Writer, TagName); } - if (!a_Item.IsBothNameAndLoreEmpty()) + if (!a_Item.IsBothNameAndLoreEmpty() || a_Item.m_ItemColor.IsValid()) { Writer.BeginCompound("display"); + if (a_Item.m_ItemColor.IsValid()) + { + Writer.AddInt("color", static_cast<int>(a_Item.m_ItemColor.m_Color)); + } + if (!a_Item.IsCustomNameEmpty()) { Writer.AddString("Name", a_Item.m_CustomName.c_str()); @@ -3354,7 +3335,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Bat.IsHanging() ? 1 : 0); break; } // case mtBat - + case mtCreeper: { auto & Creeper = reinterpret_cast<const cCreeper &>(a_Mob); @@ -3364,7 +3345,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Creeper.IsCharged() ? 1 : 0); break; } // case mtCreeper - + case mtEnderman: { auto & Enderman = reinterpret_cast<const cEnderman &>(a_Mob); @@ -3376,7 +3357,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Enderman.IsScreaming() ? 1 : 0); break; } // case mtEnderman - + case mtGhast: { auto & Ghast = reinterpret_cast<const cGhast &>(a_Mob); @@ -3384,7 +3365,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Ghast.IsCharging()); break; } // case mtGhast - + case mtHorse: { auto & Horse = reinterpret_cast<const cHorse &>(a_Mob); @@ -3401,10 +3382,6 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) { Flags |= 0x08; } - if (Horse.IsBaby()) - { - Flags |= 0x10; - } if (Horse.IsEating()) { Flags |= 0x20; @@ -3428,6 +3405,9 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEInt32(Appearance); a_Pkt.WriteBEUInt8(0x56); // Int at index 22 a_Pkt.WriteBEInt32(Horse.GetHorseArmour()); + + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Horse.GetAge()); break; } // case mtHorse @@ -3439,17 +3419,38 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) break; } // case mtMagmaCube + case mtOcelot: + { + auto & Ocelot = reinterpret_cast<const cOcelot &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Ocelot.GetAge()); + break; + } // case mtOcelot + case mtPig: { auto & Pig = reinterpret_cast<const cPig &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Pig.GetAge()); a_Pkt.WriteBEUInt8(0x10); a_Pkt.WriteBEUInt8(Pig.IsSaddled() ? 1 : 0); break; } // case mtPig - + + case mtRabbit: + { + auto & Rabbit = reinterpret_cast<const cRabbit &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Rabbit.GetAge()); + break; + } // case mtRabbit + case mtSheep: { auto & Sheep = reinterpret_cast<const cSheep &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Sheep.GetAge()); + a_Pkt.WriteBEUInt8(0x10); Byte SheepMetadata = 0; SheepMetadata = Sheep.GetFurColor(); @@ -3460,7 +3461,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(SheepMetadata); break; } // case mtSheep - + case mtSkeleton: { auto & Skeleton = reinterpret_cast<const cSkeleton &>(a_Mob); @@ -3468,7 +3469,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Skeleton.IsWither() ? 1 : 0); break; } // case mtSkeleton - + case mtSlime: { auto & Slime = reinterpret_cast<const cSlime &>(a_Mob); @@ -3482,9 +3483,11 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) auto & Villager = reinterpret_cast<const cVillager &>(a_Mob); a_Pkt.WriteBEUInt8(0x50); a_Pkt.WriteBEInt32(Villager.GetVilType()); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Villager.GetAge()); break; } // case mtVillager - + case mtWitch: { auto & Witch = reinterpret_cast<const cWitch &>(a_Mob); @@ -3502,7 +3505,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEFloat(static_cast<float>(a_Mob.GetHealth())); break; } // case mtWither - + case mtWolf: { auto & Wolf = reinterpret_cast<const cWolf &>(a_Mob); @@ -3528,20 +3531,31 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Wolf.IsBegging() ? 1 : 0); a_Pkt.WriteBEUInt8(0x14); a_Pkt.WriteBEUInt8(Wolf.GetCollarColor()); + + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Wolf.GetAge()); break; } // case mtWolf - + case mtZombie: { auto & Zombie = reinterpret_cast<const cZombie &>(a_Mob); a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEUInt8(Zombie.IsBaby() ? 1 : 0); + a_Pkt.WriteBEInt8(Zombie.IsBaby() ? 1 : -1); a_Pkt.WriteBEUInt8(0x0d); a_Pkt.WriteBEUInt8(Zombie.IsVillagerZombie() ? 1 : 0); a_Pkt.WriteBEUInt8(0x0e); a_Pkt.WriteBEUInt8(Zombie.IsConverting() ? 1 : 0); break; } // case mtZombie + + case mtZombiePigman: + { + auto & ZombiePigman = reinterpret_cast<const cZombiePigman &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(ZombiePigman.IsBaby() ? 1 : -1); + break; + } // case mtZombiePigman } // switch (a_Mob.GetType()) } |