summaryrefslogtreecommitdiffstats
path: root/source/Blocks/BlockButton.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2013-09-24 11:31:57 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2013-09-24 11:31:57 +0200
commit21b23ff1e74d6735801f5aaf7ae1659b8c787f7a (patch)
treed5d606cf69a6f3945bbb8e1c8a80821654a86998 /source/Blocks/BlockButton.cpp
parentMerge pull request #1 from tigerw/bugfixes (diff)
parentRemoved some unneeded includes (diff)
downloadcuberite-21b23ff1e74d6735801f5aaf7ae1659b8c787f7a.tar
cuberite-21b23ff1e74d6735801f5aaf7ae1659b8c787f7a.tar.gz
cuberite-21b23ff1e74d6735801f5aaf7ae1659b8c787f7a.tar.bz2
cuberite-21b23ff1e74d6735801f5aaf7ae1659b8c787f7a.tar.lz
cuberite-21b23ff1e74d6735801f5aaf7ae1659b8c787f7a.tar.xz
cuberite-21b23ff1e74d6735801f5aaf7ae1659b8c787f7a.tar.zst
cuberite-21b23ff1e74d6735801f5aaf7ae1659b8c787f7a.zip
Diffstat (limited to '')
-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);
+}
+
+
+
+