1
0
cuberite-2a/src/Blocks/BlockBed.cpp

89 lines
2.4 KiB
C++
Raw Normal View History

#include "Globals.h"
#include "BlockBed.h"
void cBlockBedHandler::OnPlacedByPlayer(
2014-02-01 13:06:32 +00:00
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
int a_CursorX, int a_CursorY, int a_CursorZ,
BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
)
{
if (a_BlockMeta < 8)
{
Vector3i Direction = MetaDataToDirection(a_BlockMeta);
2014-02-01 13:06:32 +00:00
a_ChunkInterface.SetBlock(a_WorldInterface,a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8);
}
}
2014-02-01 13:06:32 +00:00
void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
{
2014-02-01 13:06:32 +00:00
NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
Vector3i ThisPos( a_BlockX, a_BlockY, a_BlockZ );
Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 );
if (OldMeta & 0x8)
{
// Was pillow
2014-02-01 13:06:32 +00:00
if (a_ChunkInterface.GetBlock(ThisPos - Direction) == E_BLOCK_BED)
{
2014-02-01 13:06:32 +00:00
a_ChunkInterface.FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0);
}
}
else
{
// Was foot end
2014-02-01 13:06:32 +00:00
if (a_ChunkInterface.GetBlock(ThisPos + Direction) == E_BLOCK_BED)
{
2014-02-01 13:06:32 +00:00
a_ChunkInterface.FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0);
}
}
}
void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
2014-02-01 13:06:32 +00:00
if (a_WorldInterface.GetDimension() != dimOverworld)
{
Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ);
2014-02-01 13:06:32 +00:00
a_WorldInterface.DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords);
}
else
{
2014-02-01 13:06:32 +00:00
if (a_WorldInterface.GetTimeOfDay() > 13000)
{
2014-02-01 13:06:32 +00:00
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
if (Meta & 0x8)
{
// Is pillow
2014-02-01 13:06:32 +00:00
a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ);
}
else
{
// Is foot end
Vector3i Direction = MetaDataToDirection( Meta & 0x7 );
2014-02-01 13:06:32 +00:00
if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping
{
2014-02-01 13:06:32 +00:00
a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z);
}
}
} else {
2014-02-05 23:24:16 +00:00
a_Player->SendMessageFailure("You can only sleep at night");
}
}
}