summaryrefslogtreecommitdiffstats
path: root/source/Blocks/BlockButton.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2013-09-22 21:31:53 +0200
committerMattes D <github@xoft.cz>2013-09-22 21:31:53 +0200
commit63c627f68fbfe7b97fb04f0a40b44423cd12c366 (patch)
tree3f52eb0bc26015e90492d4cabdb3150984fb94b3 /source/Blocks/BlockButton.cpp
parentAdded a simple valgrind script for easier testing. (diff)
parentRemoved some unneeded includes (diff)
downloadcuberite-63c627f68fbfe7b97fb04f0a40b44423cd12c366.tar
cuberite-63c627f68fbfe7b97fb04f0a40b44423cd12c366.tar.gz
cuberite-63c627f68fbfe7b97fb04f0a40b44423cd12c366.tar.bz2
cuberite-63c627f68fbfe7b97fb04f0a40b44423cd12c366.tar.lz
cuberite-63c627f68fbfe7b97fb04f0a40b44423cd12c366.tar.xz
cuberite-63c627f68fbfe7b97fb04f0a40b44423cd12c366.tar.zst
cuberite-63c627f68fbfe7b97fb04f0a40b44423cd12c366.zip
Diffstat (limited to 'source/Blocks/BlockButton.cpp')
-rw-r--r--source/Blocks/BlockButton.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/source/Blocks/BlockButton.cpp b/source/Blocks/BlockButton.cpp
new file mode 100644
index 000000000..1011f9351
--- /dev/null
+++ b/source/Blocks/BlockButton.cpp
@@ -0,0 +1,39 @@
+
+#include "Globals.h"
+#include "BlockButton.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);
+}
+
+
+
+