2012-12-19 04:29:53 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
#include "../Doors.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockFenceGateHandler :
|
|
|
|
public cBlockHandler
|
|
|
|
{
|
|
|
|
public:
|
2013-01-11 23:46:01 -05:00
|
|
|
cBlockFenceGateHandler(BLOCKTYPE a_BlockType) :
|
|
|
|
cBlockHandler(a_BlockType)
|
2012-12-19 04:29:53 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
|
|
|
cWorld * a_World, cPlayer * a_Player,
|
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
|
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
|
|
|
) override
|
2012-12-19 04:29:53 -05:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
a_BlockType = m_BlockType;
|
2012-12-19 04:29:53 -05:00
|
|
|
a_BlockMeta = cDoors::RotationToMetaData(a_Player->GetRotation() + 270);
|
2013-01-11 23:46:01 -05:00
|
|
|
return true;
|
2012-12-19 04:29:53 -05:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
|
2012-12-19 04:29:53 -05:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
NIBBLETYPE OldMetaData = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
|
|
|
NIBBLETYPE NewMetaData = cDoors::RotationToMetaData(a_Player->GetRotation() + 270);
|
2013-03-09 09:35:43 -05:00
|
|
|
OldMetaData ^= 4; // Toggle the gate
|
2013-01-11 23:46:01 -05:00
|
|
|
if ((OldMetaData & 1) == (NewMetaData & 1))
|
2012-12-19 16:19:36 -05:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
// Standing in front of the gate - apply new direction
|
2012-12-19 04:29:53 -05:00
|
|
|
a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (OldMetaData & 4) | (NewMetaData & 3));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
// Standing aside - use last direction
|
2012-12-19 04:29:53 -05:00
|
|
|
a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, OldMetaData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
virtual bool IsUseable(void) override
|
2012-12-19 04:29:53 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|