From 5db6213f34318031ece7e2a6765f69564b671891 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 8 Oct 2013 19:20:49 +0100 Subject: Initial Metadata Commit [SEE DESC] + Pigs, Minecarts, Sheep, Skeletons, Slimes, Villagers, Wolves, and Horses have metadata + Base code on taming wolves, shearing sheep, and taming horses + Sheep and horses have different colours when spawned --- source/Protocol/Protocol125.cpp | 220 +++++++++++++++++++++++++++++++++++----- source/Protocol/Protocol125.h | 7 +- source/Protocol/Protocol132.cpp | 3 +- 3 files changed, 195 insertions(+), 35 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 54bd28c9f..89b2c15ec 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -343,8 +343,9 @@ void cProtocol125::SendEntityMetadata(const cEntity & a_Entity) cCSLock Lock(m_CSPacket); WriteByte(PACKET_METADATA); WriteInt (a_Entity.GetUniqueID()); - AString MetaData = GetEntityMetaData(a_Entity); - SendData(MetaData.data(), MetaData.size()); + + WriteMetadata(a_Entity); + Flush(); } @@ -710,8 +711,7 @@ void cProtocol125::SendSpawnMob(const cMonster & a_Mob) WriteByte (0); WriteByte (0); WriteByte (0); - AString MetaData = GetEntityMetaData(a_Mob); - SendData (MetaData.data(), MetaData.size()); + WriteMetadata(a_Mob); Flush(); } @@ -1614,48 +1614,212 @@ int cProtocol125::ParseItem(cItem & a_Item) -AString cProtocol125::GetEntityMetaData(const cEntity & a_Entity) +void cProtocol125::WriteMetadata(const cEntity & a_Entity) { - // We should send all the metadata here - AString MetaData; - // Common metadata (index 0, byte): - MetaData.push_back(0); - MetaData.push_back(GetEntityMetadataFlags(a_Entity)); - - // TODO: Add more entity-specific metadata - - MetaData.push_back(0x7f); // End metadata - return MetaData; -} + // Common Metadata + Byte CommonMetadata = 0; - - - -char cProtocol125::GetEntityMetadataFlags(const cEntity & a_Entity) -{ - char Flags = 0; if (a_Entity.IsOnFire()) { - Flags |= 1; + CommonMetadata |= 0x1; } if (a_Entity.IsCrouched()) { - Flags |= 2; + CommonMetadata |= 0x2; } if (a_Entity.IsRiding()) { - Flags |= 4; + CommonMetadata |= 0x4; } if (a_Entity.IsSprinting()) { - Flags |= 8; + CommonMetadata |= 0x8; } if (a_Entity.IsRclking()) { - Flags |= 16; + CommonMetadata |= 0x16; + } + if (a_Entity.IsInvisible()) + { + CommonMetadata |= 0x32; + } + + WriteByte(0x0); + WriteByte(CommonMetadata); + + // Common Metadata End + // Specific Entity Metadata + + if (a_Entity.IsMinecart()) + { + WriteByte(0x51); + // No idea how Mojang makes their carts shakey shakey, so here is a complicated one-liner expression that does something similar + WriteInt( (((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * a_Entity.LastDamage()) * 4 ); + WriteByte(0x52); + WriteInt(1); // Shaking direction, doesn't seem to affect anything + WriteByte(0x73); + WriteFloat((float)(a_Entity.LastDamage() + 10)); // Damage taken / shake effect multiplyer + } + else if (a_Entity.IsA("cCreeper")) + { + WriteByte(0x10); + WriteByte(a_Entity.IsBlowing() ? 1 : -1); // Blowing up? + WriteByte(0x11); + WriteByte(a_Entity.IsCharged() ? 1 : 0); // Lightning-charged? + } + else if (a_Entity.IsA("cMinecartWithFurnace")) + { + WriteByte(0x10); + WriteByte(a_Entity.IsFueled() ? 1 : 0); // Fueled? + } + else if (a_Entity.IsA("cBat")) + { + WriteByte(0x10); + WriteByte(a_Entity.IsHanging() ? 1 : 0); // Upside down? + } + else if (a_Entity.IsA("cPig")) + { + WriteByte(0x10); + WriteByte(a_Entity.IsSaddled() ? 1 : 0); // Saddled? + } + else if (a_Entity.IsA("cVillager")) + { + WriteByte(0x50); + WriteInt(a_Entity.GetVilType()); // What sort of TESTIFICATE? + } + else if (a_Entity.IsA("cZombie")) + { + WriteByte(0xC); + WriteByte(a_Entity.IsBabby() ? 1 : 0); // Babby zombie? + WriteByte(0xD); + WriteByte(a_Entity.IsVillZomb() ? 1 : 0); // Converted zombie? + WriteByte(0xE); + WriteByte(a_Entity.IsConvert() ? 1 : 0); // Converted-but-converting-back zombllager? + } + else if (a_Entity.IsA("cGhast")) + { + WriteByte(0x10); + WriteByte(a_Entity.IsCharging()); // About to eject un flamé-bol? :P + } + else if (a_Entity.IsA("cArrowEntity")) + { + WriteByte(0x10); + WriteByte(a_Entity.IsCritical() ? 1 : 0); // Critical hitting arrow? + } + else if (a_Entity.IsA("cWolf")) + { + Byte WolfStatus = 0; + if (a_Entity.IsSitting()) + { + WolfStatus |= 0x1; + } + if (a_Entity.IsAngry()) + { + WolfStatus |= 0x2; + } + if (a_Entity.IsTame()) + { + WolfStatus |= 0x4; + } + WriteByte(0x10); + WriteByte(WolfStatus); + + WriteByte(0x72); + WriteFloat((float)(a_Entity.GetHealth())); // Tail health-o-meter (only shown when tamed, by the way) + WriteByte(0x13); + WriteByte(a_Entity.IsBegging() ? 1 : 0); // Ultra cute mode? + } + else if (a_Entity.IsA("cSheep")) + { + // [1](1111) + // [] = Is sheared? () = Color, from 0 to 15 + + WriteByte(0x10); + Byte SheepMetadata = 0; + SheepMetadata = a_Entity.GetFurColor(); // Fur colour + + if (a_Entity.IsSheared()) // Is sheared? + { + SheepMetadata |= 0x16; + } + WriteByte(SheepMetadata); + } + else if (a_Entity.IsA("cEnderman")) + { + WriteByte(0x10); + WriteByte(a_Entity.CarriedBlock()); // Stolen block + WriteByte(0x11); + WriteByte(a_Entity.CarriedMeta()); // Stolen metea + WriteByte(0x12); + WriteByte(a_Entity.IsScream() ? 1 : 0); // I HATE YER FACE, I SCWEAM AT YER FACE + } + else if (a_Entity.IsA("cSkeleton")) + { + WriteByte(0xD); + WriteByte(a_Entity.IsWither() ? 1 : 0); // It's a skeleton, but it's not + } + else if (a_Entity.IsA("cWitch")) + { + WriteByte(0x15); + WriteByte(a_Entity.IsNosey() ? 1 : 0); // Drinking-nose: like Squidward + } + else if ((a_Entity.IsA("cSlime")) || (a_Entity.IsA("cMagmaCube"))) + { + WriteByte(0x10); + WriteByte(a_Entity.GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + } + else if (a_Entity.IsA("cHorse")) + { + int Flags = 0; + if (a_Entity.IsTame()) + { + Flags |= 0x2; + } + if (a_Entity.IsSaddled()) + { + Flags |= 0x4; + } + if (a_Entity.IsChested()) + { + Flags |= 0x8; + } + if (a_Entity.IsBabby()) + { + Flags |= 0x10; // IsBred flag, according to wiki.vg - don't think it does anything in multiplayer + } + if (a_Entity.IsEating()) + { + Flags |= 0x20; + } + if (a_Entity.IsRearing()) + { + Flags |= 0x40; + } + if (a_Entity.IsMthOpen()) + { + Flags |= 0x80; + } + WriteByte(0x50); + WriteInt(Flags); + + WriteByte(0x13); + WriteByte(a_Entity.GetHType()); // Type of horse (donkey, chestnut, etc.) + + WriteByte(0x54); + int Appearance = 0; + Appearance = a_Entity.GetHColor(); // Mask FF + Appearance |= a_Entity.GetHStyle() * 256; // Mask FF00, so multiply by 256 + WriteInt(Appearance); + + WriteByte(0x56); + WriteInt(a_Entity.GetHArmour()); // Horshey armour } - return Flags; + + // End Specific Metadata + // End Metadata Packet + + WriteByte(0x7f); } diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index c5c8cd1a0..7b493881b 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -142,11 +142,8 @@ protected: /// Parses one item, "slot" as the protocol wiki calls it, from m_ReceivedData; returns the usual ParsePacket() codes virtual int ParseItem(cItem & a_Item); - /// Returns the entity metadata representation - AString GetEntityMetaData(const cEntity & a_Entity); - - /// Returns the entity common metadata, index 0 (generic flags) - char GetEntityMetadataFlags(const cEntity & a_Entity); + /// Writes the entity metadata + void WriteMetadata(const cEntity & a_Entity); } ; diff --git a/source/Protocol/Protocol132.cpp b/source/Protocol/Protocol132.cpp index a06eb0b8b..63b838b70 100644 --- a/source/Protocol/Protocol132.cpp +++ b/source/Protocol/Protocol132.cpp @@ -416,8 +416,7 @@ void cProtocol132::SendSpawnMob(const cMonster & a_Mob) WriteShort ((short)(a_Mob.GetSpeedX() * 400)); WriteShort ((short)(a_Mob.GetSpeedY() * 400)); WriteShort ((short)(a_Mob.GetSpeedZ() * 400)); - AString MetaData = GetEntityMetaData(a_Mob); - SendData (MetaData.data(), MetaData.size()); + WriteMetadata(a_Mob); Flush(); } -- cgit v1.2.3 From 7401fc000dca2a3ff3ce61776f84e5c2d8eb1868 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 8 Oct 2013 22:21:55 +0100 Subject: Initial round of fixes * Fixed intentional misspelling of baby! :D * Better chested horse bool name * Fixed some weird continuity issues with my recent changes not being pushed up initially * Fixed derpy hexadecimal values --- source/Protocol/Protocol125.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 89b2c15ec..e2309c295 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -1638,11 +1638,11 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) } if (a_Entity.IsRclking()) { - CommonMetadata |= 0x16; + CommonMetadata |= 0x10; } if (a_Entity.IsInvisible()) { - CommonMetadata |= 0x32; + CommonMetadata |= 0x20; } WriteByte(0x0); @@ -1691,7 +1691,7 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) else if (a_Entity.IsA("cZombie")) { WriteByte(0xC); - WriteByte(a_Entity.IsBabby() ? 1 : 0); // Babby zombie? + WriteByte(a_Entity.IsBaby() ? 1 : 0); // Babby zombie? WriteByte(0xD); WriteByte(a_Entity.IsVillZomb() ? 1 : 0); // Converted zombie? WriteByte(0xE); @@ -1784,7 +1784,7 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) { Flags |= 0x8; } - if (a_Entity.IsBabby()) + if (a_Entity.IsBaby()) { Flags |= 0x10; // IsBred flag, according to wiki.vg - don't think it does anything in multiplayer } -- cgit v1.2.3 From fe6fa23a97421af3d02b9faf92b8df2f73abb556 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 9 Oct 2013 21:02:59 +0100 Subject: Second round of fixes * Implemented suggestions --- source/Protocol/Protocol125.cpp | 98 ++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 36 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index e2309c295..0f5f3a616 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -24,8 +24,27 @@ Documentation: #include "../UI/Window.h" #include "../Root.h" #include "../Server.h" + +#include "../Entities/ProjectileEntity.h" +#include "../Entities/Minecart.h" #include "../Entities/FallingBlock.h" +#include "../Mobs/Monster.h" +#include "../Mobs/Creeper.h" +#include "../Mobs/Bat.h" +#include "../Mobs/Pig.h" +#include "../Mobs/Villager.h" +#include "../Mobs/Zombie.h" +#include "../Mobs/Ghast.h" +#include "../Mobs/Wolf.h" +#include "../Mobs/Sheep.h" +#include "../Mobs/Enderman.h" +#include "../Mobs/Skeleton.h" +#include "../Mobs/Witch.h" +#include "../Mobs/Slime.h" +#include "../Mobs/Magmacube.h" +#include "../Mobs/Horse.h" + @@ -1655,70 +1674,70 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) { WriteByte(0x51); // No idea how Mojang makes their carts shakey shakey, so here is a complicated one-liner expression that does something similar - WriteInt( (((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * a_Entity.LastDamage()) * 4 ); + WriteInt( (((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * ((cMinecart &)a_Entity).LastDamage()) * 4 ); WriteByte(0x52); WriteInt(1); // Shaking direction, doesn't seem to affect anything WriteByte(0x73); - WriteFloat((float)(a_Entity.LastDamage() + 10)); // Damage taken / shake effect multiplyer + WriteFloat((float)(((cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer } else if (a_Entity.IsA("cCreeper")) { WriteByte(0x10); - WriteByte(a_Entity.IsBlowing() ? 1 : -1); // Blowing up? + WriteByte(((cCreeper &)a_Entity).IsBlowing() ? 1 : -1); // Blowing up? WriteByte(0x11); - WriteByte(a_Entity.IsCharged() ? 1 : 0); // Lightning-charged? + WriteByte(((cCreeper &)a_Entity).IsCharged() ? 1 : 0); // Lightning-charged? } else if (a_Entity.IsA("cMinecartWithFurnace")) { WriteByte(0x10); - WriteByte(a_Entity.IsFueled() ? 1 : 0); // Fueled? + WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0); // Fueled? } else if (a_Entity.IsA("cBat")) { WriteByte(0x10); - WriteByte(a_Entity.IsHanging() ? 1 : 0); // Upside down? + WriteByte(((const cBat &)a_Entity).IsHanging() ? 1 : 0); // Upside down? } else if (a_Entity.IsA("cPig")) { WriteByte(0x10); - WriteByte(a_Entity.IsSaddled() ? 1 : 0); // Saddled? + WriteByte(((const cPig &)a_Entity).IsSaddled() ? 1 : 0); // Saddled? } else if (a_Entity.IsA("cVillager")) { WriteByte(0x50); - WriteInt(a_Entity.GetVilType()); // What sort of TESTIFICATE? + WriteInt(((const cVillager &)a_Entity).GetVilType()); // What sort of TESTIFICATE? } else if (a_Entity.IsA("cZombie")) { WriteByte(0xC); - WriteByte(a_Entity.IsBaby() ? 1 : 0); // Babby zombie? + WriteByte(((const cZombie &)a_Entity).IsBaby() ? 1 : 0); // Babby zombie? WriteByte(0xD); - WriteByte(a_Entity.IsVillZomb() ? 1 : 0); // Converted zombie? + WriteByte(((const cZombie &)a_Entity).IsVillagerZombie() ? 1 : 0); // Converted zombie? WriteByte(0xE); - WriteByte(a_Entity.IsConvert() ? 1 : 0); // Converted-but-converting-back zombllager? + WriteByte(((const cZombie &)a_Entity).IsConverting() ? 1 : 0); // Converted-but-converting-back zombllager? } else if (a_Entity.IsA("cGhast")) { WriteByte(0x10); - WriteByte(a_Entity.IsCharging()); // About to eject un flamé-bol? :P + WriteByte(((const cGhast &)a_Entity).IsCharging()); // About to eject un flamé-bol? :P } else if (a_Entity.IsA("cArrowEntity")) { WriteByte(0x10); - WriteByte(a_Entity.IsCritical() ? 1 : 0); // Critical hitting arrow? + WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0); // Critical hitting arrow? } else if (a_Entity.IsA("cWolf")) { Byte WolfStatus = 0; - if (a_Entity.IsSitting()) + if (((const cWolf &)a_Entity).IsSitting()) { WolfStatus |= 0x1; } - if (a_Entity.IsAngry()) + if (((const cWolf &)a_Entity).IsAngry()) { WolfStatus |= 0x2; } - if (a_Entity.IsTame()) + if (((const cWolf &)a_Entity).IsTame()) { WolfStatus |= 0x4; } @@ -1728,7 +1747,7 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) WriteByte(0x72); WriteFloat((float)(a_Entity.GetHealth())); // Tail health-o-meter (only shown when tamed, by the way) WriteByte(0x13); - WriteByte(a_Entity.IsBegging() ? 1 : 0); // Ultra cute mode? + WriteByte(((const cWolf &)a_Entity).IsBegging() ? 1 : 0); // Ultra cute mode? } else if (a_Entity.IsA("cSheep")) { @@ -1737,9 +1756,9 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) WriteByte(0x10); Byte SheepMetadata = 0; - SheepMetadata = a_Entity.GetFurColor(); // Fur colour + SheepMetadata = ((const cSheep &)a_Entity).GetFurColor(); // Fur colour - if (a_Entity.IsSheared()) // Is sheared? + if (((const cSheep &)a_Entity).IsSheared()) // Is sheared? { SheepMetadata |= 0x16; } @@ -1748,55 +1767,62 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) else if (a_Entity.IsA("cEnderman")) { WriteByte(0x10); - WriteByte(a_Entity.CarriedBlock()); // Stolen block + WriteByte((Byte)(((cEnderman &)a_Entity).GetCarriedBlock())); // Block that he stole from your house WriteByte(0x11); - WriteByte(a_Entity.CarriedMeta()); // Stolen metea + WriteByte((Byte)(((cEnderman &)a_Entity).GetCarriedMeta())); // Meta of block that he stole from your house WriteByte(0x12); - WriteByte(a_Entity.IsScream() ? 1 : 0); // I HATE YER FACE, I SCWEAM AT YER FACE + WriteByte(((cEnderman &)a_Entity).IsScreaming() ? 1 : 0); // Screaming at your face? } else if (a_Entity.IsA("cSkeleton")) { WriteByte(0xD); - WriteByte(a_Entity.IsWither() ? 1 : 0); // It's a skeleton, but it's not + WriteByte(((const cSkeleton &)a_Entity).IsWither() ? 1 : 0); // It's a skeleton, but it's not } else if (a_Entity.IsA("cWitch")) { WriteByte(0x15); - WriteByte(a_Entity.IsNosey() ? 1 : 0); // Drinking-nose: like Squidward + WriteByte(((cWitch &)a_Entity).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything } else if ((a_Entity.IsA("cSlime")) || (a_Entity.IsA("cMagmaCube"))) { WriteByte(0x10); - WriteByte(a_Entity.GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + if (a_Entity.IsA("cSlime")) + { + WriteByte(((const cSlime &)a_Entity).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + } + else + { + WriteByte(((const cMagmaCube &)a_Entity).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + } } else if (a_Entity.IsA("cHorse")) { int Flags = 0; - if (a_Entity.IsTame()) + if (((const cHorse &)a_Entity).IsTame()) { Flags |= 0x2; } - if (a_Entity.IsSaddled()) + if (((const cHorse &)a_Entity).IsSaddled()) { Flags |= 0x4; } - if (a_Entity.IsChested()) + if (((const cHorse &)a_Entity).IsChested()) { Flags |= 0x8; } - if (a_Entity.IsBaby()) + if (((const cHorse &)a_Entity).IsBaby()) { Flags |= 0x10; // IsBred flag, according to wiki.vg - don't think it does anything in multiplayer } - if (a_Entity.IsEating()) + if (((const cHorse &)a_Entity).IsEating()) { Flags |= 0x20; } - if (a_Entity.IsRearing()) + if (((const cHorse &)a_Entity).IsRearing()) { Flags |= 0x40; } - if (a_Entity.IsMthOpen()) + if (((const cHorse &)a_Entity).IsMthOpen()) { Flags |= 0x80; } @@ -1804,16 +1830,16 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) WriteInt(Flags); WriteByte(0x13); - WriteByte(a_Entity.GetHType()); // Type of horse (donkey, chestnut, etc.) + WriteByte(((const cHorse &)a_Entity).GetHType()); // Type of horse (donkey, chestnut, etc.) WriteByte(0x54); int Appearance = 0; - Appearance = a_Entity.GetHColor(); // Mask FF - Appearance |= a_Entity.GetHStyle() * 256; // Mask FF00, so multiply by 256 + Appearance = ((const cHorse &)a_Entity).GetHColor(); // Mask FF + Appearance |= ((const cHorse &)a_Entity).GetHStyle() * 256; // Mask FF00, so multiply by 256 WriteInt(Appearance); WriteByte(0x56); - WriteInt(a_Entity.GetHArmour()); // Horshey armour + WriteInt(((const cHorse &)a_Entity).GetHArmour()); // Horshey armour } // End Specific Metadata -- cgit v1.2.3 From d7b2c534fd2e272c328b176432c922fd11a7cd85 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 11 Oct 2013 00:41:54 +0100 Subject: Third round of fixes * Split WriteMetadata into three functions for common, entity, and mob * Edited a few mob sizes to Vanilla values --- source/Protocol/Protocol125.cpp | 157 ++++++++++++++++++++++------------------ source/Protocol/Protocol125.h | 10 ++- source/Protocol/Protocol132.cpp | 6 +- 3 files changed, 101 insertions(+), 72 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 0f5f3a616..96a4e57ff 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -363,7 +363,16 @@ void cProtocol125::SendEntityMetadata(const cEntity & a_Entity) WriteByte(PACKET_METADATA); WriteInt (a_Entity.GetUniqueID()); - WriteMetadata(a_Entity); + WriteCommonMetadata(a_Entity); + if (a_Entity.IsMob()) + { + WriteMobMetadata(((const cMonster &)a_Entity)); + } + else + { + WriteEntityMetadata(a_Entity); + } + WriteByte(0x7f); Flush(); } @@ -730,7 +739,11 @@ void cProtocol125::SendSpawnMob(const cMonster & a_Mob) WriteByte (0); WriteByte (0); WriteByte (0); - WriteMetadata(a_Mob); + + WriteCommonMetadata(a_Mob); + WriteMobMetadata(a_Mob); + WriteByte(0x7f); + Flush(); } @@ -1633,10 +1646,8 @@ int cProtocol125::ParseItem(cItem & a_Item) -void cProtocol125::WriteMetadata(const cEntity & a_Entity) +void cProtocol125::WriteCommonMetadata(const cEntity & a_Entity) { - // Common Metadata - Byte CommonMetadata = 0; if (a_Entity.IsOnFire()) @@ -1666,78 +1677,91 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) WriteByte(0x0); WriteByte(CommonMetadata); +} + + - // Common Metadata End - // Specific Entity Metadata + +void cProtocol125::WriteEntityMetadata(const cEntity & a_Entity) +{ if (a_Entity.IsMinecart()) { WriteByte(0x51); // No idea how Mojang makes their carts shakey shakey, so here is a complicated one-liner expression that does something similar - WriteInt( (((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * ((cMinecart &)a_Entity).LastDamage()) * 4 ); + WriteInt( (((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * ((const cMinecart &)a_Entity).LastDamage()) * 4 ); WriteByte(0x52); WriteInt(1); // Shaking direction, doesn't seem to affect anything WriteByte(0x73); - WriteFloat((float)(((cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer + WriteFloat((float)(((const cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer + + if (a_Entity.IsA("cMinecartWithFurnace")) + { + WriteByte(0x10); + WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0); // Fueled? + } } - else if (a_Entity.IsA("cCreeper")) +} + + + + + +void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) +{ + if (a_Mob.GetMobType() == E_META_SPAWN_EGG_CREEPER) { WriteByte(0x10); - WriteByte(((cCreeper &)a_Entity).IsBlowing() ? 1 : -1); // Blowing up? + WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? WriteByte(0x11); - WriteByte(((cCreeper &)a_Entity).IsCharged() ? 1 : 0); // Lightning-charged? - } - else if (a_Entity.IsA("cMinecartWithFurnace")) - { - WriteByte(0x10); - WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0); // Fueled? + WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged? } - else if (a_Entity.IsA("cBat")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_BAT) { WriteByte(0x10); - WriteByte(((const cBat &)a_Entity).IsHanging() ? 1 : 0); // Upside down? + WriteByte(((const cBat &)a_Mob).IsHanging() ? 1 : 0); // Upside down? } - else if (a_Entity.IsA("cPig")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_PIG) { WriteByte(0x10); - WriteByte(((const cPig &)a_Entity).IsSaddled() ? 1 : 0); // Saddled? + WriteByte(((const cPig &)a_Mob).IsSaddled() ? 1 : 0); // Saddled? } - else if (a_Entity.IsA("cVillager")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_VILLAGER) { WriteByte(0x50); - WriteInt(((const cVillager &)a_Entity).GetVilType()); // What sort of TESTIFICATE? + WriteInt(((const cVillager &)a_Mob).GetVilType()); // What sort of TESTIFICATE? } - else if (a_Entity.IsA("cZombie")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_ZOMBIE) { WriteByte(0xC); - WriteByte(((const cZombie &)a_Entity).IsBaby() ? 1 : 0); // Babby zombie? + WriteByte(((const cZombie &)a_Mob).IsBaby() ? 1 : 0); // Babby zombie? WriteByte(0xD); - WriteByte(((const cZombie &)a_Entity).IsVillagerZombie() ? 1 : 0); // Converted zombie? + WriteByte(((const cZombie &)a_Mob).IsVillagerZombie() ? 1 : 0); // Converted zombie? WriteByte(0xE); - WriteByte(((const cZombie &)a_Entity).IsConverting() ? 1 : 0); // Converted-but-converting-back zombllager? + WriteByte(((const cZombie &)a_Mob).IsConverting() ? 1 : 0); // Converted-but-converting-back zombllager? } - else if (a_Entity.IsA("cGhast")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_GHAST) { WriteByte(0x10); - WriteByte(((const cGhast &)a_Entity).IsCharging()); // About to eject un flamé-bol? :P + WriteByte(((const cGhast &)a_Mob).IsCharging()); // About to eject un flamé-bol? :P } - else if (a_Entity.IsA("cArrowEntity")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_ARROW) { WriteByte(0x10); - WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0); // Critical hitting arrow? + WriteByte(((const cArrowEntity &)a_Mob).IsCritical() ? 1 : 0); // Critical hitting arrow? } - else if (a_Entity.IsA("cWolf")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_WOLF) { Byte WolfStatus = 0; - if (((const cWolf &)a_Entity).IsSitting()) + if (((const cWolf &)a_Mob).IsSitting()) { WolfStatus |= 0x1; } - if (((const cWolf &)a_Entity).IsAngry()) + if (((const cWolf &)a_Mob).IsAngry()) { WolfStatus |= 0x2; } - if (((const cWolf &)a_Entity).IsTame()) + if (((const cWolf &)a_Mob).IsTame()) { WolfStatus |= 0x4; } @@ -1745,84 +1769,84 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) WriteByte(WolfStatus); WriteByte(0x72); - WriteFloat((float)(a_Entity.GetHealth())); // Tail health-o-meter (only shown when tamed, by the way) + WriteFloat((float)(a_Mob.GetHealth())); // Tail health-o-meter (only shown when tamed, by the way) WriteByte(0x13); - WriteByte(((const cWolf &)a_Entity).IsBegging() ? 1 : 0); // Ultra cute mode? + WriteByte(((const cWolf &)a_Mob).IsBegging() ? 1 : 0); // Ultra cute mode? } - else if (a_Entity.IsA("cSheep")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SHEEP) { // [1](1111) // [] = Is sheared? () = Color, from 0 to 15 WriteByte(0x10); Byte SheepMetadata = 0; - SheepMetadata = ((const cSheep &)a_Entity).GetFurColor(); // Fur colour + SheepMetadata = ((const cSheep &)a_Mob).GetFurColor(); // Fur colour - if (((const cSheep &)a_Entity).IsSheared()) // Is sheared? + if (((const cSheep &)a_Mob).IsSheared()) // Is sheared? { SheepMetadata |= 0x16; } WriteByte(SheepMetadata); } - else if (a_Entity.IsA("cEnderman")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_ENDERMAN) { WriteByte(0x10); - WriteByte((Byte)(((cEnderman &)a_Entity).GetCarriedBlock())); // Block that he stole from your house + WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedBlock())); // Block that he stole from your house WriteByte(0x11); - WriteByte((Byte)(((cEnderman &)a_Entity).GetCarriedMeta())); // Meta of block that he stole from your house + WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedMeta())); // Meta of block that he stole from your house WriteByte(0x12); - WriteByte(((cEnderman &)a_Entity).IsScreaming() ? 1 : 0); // Screaming at your face? + WriteByte(((const cEnderman &)a_Mob).IsScreaming() ? 1 : 0); // Screaming at your face? } - else if (a_Entity.IsA("cSkeleton")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SKELETON) { WriteByte(0xD); - WriteByte(((const cSkeleton &)a_Entity).IsWither() ? 1 : 0); // It's a skeleton, but it's not + WriteByte(((const cSkeleton &)a_Mob).IsWither() ? 1 : 0); // It's a skeleton, but it's not } - else if (a_Entity.IsA("cWitch")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_WITCH) { WriteByte(0x15); - WriteByte(((cWitch &)a_Entity).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything + WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything } - else if ((a_Entity.IsA("cSlime")) || (a_Entity.IsA("cMagmaCube"))) + else if ((a_Mob.GetMobType() == E_META_SPAWN_EGG_SLIME) || (a_Mob.GetMobType() == E_META_SPAWN_EGG_MAGMA_CUBE)) { WriteByte(0x10); - if (a_Entity.IsA("cSlime")) + if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SLIME) { - WriteByte(((const cSlime &)a_Entity).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte(((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME } else { - WriteByte(((const cMagmaCube &)a_Entity).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte(((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME } } - else if (a_Entity.IsA("cHorse")) + else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_HORSE) { int Flags = 0; - if (((const cHorse &)a_Entity).IsTame()) + if (((const cHorse &)a_Mob).IsTame()) { Flags |= 0x2; } - if (((const cHorse &)a_Entity).IsSaddled()) + if (((const cHorse &)a_Mob).IsSaddled()) { Flags |= 0x4; } - if (((const cHorse &)a_Entity).IsChested()) + if (((const cHorse &)a_Mob).IsChested()) { Flags |= 0x8; } - if (((const cHorse &)a_Entity).IsBaby()) + if (((const cHorse &)a_Mob).IsBaby()) { Flags |= 0x10; // IsBred flag, according to wiki.vg - don't think it does anything in multiplayer } - if (((const cHorse &)a_Entity).IsEating()) + if (((const cHorse &)a_Mob).IsEating()) { Flags |= 0x20; } - if (((const cHorse &)a_Entity).IsRearing()) + if (((const cHorse &)a_Mob).IsRearing()) { Flags |= 0x40; } - if (((const cHorse &)a_Entity).IsMthOpen()) + if (((const cHorse &)a_Mob).IsMthOpen()) { Flags |= 0x80; } @@ -1830,22 +1854,17 @@ void cProtocol125::WriteMetadata(const cEntity & a_Entity) WriteInt(Flags); WriteByte(0x13); - WriteByte(((const cHorse &)a_Entity).GetHType()); // Type of horse (donkey, chestnut, etc.) + WriteByte(((const cHorse &)a_Mob).GetHType()); // Type of horse (donkey, chestnut, etc.) WriteByte(0x54); int Appearance = 0; - Appearance = ((const cHorse &)a_Entity).GetHColor(); // Mask FF - Appearance |= ((const cHorse &)a_Entity).GetHStyle() * 256; // Mask FF00, so multiply by 256 + Appearance = ((const cHorse &)a_Mob).GetHColor(); // Mask FF + Appearance |= ((const cHorse &)a_Mob).GetHStyle() * 256; // Mask FF00, so multiply by 256 WriteInt(Appearance); WriteByte(0x56); - WriteInt(((const cHorse &)a_Entity).GetHArmour()); // Horshey armour + WriteInt(((const cHorse &)a_Mob).GetHArmour()); // Horshey armour } - - // End Specific Metadata - // End Metadata Packet - - WriteByte(0x7f); } diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index 7b493881b..ae198780c 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -142,8 +142,14 @@ protected: /// Parses one item, "slot" as the protocol wiki calls it, from m_ReceivedData; returns the usual ParsePacket() codes virtual int ParseItem(cItem & a_Item); - /// Writes the entity metadata - void WriteMetadata(const cEntity & a_Entity); + /// Writes the COMMON entity metadata + void WriteCommonMetadata(const cEntity & a_Entity); + + /// Writes normal entity metadata + void WriteEntityMetadata(const cEntity & a_Entity); + + /// Writes mobile entity metadata + void WriteMobMetadata(const cMonster & a_Mob); } ; diff --git a/source/Protocol/Protocol132.cpp b/source/Protocol/Protocol132.cpp index 63b838b70..53159a3b3 100644 --- a/source/Protocol/Protocol132.cpp +++ b/source/Protocol/Protocol132.cpp @@ -416,7 +416,11 @@ void cProtocol132::SendSpawnMob(const cMonster & a_Mob) WriteShort ((short)(a_Mob.GetSpeedX() * 400)); WriteShort ((short)(a_Mob.GetSpeedY() * 400)); WriteShort ((short)(a_Mob.GetSpeedZ() * 400)); - WriteMetadata(a_Mob); + + WriteCommonMetadata(a_Mob); + WriteMobMetadata(a_Mob); + WriteByte(0x7f); + Flush(); } -- cgit v1.2.3 From ee2df34d03313ecf98110384559f46f00a05978b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 11 Oct 2013 01:00:16 +0100 Subject: Fourth round of fixes * Switchified WriteMobMetadata * Renamed Horse functions to be better --- source/Protocol/Protocol125.cpp | 268 +++++++++++++++++++++------------------- 1 file changed, 143 insertions(+), 125 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 96a4e57ff..6d6101fb2 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -1709,161 +1709,179 @@ void cProtocol125::WriteEntityMetadata(const cEntity & a_Entity) void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) { - if (a_Mob.GetMobType() == E_META_SPAWN_EGG_CREEPER) + switch (a_Mob.GetMobType()) { - WriteByte(0x10); - WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? - WriteByte(0x11); - WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_BAT) - { - WriteByte(0x10); - WriteByte(((const cBat &)a_Mob).IsHanging() ? 1 : 0); // Upside down? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_PIG) - { - WriteByte(0x10); - WriteByte(((const cPig &)a_Mob).IsSaddled() ? 1 : 0); // Saddled? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_VILLAGER) - { - WriteByte(0x50); - WriteInt(((const cVillager &)a_Mob).GetVilType()); // What sort of TESTIFICATE? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_ZOMBIE) - { - WriteByte(0xC); - WriteByte(((const cZombie &)a_Mob).IsBaby() ? 1 : 0); // Babby zombie? - WriteByte(0xD); - WriteByte(((const cZombie &)a_Mob).IsVillagerZombie() ? 1 : 0); // Converted zombie? - WriteByte(0xE); - WriteByte(((const cZombie &)a_Mob).IsConverting() ? 1 : 0); // Converted-but-converting-back zombllager? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_GHAST) - { - WriteByte(0x10); - WriteByte(((const cGhast &)a_Mob).IsCharging()); // About to eject un flamé-bol? :P - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_ARROW) - { - WriteByte(0x10); - WriteByte(((const cArrowEntity &)a_Mob).IsCritical() ? 1 : 0); // Critical hitting arrow? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_WOLF) - { - Byte WolfStatus = 0; - if (((const cWolf &)a_Mob).IsSitting()) + case E_META_SPAWN_EGG_CREEPER: { - WolfStatus |= 0x1; + WriteByte(0x10); + WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? + WriteByte(0x11); + WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged? + break; } - if (((const cWolf &)a_Mob).IsAngry()) + case E_META_SPAWN_EGG_BAT: { - WolfStatus |= 0x2; + WriteByte(0x10); + WriteByte(((const cBat &)a_Mob).IsHanging() ? 1 : 0); // Upside down? + break; } - if (((const cWolf &)a_Mob).IsTame()) + case E_META_SPAWN_EGG_PIG: { - WolfStatus |= 0x4; + WriteByte(0x10); + WriteByte(((const cPig &)a_Mob).IsSaddled() ? 1 : 0); // Saddled? + break; } - WriteByte(0x10); - WriteByte(WolfStatus); - - WriteByte(0x72); - WriteFloat((float)(a_Mob.GetHealth())); // Tail health-o-meter (only shown when tamed, by the way) - WriteByte(0x13); - WriteByte(((const cWolf &)a_Mob).IsBegging() ? 1 : 0); // Ultra cute mode? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SHEEP) - { - // [1](1111) - // [] = Is sheared? () = Color, from 0 to 15 - - WriteByte(0x10); - Byte SheepMetadata = 0; - SheepMetadata = ((const cSheep &)a_Mob).GetFurColor(); // Fur colour - - if (((const cSheep &)a_Mob).IsSheared()) // Is sheared? + case E_META_SPAWN_EGG_VILLAGER: { - SheepMetadata |= 0x16; + WriteByte(0x50); + WriteInt(((const cVillager &)a_Mob).GetVilType()); // What sort of TESTIFICATE? + break; } - WriteByte(SheepMetadata); - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_ENDERMAN) - { - WriteByte(0x10); - WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedBlock())); // Block that he stole from your house - WriteByte(0x11); - WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedMeta())); // Meta of block that he stole from your house - WriteByte(0x12); - WriteByte(((const cEnderman &)a_Mob).IsScreaming() ? 1 : 0); // Screaming at your face? - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SKELETON) - { - WriteByte(0xD); - WriteByte(((const cSkeleton &)a_Mob).IsWither() ? 1 : 0); // It's a skeleton, but it's not - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_WITCH) - { - WriteByte(0x15); - WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything - } - else if ((a_Mob.GetMobType() == E_META_SPAWN_EGG_SLIME) || (a_Mob.GetMobType() == E_META_SPAWN_EGG_MAGMA_CUBE)) - { - WriteByte(0x10); - if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SLIME) + case E_META_SPAWN_EGG_ZOMBIE: { - WriteByte(((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte(0xC); + WriteByte(((const cZombie &)a_Mob).IsBaby() ? 1 : 0); // Babby zombie? + WriteByte(0xD); + WriteByte(((const cZombie &)a_Mob).IsVillagerZombie() ? 1 : 0); // Converted zombie? + WriteByte(0xE); + WriteByte(((const cZombie &)a_Mob).IsConverting() ? 1 : 0); // Converted-but-converting-back zombllager? + break; } - else + case E_META_SPAWN_EGG_GHAST: { - WriteByte(((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte(0x10); + WriteByte(((const cGhast &)a_Mob).IsCharging()); // About to eject un flamé-bol? :P + break; } - } - else if (a_Mob.GetMobType() == E_META_SPAWN_EGG_HORSE) - { - int Flags = 0; - if (((const cHorse &)a_Mob).IsTame()) + case E_META_SPAWN_EGG_ARROW: { - Flags |= 0x2; + WriteByte(0x10); + WriteByte(((const cArrowEntity &)a_Mob).IsCritical() ? 1 : 0); // Critical hitting arrow? + break; } - if (((const cHorse &)a_Mob).IsSaddled()) + case E_META_SPAWN_EGG_WOLF: { - Flags |= 0x4; + Byte WolfStatus = 0; + if (((const cWolf &)a_Mob).IsSitting()) + { + WolfStatus |= 0x1; + } + if (((const cWolf &)a_Mob).IsAngry()) + { + WolfStatus |= 0x2; + } + if (((const cWolf &)a_Mob).IsTame()) + { + WolfStatus |= 0x4; + } + WriteByte(0x10); + WriteByte(WolfStatus); + + WriteByte(0x72); + WriteFloat((float)(a_Mob.GetHealth())); // Tail health-o-meter (only shown when tamed, by the way) + WriteByte(0x13); + WriteByte(((const cWolf &)a_Mob).IsBegging() ? 1 : 0); // Ultra cute mode? + break; } - if (((const cHorse &)a_Mob).IsChested()) + case E_META_SPAWN_EGG_SHEEP: { - Flags |= 0x8; + // [1](1111) + // [] = Is sheared? () = Color, from 0 to 15 + + WriteByte(0x10); + Byte SheepMetadata = 0; + SheepMetadata = ((const cSheep &)a_Mob).GetFurColor(); // Fur colour + + if (((const cSheep &)a_Mob).IsSheared()) // Is sheared? + { + SheepMetadata |= 0x16; + } + WriteByte(SheepMetadata); + break; } - if (((const cHorse &)a_Mob).IsBaby()) + case E_META_SPAWN_EGG_ENDERMAN: { - Flags |= 0x10; // IsBred flag, according to wiki.vg - don't think it does anything in multiplayer + WriteByte(0x10); + WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedBlock())); // Block that he stole from your house + WriteByte(0x11); + WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedMeta())); // Meta of block that he stole from your house + WriteByte(0x12); + WriteByte(((const cEnderman &)a_Mob).IsScreaming() ? 1 : 0); // Screaming at your face? + break; } - if (((const cHorse &)a_Mob).IsEating()) + case E_META_SPAWN_EGG_SKELETON: { - Flags |= 0x20; + WriteByte(0xD); + WriteByte(((const cSkeleton &)a_Mob).IsWither() ? 1 : 0); // It's a skeleton, but it's not + break; } - if (((const cHorse &)a_Mob).IsRearing()) + case E_META_SPAWN_EGG_WITCH: { - Flags |= 0x40; + WriteByte(0x15); + WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything + break; } - if (((const cHorse &)a_Mob).IsMthOpen()) + case E_META_SPAWN_EGG_SLIME: + case E_META_SPAWN_EGG_MAGMA_CUBE: { - Flags |= 0x80; + WriteByte(0x10); + if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SLIME) + { + WriteByte(((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + } + else + { + WriteByte(((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + } + break; } - WriteByte(0x50); - WriteInt(Flags); + case E_META_SPAWN_EGG_HORSE: + { + int Flags = 0; + if (((const cHorse &)a_Mob).IsTame()) + { + Flags |= 0x2; + } + if (((const cHorse &)a_Mob).IsSaddled()) + { + Flags |= 0x4; + } + if (((const cHorse &)a_Mob).IsChested()) + { + Flags |= 0x8; + } + if (((const cHorse &)a_Mob).IsBaby()) + { + Flags |= 0x10; // IsBred flag, according to wiki.vg - don't think it does anything in multiplayer + } + if (((const cHorse &)a_Mob).IsEating()) + { + Flags |= 0x20; + } + if (((const cHorse &)a_Mob).IsRearing()) + { + Flags |= 0x40; + } + if (((const cHorse &)a_Mob).IsMthOpen()) + { + Flags |= 0x80; + } + WriteByte(0x50); + WriteInt(Flags); - WriteByte(0x13); - WriteByte(((const cHorse &)a_Mob).GetHType()); // Type of horse (donkey, chestnut, etc.) + WriteByte(0x13); + WriteByte(((const cHorse &)a_Mob).GetHorseType()); // Type of horse (donkey, chestnut, etc.) - WriteByte(0x54); - int Appearance = 0; - Appearance = ((const cHorse &)a_Mob).GetHColor(); // Mask FF - Appearance |= ((const cHorse &)a_Mob).GetHStyle() * 256; // Mask FF00, so multiply by 256 - WriteInt(Appearance); + WriteByte(0x54); + int Appearance = 0; + Appearance = ((const cHorse &)a_Mob).GetHorseColor(); // Mask FF + Appearance |= ((const cHorse &)a_Mob).GetHorseStyle() * 256; // Mask FF00, so multiply by 256 + WriteInt(Appearance); - WriteByte(0x56); - WriteInt(((const cHorse &)a_Mob).GetHArmour()); // Horshey armour + WriteByte(0x56); + WriteInt(((const cHorse &)a_Mob).GetHorseArmour()); // Horshey armour + break; + } } } -- cgit v1.2.3 From d0acb37aedb280f0589275ace342ea6565f80aaa Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 12 Oct 2013 23:05:15 +0100 Subject: Seventh round of fixes * Fixed arrows not critical-effecting because they were in MOBS! (derp) * Used cMonster::mtXX as per xoft's suggestions --- source/Protocol/Protocol125.cpp | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 6d6101fb2..4730c3dfc 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -1701,6 +1701,12 @@ void cProtocol125::WriteEntityMetadata(const cEntity & a_Entity) WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0); // Fueled? } } + else if (a_Entity.IsA("cArrowEntity")); + { + WriteByte(0x10); + WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0); // Critical hitting arrow? + } + } @@ -1711,7 +1717,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) { switch (a_Mob.GetMobType()) { - case E_META_SPAWN_EGG_CREEPER: + case cMonster::mtCreeper: { WriteByte(0x10); WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? @@ -1719,25 +1725,25 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged? break; } - case E_META_SPAWN_EGG_BAT: + case cMonster::mtBat: { WriteByte(0x10); WriteByte(((const cBat &)a_Mob).IsHanging() ? 1 : 0); // Upside down? break; } - case E_META_SPAWN_EGG_PIG: + case cMonster::mtPig: { WriteByte(0x10); WriteByte(((const cPig &)a_Mob).IsSaddled() ? 1 : 0); // Saddled? break; } - case E_META_SPAWN_EGG_VILLAGER: + case cMonster::mtVillager: { WriteByte(0x50); WriteInt(((const cVillager &)a_Mob).GetVilType()); // What sort of TESTIFICATE? break; } - case E_META_SPAWN_EGG_ZOMBIE: + case cMonster::mtZombie: { WriteByte(0xC); WriteByte(((const cZombie &)a_Mob).IsBaby() ? 1 : 0); // Babby zombie? @@ -1747,19 +1753,13 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(((const cZombie &)a_Mob).IsConverting() ? 1 : 0); // Converted-but-converting-back zombllager? break; } - case E_META_SPAWN_EGG_GHAST: + case cMonster::mtGhast: { WriteByte(0x10); WriteByte(((const cGhast &)a_Mob).IsCharging()); // About to eject un flamé-bol? :P break; } - case E_META_SPAWN_EGG_ARROW: - { - WriteByte(0x10); - WriteByte(((const cArrowEntity &)a_Mob).IsCritical() ? 1 : 0); // Critical hitting arrow? - break; - } - case E_META_SPAWN_EGG_WOLF: + case cMonster::mtWolf: { Byte WolfStatus = 0; if (((const cWolf &)a_Mob).IsSitting()) @@ -1783,7 +1783,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(((const cWolf &)a_Mob).IsBegging() ? 1 : 0); // Ultra cute mode? break; } - case E_META_SPAWN_EGG_SHEEP: + case cMonster::mtSheep: { // [1](1111) // [] = Is sheared? () = Color, from 0 to 15 @@ -1799,7 +1799,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(SheepMetadata); break; } - case E_META_SPAWN_EGG_ENDERMAN: + case cMonster::mtEnderman: { WriteByte(0x10); WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedBlock())); // Block that he stole from your house @@ -1809,23 +1809,23 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(((const cEnderman &)a_Mob).IsScreaming() ? 1 : 0); // Screaming at your face? break; } - case E_META_SPAWN_EGG_SKELETON: + case cMonster::mtSkeleton: { WriteByte(0xD); WriteByte(((const cSkeleton &)a_Mob).IsWither() ? 1 : 0); // It's a skeleton, but it's not break; } - case E_META_SPAWN_EGG_WITCH: + case cMonster::mtWitch: { WriteByte(0x15); WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything break; } - case E_META_SPAWN_EGG_SLIME: - case E_META_SPAWN_EGG_MAGMA_CUBE: + case cMonster::mtSlime: + case cMonster::mtMagmaCube: { WriteByte(0x10); - if (a_Mob.GetMobType() == E_META_SPAWN_EGG_SLIME) + if (a_Mob.GetMobType() == cMonster::mtSlime) { WriteByte(((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME } @@ -1835,7 +1835,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) } break; } - case E_META_SPAWN_EGG_HORSE: + case cMonster::mtHorse: { int Flags = 0; if (((const cHorse &)a_Mob).IsTame()) -- cgit v1.2.3 From d8d2f35e9dd354fba14f8d6512e818d18d2066c2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 13 Oct 2013 12:47:55 +0100 Subject: Eight round of fixes * Changed IsA() to *long if statement* - Removed deprecated values in Entity.h - to blazes with the plugins! * Renamed villager type enumerations to be LESS SHOUTY and more vt-y + Use vtMax for World.cpp testificate spawning --- source/Protocol/Protocol125.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 4730c3dfc..62863cd48 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -1695,18 +1695,17 @@ void cProtocol125::WriteEntityMetadata(const cEntity & a_Entity) WriteByte(0x73); WriteFloat((float)(((const cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer - if (a_Entity.IsA("cMinecartWithFurnace")) + if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpFurnace) { WriteByte(0x10); WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0); // Fueled? } } - else if (a_Entity.IsA("cArrowEntity")); + else if ((a_Entity.IsProjectile() && ((cProjectileEntity &)a_Entity).GetProjectileKind() == cProjectileEntity::pkArrow)); { WriteByte(0x10); WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0); // Critical hitting arrow? } - } -- cgit v1.2.3