2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ItemHandler.h"
|
|
|
|
#include "../World.h"
|
|
|
|
#include "../Blocks/BlockBed.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
class cItemBedHandler:
|
2013-07-29 07:13:03 -04:00
|
|
|
public cItemHandler
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
using Super = cItemHandler;
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
cItemBedHandler(int a_ItemType):
|
|
|
|
Super(a_ItemType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual bool IsPlaceable(void) override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-24 01:20:17 -05:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-21 13:49:22 -04:00
|
|
|
virtual bool GetBlocksToPlace(
|
2020-04-21 16:19:22 -04:00
|
|
|
cWorld & a_World,
|
|
|
|
cPlayer & a_Player,
|
|
|
|
const cItem & a_EquippedItem,
|
|
|
|
const Vector3i a_PlacedBlockPos,
|
|
|
|
eBlockFace a_ClickedBlockFace,
|
|
|
|
const Vector3i a_CursorPos,
|
2015-06-21 13:49:22 -04:00
|
|
|
sSetBlockVector & a_BlocksToPlace
|
2013-07-29 07:13:03 -04:00
|
|
|
) override
|
|
|
|
{
|
2014-12-24 01:20:17 -05:00
|
|
|
// Can only be placed on the floor:
|
2020-04-21 16:19:22 -04:00
|
|
|
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-24 01:20:17 -05:00
|
|
|
// The "foot" block:
|
2020-04-08 16:35:08 -04:00
|
|
|
NIBBLETYPE BlockMeta = cBlockBedHandler::YawToMetaData(a_Player.GetYaw());
|
2020-04-21 16:19:22 -04:00
|
|
|
a_BlocksToPlace.emplace_back(a_PlacedBlockPos, E_BLOCK_BED, BlockMeta);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-12-24 01:20:17 -05:00
|
|
|
// Check if there is empty space for the "head" block:
|
|
|
|
// (Vanilla only allows beds to be placed into air)
|
2020-04-21 16:19:22 -04:00
|
|
|
auto Direction = cBlockBedHandler::MetaDataToDirection(BlockMeta);
|
|
|
|
auto HeadPos = a_PlacedBlockPos + Direction;
|
|
|
|
if (a_World.GetBlock(HeadPos) != E_BLOCK_AIR)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-21 16:19:22 -04:00
|
|
|
a_BlocksToPlace.emplace_back(HeadPos, E_BLOCK_BED, BlockMeta | 0x08);
|
2015-06-21 13:49:22 -04:00
|
|
|
return true;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2020-04-21 16:19:22 -04:00
|
|
|
};
|