diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2015-12-19 22:20:56 +0100 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2015-12-19 22:20:56 +0100 |
commit | b8752bb26e91bcdcebfb8dd43e5794251ff70a89 (patch) | |
tree | 95048f5a2a833c1d43785f6eaea070627c2b9ebe /src/Blocks/BlockButton.h | |
parent | Merge pull request #2776 from cuberite/AtomicBoolIsthread (diff) | |
parent | Reorganised the redstone simulator (diff) | |
download | cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.gz cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.bz2 cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.lz cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.xz cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.tar.zst cuberite-b8752bb26e91bcdcebfb8dd43e5794251ff70a89.zip |
Diffstat (limited to 'src/Blocks/BlockButton.h')
-rw-r--r-- | src/Blocks/BlockButton.h | 26 |
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); + } } ; |