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"
|
2015-02-08 16:21:48 -05:00
|
|
|
#include "ChunkInterface.h"
|
2021-05-14 05:42:08 -04:00
|
|
|
#include "Entities/Player.h"
|
|
|
|
#include "Mixins.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 cWorldInterface;
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-14 05:42:08 -04:00
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockBedHandler final :
|
2020-04-10 07:25:36 -04:00
|
|
|
public cYawRotator<cBlockEntityHandler, 0x03, 0x02, 0x03, 0x00, 0x01>
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cYawRotator<cBlockEntityHandler, 0x03, 0x02, 0x03, 0x00, 0x01>;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
|
|
|
|
|
|
|
static Vector3i MetaDataToDirection(NIBBLETYPE a_MetaData)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-09-20 09:50:52 -04:00
|
|
|
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();
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2021-04-09 18:18:09 -04:00
|
|
|
static void VacateBed(cChunkInterface & a_ChunkInterface, cPlayer & a_Player)
|
2020-09-20 09:50:52 -04:00
|
|
|
{
|
2021-04-09 18:18:09 -04:00
|
|
|
auto BedPosition = a_Player.GetLastBedPos();
|
|
|
|
|
|
|
|
BLOCKTYPE Type;
|
|
|
|
NIBBLETYPE Meta;
|
|
|
|
a_ChunkInterface.GetBlockTypeMeta(BedPosition, Type, Meta);
|
|
|
|
|
|
|
|
if (Type != E_BLOCK_BED)
|
2020-09-20 09:50:52 -04:00
|
|
|
{
|
2021-04-09 18:18:09 -04:00
|
|
|
// Bed was incomplete, just wake:
|
|
|
|
a_Player.SetIsInBed(false);
|
|
|
|
return;
|
2020-09-20 09:50:52 -04:00
|
|
|
}
|
2021-04-09 18:18:09 -04:00
|
|
|
|
|
|
|
if ((Meta & 0x8) == 0)
|
2020-09-20 09:50:52 -04:00
|
|
|
{
|
2021-04-09 18:18:09 -04:00
|
|
|
// BedPosition is the foot of the bed, adjust to the head:
|
|
|
|
BedPosition += MetaDataToDirection(Meta & 0x03);
|
|
|
|
|
|
|
|
a_ChunkInterface.GetBlockTypeMeta(BedPosition, Type, Meta);
|
|
|
|
if (Type != E_BLOCK_BED)
|
|
|
|
{
|
|
|
|
// Bed was incomplete, just wake:
|
|
|
|
a_Player.SetIsInBed(false);
|
|
|
|
return;
|
|
|
|
}
|
2020-09-20 09:50:52 -04:00
|
|
|
}
|
2017-07-07 03:31:45 -04:00
|
|
|
|
2021-04-09 18:18:09 -04:00
|
|
|
// Clear the "occupied" bit of the bed's pillow block:
|
|
|
|
a_ChunkInterface.SetBlockMeta(BedPosition, Meta & 0x0b);
|
|
|
|
|
|
|
|
// Wake the player:
|
|
|
|
a_Player.SetIsInBed(false);
|
2020-09-20 09:50:52 -04:00
|
|
|
}
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
// Overrides:
|
2020-04-21 16:19:22 -04:00
|
|
|
virtual void OnBroken(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
|
|
|
const Vector3i a_BlockPos,
|
2020-10-08 15:13:44 -04:00
|
|
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
|
|
|
|
const cEntity * a_Digger
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override;
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
virtual bool OnUse(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player,
|
|
|
|
const Vector3i a_ClickedBlockPos,
|
|
|
|
eBlockFace a_ClickedBlockFace,
|
|
|
|
const Vector3i a_CursorPos
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override;
|
2020-04-21 16:19:22 -04:00
|
|
|
|
2021-03-28 09:41:34 -04:00
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cItem * a_Tool) const override;
|
2020-04-21 16:19:22 -04:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-07 03:31:45 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
2015-06-30 10:50:15 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 28;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|