summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockBed.cpp
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/Blocks/BlockBed.cpp
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 'src/Blocks/BlockBed.cpp')
-rw-r--r--src/Blocks/BlockBed.cpp62
1 files changed, 60 insertions, 2 deletions
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp
index adc01c158..d6112f853 100644
--- a/src/Blocks/BlockBed.cpp
+++ b/src/Blocks/BlockBed.cpp
@@ -1,3 +1,6 @@
+
+// BlockBed.cpp
+
#include "Globals.h"
#include "BlockBed.h"
@@ -7,6 +10,7 @@
#include "../BoundingBox.h"
#include "../Mobs/Monster.h"
#include "../Entities/Entity.h"
+#include "../BlockEntities/BedEntity.h"
@@ -16,14 +20,19 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt
{
NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- Vector3i ThisPos( a_BlockX, a_BlockY, a_BlockZ);
- Vector3i Direction = MetaDataToDirection( OldMeta & 0x3);
+ Vector3i ThisPos(a_BlockX, a_BlockY, a_BlockZ);
+ Vector3i Direction = MetaDataToDirection(OldMeta & 0x3);
if (OldMeta & 0x8)
{
// Was pillow
if (a_ChunkInterface.GetBlock(ThisPos - Direction) == E_BLOCK_BED)
{
+ // First replace the bed with air
a_ChunkInterface.FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0);
+
+ // Then destroy the bed entity
+ Vector3i PillowPos(ThisPos - Direction);
+ a_ChunkInterface.SetBlock(PillowPos.x, PillowPos.y, PillowPos.z, E_BLOCK_AIR, 0);
}
}
else
@@ -31,7 +40,12 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt
// Was foot end
if (a_ChunkInterface.GetBlock(ThisPos + Direction) == E_BLOCK_BED)
{
+ // First replace the bed with air
a_ChunkInterface.FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0);
+
+ // Then destroy the bed entity
+ Vector3i FootPos(ThisPos + Direction);
+ a_ChunkInterface.SetBlock(FootPos.x, FootPos.y, FootPos.z, E_BLOCK_AIR, 0);
}
}
}
@@ -169,4 +183,48 @@ bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
+void cBlockBedHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, const sSetBlock & a_BlockChange)
+{
+ class cBedColor :
+ public cBedCallback
+ {
+ public:
+ short m_Color;
+ cBedColor(short a_Color) :
+ m_Color(a_Color)
+ {
+ }
+
+ virtual bool Item(cBedEntity * a_Bed) override
+ {
+ a_Bed->SetColor(m_Color);
+ return true;
+ }
+ };
+ cBedColor BedCallback(a_Player->GetEquippedItem().m_ItemDamage);
+ a_Player->GetWorld()->DoWithBedAt(a_BlockChange.GetX(), a_BlockChange.GetY(), a_BlockChange.GetZ(), BedCallback);
+}
+
+
+
+
+
+void cBlockBedHandler::ConvertToPickups(cEntity * a_Digger, cItems & a_Pickups, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ class cBedColor :
+ public cBedCallback
+ {
+ public:
+ short m_Color = E_META_WOOL_RED;
+
+ virtual bool Item(cBedEntity * a_Bed) override
+ {
+ m_Color = a_Bed->GetColor();
+ return true;
+ }
+ };
+ cBedColor BedCallback;
+ a_Digger->GetWorld()->DoWithBedAt(a_BlockX, a_BlockY, a_BlockZ, BedCallback);
+ a_Pickups.Add(cItem(E_ITEM_BED, 1, BedCallback.m_Color));
+}