summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorLukas Pioch <lukas@zgow.de>2017-07-07 09:31:45 +0200
committerGitHub <noreply@github.com>2017-07-07 09:31:45 +0200
commit885d8287125439047ca2318f8e349b8da279e612 (patch)
tree2f54b688dba0f49b64544d3c1220a16a6936cd6f /src/BlockEntities
parentChanged Lua plugins to only execute files ending in .lua (#3831) (diff)
downloadcuberite-885d8287125439047ca2318f8e349b8da279e612.tar
cuberite-885d8287125439047ca2318f8e349b8da279e612.tar.gz
cuberite-885d8287125439047ca2318f8e349b8da279e612.tar.bz2
cuberite-885d8287125439047ca2318f8e349b8da279e612.tar.lz
cuberite-885d8287125439047ca2318f8e349b8da279e612.tar.xz
cuberite-885d8287125439047ca2318f8e349b8da279e612.tar.zst
cuberite-885d8287125439047ca2318f8e349b8da279e612.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BedEntity.cpp56
-rw-r--r--src/BlockEntities/BedEntity.h45
-rw-r--r--src/BlockEntities/BlockEntity.cpp3
-rw-r--r--src/BlockEntities/CMakeLists.txt2
4 files changed, 106 insertions, 0 deletions
diff --git a/src/BlockEntities/BedEntity.cpp b/src/BlockEntities/BedEntity.cpp
new file mode 100644
index 000000000..b8f61c049
--- /dev/null
+++ b/src/BlockEntities/BedEntity.cpp
@@ -0,0 +1,56 @@
+
+// BedEntity.cpp
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BedEntity.h"
+#include "../World.h"
+#include "../Entities/Player.h"
+#include "../ClientHandle.h"
+#include "../Blocks/BlockBed.h"
+
+cBedEntity::cBedEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, short a_Color):
+ Super(a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World),
+ m_Color(a_Color)
+{
+ ASSERT(a_BlockType == E_BLOCK_BED);
+}
+
+
+
+
+
+void cBedEntity::CopyFrom(const cBlockEntity & a_Src)
+{
+ Super::CopyFrom(a_Src);
+ auto & src = reinterpret_cast<const cBedEntity &>(a_Src);
+ m_Color = src.m_Color;
+}
+
+
+
+
+
+void cBedEntity::SendTo(cClientHandle & a_Client)
+{
+ a_Client.SendUpdateBlockEntity(*this);
+}
+
+
+
+
+
+void cBedEntity::SetColor(short a_Color)
+{
+ m_Color = a_Color;
+ int posX = m_PosX;
+ int posY = m_PosY;
+ int posZ = m_PosZ;
+
+ // If the bed entity is send immediately, the client (maybe) still has not the bed.
+ // Fix that by delaying the broadcast of the bed entity by a tick:
+ m_World->ScheduleTask(1, [posX, posY, posZ](cWorld & a_World)
+ {
+ a_World.BroadcastBlockEntity(posX, posY, posZ);
+ });
+}
diff --git a/src/BlockEntities/BedEntity.h b/src/BlockEntities/BedEntity.h
new file mode 100644
index 000000000..8caa205c4
--- /dev/null
+++ b/src/BlockEntities/BedEntity.h
@@ -0,0 +1,45 @@
+
+// BedEntity.h
+
+#pragma once
+
+#include "BlockEntity.h"
+
+
+
+
+
+// tolua_begin
+
+class cBedEntity :
+ public cBlockEntity
+{
+ typedef cBlockEntity Super;
+public:
+ // tolua_end
+
+ BLOCKENTITY_PROTODEF(cBedEntity)
+
+ cBedEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, short a_Color = E_META_WOOL_RED);
+
+ // tolua_begin
+
+ /** Returns the color of the bed */
+ short GetColor(void) const { return m_Color; }
+
+ /** Set the color of the bed. */
+ void SetColor(short a_Color);
+
+ /** Returns true if this is the pillow block, it has then the meta 8. */
+ bool IsPillowBlock(void) { return ((m_BlockMeta & 0x08) == 0x08); }
+
+ // tolua_end
+
+ // cBlockEntity overrides:
+ virtual void CopyFrom(const cBlockEntity & a_Src) override;
+ virtual bool UsedBy(cPlayer * a_Player) override { return false; }
+ virtual void SendTo(cClientHandle & a_Client) override;
+
+private:
+ short m_Color;
+}; // tolua_export
diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp
index f60eb5622..f2380734a 100644
--- a/src/BlockEntities/BlockEntity.cpp
+++ b/src/BlockEntities/BlockEntity.cpp
@@ -5,6 +5,7 @@
#include "Globals.h"
#include "BeaconEntity.h"
+#include "BedEntity.h"
#include "BlockEntity.h"
#include "BrewingstandEntity.h"
#include "ChestEntity.h"
@@ -42,6 +43,7 @@ bool cBlockEntity::IsBlockEntityBlockType(BLOCKTYPE a_BlockType)
switch (a_BlockType)
{
case E_BLOCK_BEACON:
+ case E_BLOCK_BED:
case E_BLOCK_BREWING_STAND:
case E_BLOCK_CHEST:
case E_BLOCK_COMMAND_BLOCK:
@@ -75,6 +77,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE
switch (a_BlockType)
{
case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World);
+ case E_BLOCK_BED: return new cBedEntity (a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_BREWING_STAND: return new cBrewingstandEntity(a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_CHEST: return new cChestEntity (a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World);
diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt
index d6bf6355c..93033931c 100644
--- a/src/BlockEntities/CMakeLists.txt
+++ b/src/BlockEntities/CMakeLists.txt
@@ -4,6 +4,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
SET (SRCS
BeaconEntity.cpp
+ BedEntity.cpp
BlockEntity.cpp
BlockEntityWithItems.cpp
BrewingstandEntity.cpp
@@ -25,6 +26,7 @@ SET (SRCS
SET (HDRS
BeaconEntity.h
+ BedEntity.h
BlockEntity.h
BlockEntityWithItems.h
BrewingstandEntity.h