2013-07-29 07:13:03 -04:00
|
|
|
|
2017-07-07 03:31:45 -04:00
|
|
|
// BlockBed.h
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
#pragma once
|
|
|
|
|
2017-07-07 03:31:45 -04:00
|
|
|
#include "BlockEntity.h"
|
2014-03-25 17:26:13 -04:00
|
|
|
#include "MetaRotator.h"
|
2015-02-08 16:21:48 -05:00
|
|
|
#include "ChunkInterface.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
2017-08-07 03:08:27 -04:00
|
|
|
class cEntity;
|
2014-09-26 13:13:19 -04:00
|
|
|
class cPlayer;
|
|
|
|
class cWorldInterface;
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockBedHandler :
|
2017-07-07 03:31:45 -04:00
|
|
|
public cMetaRotator<cBlockEntityHandler, 0x3, 0x02, 0x03, 0x00, 0x01, true>
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
cBlockBedHandler(BLOCKTYPE a_BlockType)
|
2017-07-07 03:31:45 -04:00
|
|
|
: cMetaRotator<cBlockEntityHandler, 0x3, 0x02, 0x03, 0x00, 0x01, true>(a_BlockType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override;
|
2017-07-07 03:31:45 -04:00
|
|
|
|
2017-07-31 16:17:52 -04:00
|
|
|
virtual bool 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) override;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
virtual bool IsUseable(void) override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-07-07 03:31:45 -04:00
|
|
|
virtual void ConvertToPickups(cItems & Pickups, NIBBLETYPE Meta) override {}
|
|
|
|
|
2017-08-25 05:56:01 -04:00
|
|
|
virtual void ConvertToPickups(cWorldInterface & a_WorldInterface, cItems & a_Pickups, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ) override;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// Bed specific helper functions
|
|
|
|
static NIBBLETYPE RotationToMetaData(double a_Rotation)
|
|
|
|
{
|
|
|
|
a_Rotation += 180 + (180 / 4); // So its not aligned with axis
|
2014-12-05 10:59:11 -05:00
|
|
|
if (a_Rotation > 360)
|
|
|
|
{
|
|
|
|
a_Rotation -= 360;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
a_Rotation = (a_Rotation / 360) * 4;
|
|
|
|
|
2015-05-24 07:56:56 -04:00
|
|
|
return (static_cast<NIBBLETYPE>(a_Rotation + 2)) % 4;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static Vector3i MetaDataToDirection(NIBBLETYPE a_MetaData)
|
|
|
|
{
|
|
|
|
switch (a_MetaData)
|
|
|
|
{
|
|
|
|
case 0: return Vector3i(0, 0, 1);
|
|
|
|
case 1: return Vector3i(-1, 0, 0);
|
|
|
|
case 2: return Vector3i(0, 0, -1);
|
|
|
|
case 3: return Vector3i(1, 0, 0);
|
|
|
|
}
|
|
|
|
return Vector3i();
|
|
|
|
}
|
2015-02-08 16:21:48 -05:00
|
|
|
|
|
|
|
static void SetBedOccupationState(cChunkInterface & a_ChunkInterface, const Vector3i & a_BedPosition, bool a_IsOccupied)
|
|
|
|
{
|
2017-11-20 06:13:11 -05:00
|
|
|
auto Meta = a_ChunkInterface.GetBlockMeta(a_BedPosition);
|
2015-02-08 16:21:48 -05:00
|
|
|
if (a_IsOccupied)
|
|
|
|
{
|
|
|
|
Meta |= 0x04; // Where 0x4 = occupied bit
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Meta &= 0x0b; // Clear the "occupied" bit of the bed's block
|
|
|
|
}
|
|
|
|
|
|
|
|
a_ChunkInterface.SetBlockMeta(a_BedPosition.x, a_BedPosition.y, a_BedPosition.z, Meta);
|
|
|
|
}
|
2015-06-30 10:50:15 -04:00
|
|
|
|
2017-07-31 16:17:52 -04:00
|
|
|
virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, const sSetBlock & a_BlockChange) override;
|
2017-07-07 03:31:45 -04:00
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
|
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 28;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|