From 885d8287125439047ca2318f8e349b8da279e612 Mon Sep 17 00:00:00 2001 From: Lukas Pioch Date: Fri, 7 Jul 2017 09:31:45 +0200 Subject: Added bed entity (#3823) * Added bed entity * Export cBedEntity to lua * Set color of bed through item damage value * Added bed entity to APIDoc * NBT: Added loading and saving * Crafting recipes for the colored beds --- src/Protocol/Protocol_1_11.cpp | 12 ++++++++++++ src/Protocol/Protocol_1_12.cpp | 27 +++++++++++++++++++++++++++ src/Protocol/Protocol_1_12.h | 1 + 3 files changed, 40 insertions(+) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index 8f9a0b0b9..e4aaa8f6f 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -30,6 +30,7 @@ Implements the 1.11 protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../BlockEntities/BeaconEntity.h" +#include "../BlockEntities/BedEntity.h" #include "../BlockEntities/CommandBlockEntity.h" #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/MobSpawnerEntity.h" @@ -421,6 +422,17 @@ void cProtocol_1_11_0::WriteBlockEntity(cPacketizer & a_Pkt, const cBlockEntity break; } + case E_BLOCK_BED: + { + auto & BedEntity = reinterpret_cast(a_BlockEntity); + Writer.AddInt("x", BedEntity.GetPosX()); + Writer.AddInt("y", BedEntity.GetPosY()); + Writer.AddInt("z", BedEntity.GetPosZ()); + Writer.AddInt("color", BedEntity.GetColor()); + Writer.AddString("id", "Bed"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + break; + } + case E_BLOCK_COMMAND_BLOCK: { auto & CommandBlockEntity = reinterpret_cast(a_BlockEntity); diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index a0f2b9aa7..904b31ca0 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -1269,6 +1269,33 @@ void cProtocol_1_12::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol_1_12::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x09); // Update tile entity packet + Pkt.WritePosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ()); + + Byte Action = 0; + switch (a_BlockEntity.GetBlockType()) + { + case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing + case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text + case E_BLOCK_BEACON: Action = 3; break; // Update beacon entity + case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity + case E_BLOCK_FLOWER_POT: Action = 5; break; // Update flower pot + case E_BLOCK_BED: Action = 11; break; // Update bed color + default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; + } + Pkt.WriteBEUInt8(Action); + + WriteBlockEntity(Pkt, a_BlockEntity); +} + + + + + void cProtocol_1_12::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_State == 3); // In game mode? diff --git a/src/Protocol/Protocol_1_12.h b/src/Protocol/Protocol_1_12.h index f61b713ae..814932e79 100644 --- a/src/Protocol/Protocol_1_12.h +++ b/src/Protocol/Protocol_1_12.h @@ -59,6 +59,7 @@ public: virtual void SendTeleportEntity(const cEntity & a_Entity) override; virtual void SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override; virtual void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override; + virtual void SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) override; protected: virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) override; virtual void HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) override; -- cgit v1.2.3