2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ItemHandler.h"
|
2021-05-05 09:25:10 -04:00
|
|
|
#include "Blocks/BlockBed.h"
|
|
|
|
#include "BlockEntities/BedEntity.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-09-13 06:58:39 -04:00
|
|
|
const auto BlockMeta = cBlockBedHandler::YawToMetaData(a_Player.GetYaw());
|
2021-05-05 09:25:10 -04:00
|
|
|
const auto HeadPosition = a_PlacePosition + cBlockBedHandler::MetaDataToDirection(BlockMeta);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
auto & World = *a_Player.GetWorld();
|
|
|
|
BLOCKTYPE HeadType;
|
|
|
|
NIBBLETYPE HeadMeta;
|
|
|
|
World.GetBlockTypeMeta(HeadPosition, HeadType, HeadMeta);
|
|
|
|
|
|
|
|
// Vanilla only allows beds to be placed into air.
|
2014-12-24 01:20:17 -05:00
|
|
|
// Check if there is empty space for the "head" block:
|
2021-05-05 09:25:10 -04:00
|
|
|
if (!cBlockHandler::For(HeadType).DoesIgnoreBuildCollision(World, a_HeldItem, HeadPosition, HeadMeta, a_ClickedBlockFace, false))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-13 06:58:39 -04:00
|
|
|
|
|
|
|
// The "foot", and the "head" block:
|
2021-05-05 09:25:10 -04:00
|
|
|
if (
|
|
|
|
!a_Player.PlaceBlocks(
|
|
|
|
{
|
|
|
|
{ a_PlacePosition, E_BLOCK_BED, BlockMeta },
|
|
|
|
{ HeadPosition, E_BLOCK_BED, static_cast<NIBBLETYPE>(BlockMeta | 0x08) }
|
|
|
|
})
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto SetColor = [&a_HeldItem](cBlockEntity & a_BlockEntity)
|
|
|
|
{
|
|
|
|
ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_BED);
|
|
|
|
|
|
|
|
static_cast<cBedEntity &>(a_BlockEntity).SetColor(a_HeldItem.m_ItemDamage);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
World.DoWithBlockEntityAt(a_PlacePosition, SetColor);
|
|
|
|
World.DoWithBlockEntityAt(HeadPosition, SetColor);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool IsPlaceable(void) override
|
|
|
|
{
|
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
|
|
|
};
|