diff options
Diffstat (limited to 'source/Piston.cpp')
-rw-r--r-- | source/Piston.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/source/Piston.cpp b/source/Piston.cpp index d1d2b96a4..2431bdac2 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -20,6 +20,13 @@ extern bool g_BlockPistonBreakable[]; +/// Number of ticks that the piston extending / retracting waits before setting the block +const int PISTON_TICK_DELAY = 5; + + + + + cPiston::cPiston(cWorld * a_World) : m_World(a_World) { @@ -39,16 +46,16 @@ int cPiston::FirstPassthroughBlock(int pistonX, int pistonY, int pistonZ, NIBBLE NIBBLETYPE currMeta; AddDir(pistonX, pistonY, pistonZ, pistonmeta, 1); m_World->GetBlockTypeMeta(pistonX, pistonY, pistonZ, currBlock, currMeta); - if (!CanPush(currBlock, currMeta)) - { - // This block cannot be pushed at all, the piston can't extend - return -1; - } if (CanBreakPush(currBlock, currMeta)) { // This block breaks when pushed, extend up to here return ret; } + if (!CanPush(currBlock, currMeta)) + { + // This block cannot be pushed at all, the piston can't extend + return -1; + } } // There is no space for the blocks to move, piston can't extend return -1; @@ -98,7 +105,7 @@ void cPiston::ExtendPiston(int pistx, int pisty, int pistz) { AddDir(pistx, pisty, pistz, pistonMeta, -1); m_World->GetBlockTypeMeta(pistx, pisty, pistz, currBlock, currBlockMeta); - m_World->QueueSetBlock( oldx, oldy, oldz, currBlock, currBlockMeta, 80); + m_World->QueueSetBlock( oldx, oldy, oldz, currBlock, currBlockMeta, PISTON_TICK_DELAY); oldx = pistx; oldy = pisty; oldz = pistz; @@ -113,14 +120,14 @@ void cPiston::ExtendPiston(int pistx, int pisty, int pistz) m_World->BroadcastBlockAction(pistx, pisty, pistz, 0, pistonMeta, pistonBlock); m_World->BroadcastSoundEffect("tile.piston.out", pistx * 8, pisty * 8, pistz * 8, 0.5f, 0.7f); m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 0x8 ); - m_World->QueueSetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, pistonMeta | (IsSticky(pistonBlock) ? 8 : 0), 80); + m_World->QueueSetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, pistonMeta | (IsSticky(pistonBlock) ? 8 : 0), PISTON_TICK_DELAY); } -void cPiston::RetractPiston( int pistx, int pisty, int pistz ) +void cPiston::RetractPiston(int pistx, int pisty, int pistz) { BLOCKTYPE pistonBlock; NIBBLETYPE pistonMeta; @@ -133,7 +140,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) m_World->BroadcastBlockAction(pistx, pisty, pistz, 1, pistonMeta & ~(8), pistonBlock); m_World->BroadcastSoundEffect("tile.piston.in", pistx * 8, pisty * 8, pistz * 8, 0.5f, 0.7f); - m_World->QueueSetBlock(pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8), 80); + m_World->QueueSetBlock(pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8), PISTON_TICK_DELAY); // Check the extension: @@ -155,18 +162,18 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) if (CanPull(tempBlock, tempMeta)) { // Pull the block - m_World->QueueSetBlock(pistx, pisty, pistz, tempBlock, tempMeta, 80); - m_World->QueueSetBlock(tempx, tempy, tempz, E_BLOCK_AIR, 0, 80); + m_World->QueueSetBlock(pistx, pisty, pistz, tempBlock, tempMeta, PISTON_TICK_DELAY); + m_World->QueueSetBlock(tempx, tempy, tempz, E_BLOCK_AIR, 0, PISTON_TICK_DELAY); } else { // Retract without pulling - m_World->QueueSetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0, 80); + m_World->QueueSetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0, PISTON_TICK_DELAY); } } else { - m_World->QueueSetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0, 80); + m_World->QueueSetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0, PISTON_TICK_DELAY); } } @@ -228,6 +235,7 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { return false; } + case E_BLOCK_STICKY_PISTON: case E_BLOCK_PISTON: { // A piston can only be pushed if retracted: |