summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol17x.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Protocol/Protocol17x.cpp')
-rw-r--r--src/Protocol/Protocol17x.cpp93
1 files changed, 47 insertions, 46 deletions
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 53bb01790..098c62a90 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -723,64 +723,55 @@ void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting)
-void cProtocol172::SendMapColumn(int a_MapID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
+void cProtocol172::SendMapData(const cMap & a_Map, int a_DataStartX, int a_DataStartY)
{
ASSERT(m_State == 3); // In game mode?
- ASSERT(a_Length + 3 <= USHRT_MAX);
- ASSERT((a_X >= 0) && (a_X < 256));
- ASSERT((a_Y >= 0) && (a_Y < 256));
-
- cPacketizer Pkt(*this, 0x34);
- Pkt.WriteVarInt32(static_cast<UInt32>(a_MapID));
- Pkt.WriteBEUInt16(static_cast<UInt16>(3 + a_Length));
- Pkt.WriteBEUInt8(0);
- Pkt.WriteBEUInt8(static_cast<Byte>(a_X));
- Pkt.WriteBEUInt8(static_cast<Byte>(a_Y));
-
- Pkt.WriteBuf(reinterpret_cast<const char *>(a_Colors), a_Length);
-}
+ {
+ ASSERT(a_Map.GetScale() < 256);
+ cPacketizer Pkt(*this, 0x34);
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetID()));
+ Pkt.WriteBEUInt16(2);
+ Pkt.WriteBEUInt8(2);
+ Pkt.WriteBEUInt8(static_cast<Byte>(a_Map.GetScale()));
+ }
+ {
+ ASSERT(a_Map.GetData().size() + 3 <= USHRT_MAX);
+ ASSERT((a_DataStartX >= 0) && (a_DataStartX < 256));
+ ASSERT((a_DataStartY >= 0) && (a_DataStartY < 256));
+ cPacketizer Pkt(*this, 0x34);
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetID()));
+ Pkt.WriteBEUInt16(static_cast<UInt16>(3 + a_Map.GetData().size()));
-void cProtocol172::SendMapDecorators(int a_MapID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
-{
- ASSERT(m_State == 3); // In game mode?
- ASSERT(1 + 3 * a_Decorators.size() < USHRT_MAX);
-
- cPacketizer Pkt(*this, 0x34);
- Pkt.WriteVarInt32(static_cast<UInt32>(a_MapID));
- Pkt.WriteBEUInt16(static_cast<UInt16>(1 + (3 * a_Decorators.size())));
+ Pkt.WriteBEUInt8(0);
+ Pkt.WriteBEUInt8(static_cast<Byte>(a_DataStartX));
+ Pkt.WriteBEUInt8(static_cast<Byte>(a_DataStartX));
- Pkt.WriteBEUInt8(1);
-
- for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it)
- {
- ASSERT(it->GetPixelX() < 256);
- ASSERT(it->GetPixelZ() < 256);
- Pkt.WriteBEUInt8(static_cast<Byte>((it->GetType() << 4) | static_cast<Byte>(it->GetRot() & 0xf)));
- Pkt.WriteBEUInt8(static_cast<Byte>(it->GetPixelX()));
- Pkt.WriteBEUInt8(static_cast<Byte>(it->GetPixelZ()));
+ Pkt.WriteBuf(reinterpret_cast<const char *>(a_Map.GetData().data()), a_Map.GetData().size());
}
-}
-
+ {
+ ASSERT(1 + 3 * a_Map.GetDecorators().size() < USHRT_MAX);
+ cPacketizer Pkt(*this, 0x34);
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetID()));
+ Pkt.WriteBEUInt16(static_cast<UInt16>(1 + (3 * a_Map.GetDecorators().size())));
+ Pkt.WriteBEUInt8(1);
-void cProtocol172::SendMapInfo(int a_MapID, unsigned int a_Scale)
-{
- ASSERT(m_State == 3); // In game mode?
- ASSERT(a_Scale < 256);
-
- cPacketizer Pkt(*this, 0x34);
- Pkt.WriteVarInt32(static_cast<UInt32>(a_MapID));
- Pkt.WriteBEUInt16(2);
-
- Pkt.WriteBEUInt8(2);
- Pkt.WriteBEUInt8(static_cast<Byte>(a_Scale));
+ for (const auto & Decorator : a_Map.GetDecorators())
+ {
+ ASSERT(Decorator.GetPixelX() < 256);
+ ASSERT(Decorator.GetPixelZ() < 256);
+ Pkt.WriteBEUInt8(static_cast<Byte>((Decorator.GetRot() << 4) | static_cast<int>(Decorator.GetType())));
+ Pkt.WriteBEUInt8(static_cast<Byte>(Decorator.GetPixelX()));
+ Pkt.WriteBEUInt8(static_cast<Byte>(Decorator.GetPixelZ()));
+ }
+ }
}
@@ -2646,6 +2637,10 @@ void cProtocol172::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"))
@@ -2732,7 +2727,7 @@ void cProtocol172::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.WriteBEInt16(-1);
return;
@@ -2749,9 +2744,15 @@ void cProtocol172::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());