2013-09-22 14:34:42 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2014-02-01 09:01:13 -05:00
|
|
|
#include "Chunk.h"
|
2014-03-25 17:26:13 -04:00
|
|
|
#include "MetaRotator.h"
|
2013-09-22 14:34:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockButtonHandler :
|
2014-03-25 17:26:13 -04:00
|
|
|
public cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, true>
|
2013-09-22 14:34:42 -04:00
|
|
|
{
|
|
|
|
public:
|
2013-11-29 17:25:07 -05:00
|
|
|
cBlockButtonHandler(BLOCKTYPE a_BlockType)
|
2014-03-25 17:26:13 -04:00
|
|
|
: cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, true>(a_BlockType)
|
2013-11-29 17:25:07 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-22 14:34:42 -04:00
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
virtual void 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-11-29 17:25:07 -05:00
|
|
|
{
|
2013-12-06 17:29:15 -05:00
|
|
|
// Set p the ON bit to on
|
2014-02-01 08:06:32 -05:00
|
|
|
NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08);
|
2013-11-29 17:25:07 -05:00
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
|
2014-07-02 13:46:00 -04:00
|
|
|
a_WorldInterface.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ);
|
2014-07-12 20:08:02 -04:00
|
|
|
a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", (double)a_BlockX, (double)a_BlockY, (double)a_BlockZ, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f);
|
2013-11-29 17:25:07 -05:00
|
|
|
|
|
|
|
// Queue a button reset (unpress)
|
2014-02-01 08:06:32 -05:00
|
|
|
a_ChunkInterface.QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType, a_WorldInterface);
|
2013-11-29 17:25:07 -05:00
|
|
|
}
|
2013-09-22 14:34:42 -04:00
|
|
|
|
2013-11-18 17:30:34 -05:00
|
|
|
|
2013-09-22 14:34:42 -04:00
|
|
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
|
|
|
{
|
|
|
|
// Reset meta to 0
|
2013-11-18 17:30:34 -05:00
|
|
|
a_Pickups.push_back(cItem(m_BlockType, 1, 0));
|
2013-09-22 14:34:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool IsUseable(void) override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
2014-02-01 08:06:32 -05:00
|
|
|
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
|
2014-07-17 16:50:58 -04:00
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
2013-09-22 14:34:42 -04:00
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
|
|
|
) override
|
|
|
|
{
|
|
|
|
a_BlockType = m_BlockType;
|
|
|
|
a_BlockMeta = BlockFaceToMetaData(a_BlockFace);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual const char * GetStepSound(void) override
|
|
|
|
{
|
|
|
|
return m_BlockType == E_BLOCK_WOODEN_BUTTON ? "step.wood" : "step.stone";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace)
|
2013-09-22 14:34:42 -04:00
|
|
|
{
|
|
|
|
switch (a_BlockFace)
|
|
|
|
{
|
2013-11-29 17:25:07 -05:00
|
|
|
case BLOCK_FACE_ZM: return 0x4;
|
|
|
|
case BLOCK_FACE_ZP: return 0x3;
|
|
|
|
case BLOCK_FACE_XM: return 0x2;
|
|
|
|
case BLOCK_FACE_XP: return 0x1;
|
2013-09-22 14:34:42 -04:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled block face!");
|
2014-07-17 16:15:34 -04:00
|
|
|
return 0x0; // No idea, give a special meta (button in centre of block)
|
2013-09-22 14:34:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-18 17:30:34 -05:00
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta)
|
2013-11-18 17:30:34 -05:00
|
|
|
{
|
|
|
|
switch (a_Meta & 0x7)
|
|
|
|
{
|
|
|
|
case 0x1: return BLOCK_FACE_XP;
|
|
|
|
case 0x2: return BLOCK_FACE_XM;
|
|
|
|
case 0x3: return BLOCK_FACE_ZP;
|
|
|
|
case 0x4: return BLOCK_FACE_ZM;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled block meta!");
|
2014-02-08 19:57:22 -05:00
|
|
|
return BLOCK_FACE_NONE;
|
2013-11-18 17:30:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
2013-11-18 17:30:34 -05:00
|
|
|
{
|
2013-11-21 17:44:18 -05:00
|
|
|
NIBBLETYPE Meta;
|
|
|
|
a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta);
|
2013-11-18 17:30:34 -05:00
|
|
|
|
|
|
|
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
|
2013-11-21 17:44:18 -05:00
|
|
|
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
|
|
|
|
|
2014-06-27 19:29:19 -04:00
|
|
|
return (a_RelY > 0) && (cBlockInfo::FullyOccupiesVoxel(BlockIsOn));
|
2013-11-18 17:30:34 -05:00
|
|
|
}
|
2013-09-22 14:34:42 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|