MCPcopy Create free account
hub / github.com/cuberite/cuberite / WriteItem

Method WriteItem

src/Protocol/Protocol132.cpp:660–695  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

658
659
660void cProtocol132::WriteItem(const cItem & a_Item)
661{
662 short ItemType = a_Item.m_ItemType;
663 ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
664 if (ItemType <= 0)
665 {
666 // Fix, to make sure no invalid values are sent.
667 ItemType = -1;
668 }
669
670 if (a_Item.IsEmpty())
671 {
672 WriteShort(-1);
673 return;
674 }
675
676 WriteShort(ItemType);
677 WriteChar (a_Item.m_ItemCount);
678 WriteShort(a_Item.m_ItemDamage);
679
680 if (a_Item.m_Enchantments.IsEmpty())
681 {
682 WriteShort(-1);
683 return;
684 }
685
686 // Send the enchantments:
687 cFastNBTWriter Writer;
688 const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
689 EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, Writer, TagName);
690 Writer.Finish();
691 AString Compressed;
692 CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
693 WriteShort((short)Compressed.size());
694 SendData(Compressed.data(), Compressed.size());
695}
696
697
698

Callers

nothing calls this directly

Calls 5

CompressStringGZIPFunction · 0.85
GetResultMethod · 0.80
sizeMethod · 0.80
IsEmptyMethod · 0.45
FinishMethod · 0.45

Tested by

no test coverage detected