From a8a45a4afc615926a705eee482c27ef166f2f9ec Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Sep 2013 19:34:42 +0100 Subject: Added button placement handler Also removed an unneeded variable in the stair handler --- source/Blocks/BlockButton.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 source/Blocks/BlockButton.cpp (limited to 'source/Blocks/BlockButton.cpp') diff --git a/source/Blocks/BlockButton.cpp b/source/Blocks/BlockButton.cpp new file mode 100644 index 000000000..8df399cf0 --- /dev/null +++ b/source/Blocks/BlockButton.cpp @@ -0,0 +1,40 @@ + +#include "Globals.h" +#include "BlockButton.h" +#include "../Simulator/RedstoneSimulator.h" + + + + + +cBlockButtonHandler::cBlockButtonHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) +{ +} + + + + + +void cBlockButtonHandler::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) +{ + // Flip the ON bit on/off. Using XOR bitwise operation to turn it on/off. + NIBBLETYPE Meta = ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f); + a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + + if (Meta & 0x08) + { + a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); + } + else + { + a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.5f); + } + + // Queue a button reset (unpress), with a GetBlock to prevent duplication of buttons (press, break, wait for reset) + a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 25); +} + + + + -- cgit v1.2.3 From dad3648102c5861ed691ac90bd265bcc5667e787 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Sep 2013 19:48:59 +0100 Subject: Removed some unneeded includes --- source/Blocks/BlockButton.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'source/Blocks/BlockButton.cpp') diff --git a/source/Blocks/BlockButton.cpp b/source/Blocks/BlockButton.cpp index 8df399cf0..1011f9351 100644 --- a/source/Blocks/BlockButton.cpp +++ b/source/Blocks/BlockButton.cpp @@ -1,7 +1,6 @@ #include "Globals.h" #include "BlockButton.h" -#include "../Simulator/RedstoneSimulator.h" -- cgit v1.2.3