summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockButton.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2015-06-27 00:24:51 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2015-12-18 14:17:38 +0100
commit5b62c4c3145c08b093521e42c565922fa85de4ad (patch)
treedca8cbfe86aa27af174da21f6835a8fbbe83d248 /src/Blocks/BlockButton.h
parentMerge pull request #2770 from cuberite/RemoveChunkDataCollector (diff)
downloadcuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar
cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.gz
cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.bz2
cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.lz
cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.xz
cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.tar.zst
cuberite-5b62c4c3145c08b093521e42c565922fa85de4ad.zip
Diffstat (limited to 'src/Blocks/BlockButton.h')
-rw-r--r--src/Blocks/BlockButton.h26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index 7f6c3e56f..354d563fd 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -38,14 +38,18 @@ public:
a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", x, y, z, 0.5f, 0.6f);
// Queue a button reset (unpress)
- int delay = (m_BlockType == E_BLOCK_STONE_BUTTON) ? 20 : 30;
-
- a_ChunkInterface.QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), delay, m_BlockType, a_WorldInterface);
-
- a_Player->GetWorld()->ScheduleTask(delay, [x, y, z](cWorld & a_World)
- {
- a_World.BroadcastSoundEffect("random.click", x, y, z, 0.5f, 0.5f);
- });
+ auto TickDelay = (m_BlockType == E_BLOCK_STONE_BUTTON) ? 20 : 30;
+ a_Player->GetWorld()->ScheduleTask(TickDelay, [x, y, z, a_BlockX, a_BlockY, a_BlockZ, this](cWorld & a_World)
+ {
+ if (a_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ) == m_BlockType)
+ {
+ // Block hasn't change in the meantime; set its meta
+ a_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07);
+ a_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ);
+ a_World.BroadcastSoundEffect("random.click", x, y, z, 0.5f, 0.5f);
+ }
+ }
+ );
return true;
}
@@ -129,6 +133,12 @@ public:
UNUSED(a_Meta);
return 0;
}
+
+ /** Extracts the ON bit from metadata and returns if true if it is set */
+ static bool IsButtonOn(NIBBLETYPE a_BlockMeta)
+ {
+ return ((a_BlockMeta & 0x8) == 0x8);
+ }
} ;