From 744c0187ba3413d29c008f8ff5177f54540bf65b Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Wed, 9 Nov 2011 01:31:19 +0000 Subject: Redstone clocks now work. even one clocks. torches don't update themselves when placed yet, but redstone wire updates the torch. Fixed a bug with piston animations. git-svn-id: http://mc-server.googlecode.com/svn/trunk@80 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cChunk.cpp | 8 +- source/cPiston.cpp | 5 +- source/cRedstone.cpp | 347 ++++++++++++++++++++++++++++++++++++--------------- source/cRedstone.h | 5 +- source/cWorld.cpp | 35 ++++++ source/cWorld.h | 6 + 6 files changed, 298 insertions(+), 108 deletions(-) (limited to 'source') diff --git a/source/cChunk.cpp b/source/cChunk.cpp index a9c40bfe0..12b54c25e 100644 --- a/source/cChunk.cpp +++ b/source/cChunk.cpp @@ -215,7 +215,7 @@ void cChunk::Tick(float a_Dt) std::map< unsigned int, int > ToTickBlocks = m_pState->m_ToTickBlocks; unsigned int NumTickBlocks = ToTickBlocks.size(); - if( NumTickBlocks > 0 ) LOG("To tick: %i", NumTickBlocks ); + //if( NumTickBlocks > 0 ) LOG("To tick: %i", NumTickBlocks ); m_pState->m_ToTickBlocks.clear(); bool isRedstone = false; for( std::map< unsigned int, int>::iterator itr = ToTickBlocks.begin(); itr != ToTickBlocks.end(); ++itr ) @@ -345,9 +345,9 @@ void cChunk::Tick(float a_Dt) FastSetBlock( m_BlockTickX, m_BlockTickY, m_BlockTickZ, E_BLOCK_GRASS, GetLight( m_BlockMeta, Index ) ); } if ( (g_BlockOneHitDig[AboveBlock]) && GetLight( m_BlockSkyLight, Index+1 ) > 0xf/2 ) // Half lit //ch$ - { - FastSetBlock( m_BlockTickX, m_BlockTickY, m_BlockTickZ, E_BLOCK_GRASS, GetLight( m_BlockMeta, Index ) ); - } + { + FastSetBlock( m_BlockTickX, m_BlockTickY, m_BlockTickZ, E_BLOCK_GRASS, GetLight( m_BlockMeta, Index ) ); + } } break; diff --git a/source/cPiston.cpp b/source/cPiston.cpp index 928d7c04b..1104122c8 100644 --- a/source/cPiston.cpp +++ b/source/cPiston.cpp @@ -16,6 +16,7 @@ extern bool g_BlockPistonBreakable[]; #define AddDir( x, y, z, dir, amount ) switch(dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\ case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\ case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; } + #define FAST_FLOOR( x ) ( (x) < 0 ? ((int)x)-1 : ((int)x) ) cPiston::cPiston( cWorld* a_World ) @@ -77,6 +78,8 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) { Action.m_PosZ = (int)pistz; Action.m_Byte1 = 0; Action.m_Byte2 = pistonMeta; + + cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) ); Chunk->Broadcast( Action ); m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 8 ); @@ -109,7 +112,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) { Action.m_PosY = (short)pisty; Action.m_PosZ = (int)pistz; Action.m_Byte1 = 1; - Action.m_Byte1 = pistonMeta & ~(8); + Action.m_Byte2 = pistonMeta & ~(8); cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) ); Chunk->Broadcast( Action ); m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8) ); diff --git a/source/cRedstone.cpp b/source/cRedstone.cpp index 178fdc7be..1a981e654 100644 --- a/source/cRedstone.cpp +++ b/source/cRedstone.cpp @@ -3,107 +3,83 @@ #include "cRoot.h" #include "cWorld.h" #include "BlockID.h" +#include +#include +#include cRedstone::cRedstone( cWorld* a_World ) :m_World ( a_World ) ,m_Metadata ( 0 ) + ,m_Direction ( 0 ) { } void cRedstone::ChangeRedstone( int fillx, int filly, int fillz, bool added ) { +char before; +//int tempX; +//int tempY; +//int tempZ; +//int state; +//m_Direction +// 0 = x+ +// 1 = x- +// 2 = z+ +// 3 = z- +// 4 = y+ +// 5 = v- + + if (added) { m_Metadata = 15; } else { m_Metadata = 0; } + before = m_Metadata; - CalculatetRedstone( fillx, filly, fillz ); - - if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_AIR ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON_EXTENSION ) ) { - - m_Metadata = 0; - CalculatetRedstone( fillx+1, filly, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx-1, filly, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly, fillz+1 ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly, fillz-1 ); - m_Metadata = 0; - - CalculatetRedstone( fillx+1, filly+1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx-1, filly+1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly+1, fillz+1 ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly+1, fillz-1 ); - m_Metadata = 0; - - CalculatetRedstone( fillx+1, filly-1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx-1, filly-1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly-1, fillz+1 ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly-1, fillz-1 ); - m_Metadata = 0; + //printf("etb1\n"); + CalculatetRedstone( fillx, filly, fillz ); //calculate all item centers. + //printf("etb2\n"); - } + int Block = (int)m_World->GetBlock( fillx, filly, fillz ); - if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE ) { //we added dust - - CalculatetRedstone( fillx+1, filly, fillz ); - CalculatetRedstone( fillx-1, filly, fillz ); - CalculatetRedstone( fillx, filly, fillz+1 ); - CalculatetRedstone( fillx, filly, fillz-1 ); - - CalculatetRedstone( fillx+1, filly+1, fillz ); - CalculatetRedstone( fillx-1, filly+1, fillz ); - CalculatetRedstone( fillx, filly+1, fillz+1 ); - CalculatetRedstone( fillx, filly+1, fillz-1 ); - - CalculatetRedstone( fillx+1, filly-1, fillz ); - CalculatetRedstone( fillx-1, filly-1, fillz ); - CalculatetRedstone( fillx, filly-1, fillz+1 ); - CalculatetRedstone( fillx, filly-1, fillz-1 ); - + switch (Block)//these blocks won't trigger the normal calculaton because they are affected by the redstone around them. So we check each possible channel around them instead. + { + case E_BLOCK_AIR: + case E_BLOCK_PISTON_EXTENSION: + case E_BLOCK_PISTON: + case E_BLOCK_STICKY_PISTON: + { + m_Metadata = 0; + m_Direction = 0; + CalculatetRedstone( fillx+1, filly, fillz ); + m_Metadata = 0; + m_Direction = 1; + CalculatetRedstone( fillx-1, filly, fillz ); + m_Metadata = 0; + m_Direction = 2; + CalculatetRedstone( fillx, filly, fillz+1 ); + m_Metadata = 0; + m_Direction = 3; + CalculatetRedstone( fillx, filly, fillz-1 ); + break; + } + case E_BLOCK_REDSTONE_WIRE: //special case for redstone wire. + { + m_Direction = 0; + CalculatetRedstone( fillx+1, filly, fillz ); + m_Direction = 1; + CalculatetRedstone( fillx-1, filly, fillz ); + m_Direction = 2; + CalculatetRedstone( fillx, filly, fillz+1 ); + m_Direction = 3; + CalculatetRedstone( fillx, filly, fillz-1 ); + break; + } } - - if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) ) { //we added a piston - - m_Metadata = 0; - CalculatetRedstone( fillx+1, filly, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx-1, filly, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly, fillz+1 ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly, fillz-1 ); - m_Metadata = 0; - - CalculatetRedstone( fillx+1, filly+1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx-1, filly+1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly+1, fillz+1 ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly+1, fillz-1 ); - m_Metadata = 0; - - CalculatetRedstone( fillx+1, filly-1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx-1, filly-1, fillz ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly-1, fillz+1 ); - m_Metadata = 0; - CalculatetRedstone( fillx, filly-1, fillz-1 ); - m_Metadata = 0; - - } - + + //printf("done here\n"); } void cRedstone::CalculatetRedstone( int fillx, int filly, int fillz) @@ -122,10 +98,74 @@ void cRedstone::CalculatetRedstone( int fillx, int filly, int fillz) Piston.RetractPiston(fillx, filly, fillz); } } - } - if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON ) { //If torch is on - m_Metadata = 15; + } else if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_ITEM_LEVER ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_ITEM_STONE_BUTTON ) ) { + + if ( (int)m_World->GetBlockMeta( fillx, filly, fillz) > 6 ) { //button powered + m_Metadata = 15; //change meta to 15 only if redstone power device in on possition is found. + if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx-1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx+1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz-1); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz+1); + } + } else { + if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx-1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx+1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz-1); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz+1); + } + } + + } else if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STONE_PRESSURE_PLATE ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STONE_BUTTON ) ) { + + if ( (int)m_World->GetBlockMeta( fillx, filly, fillz) == 1 ) { //plate powered + m_Metadata = 15; //change meta to 15 only if redstone power device in on possition is found. + if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx-1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx+1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz-1); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz+1); + } + + } else { + + if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx-1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) { + CalculatetRedstone(fillx+1,filly,fillz); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz-1); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) { + CalculatetRedstone(fillx,filly,fillz+1); + } + } + + } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON ) { //If torch is on + //printf("found torch on\n"); + m_Metadata = 15; //change meta to 15 only if redstone torch in on possition is found. if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { CalculatetRedstone(fillx-1,filly,fillz); } @@ -139,6 +179,8 @@ void cRedstone::CalculatetRedstone( int fillx, int filly, int fillz) CalculatetRedstone(fillx,filly,fillz+1); } } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF ) { //if the torch is off + //printf("found torch off\n"); + // no need to change meta here. if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { CalculatetRedstone(fillx-1,filly,fillz); } @@ -151,25 +193,128 @@ void cRedstone::CalculatetRedstone( int fillx, int filly, int fillz) if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) { CalculatetRedstone(fillx,filly,fillz+1); } - } + } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE ) { //simple fill algorithm for redstone wire. - if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != m_Metadata ) ) { + if ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != m_Metadata ) { m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, m_Metadata ); - CalculatetRedstone(fillx-1,filly,fillz); - CalculatetRedstone(fillx+1,filly,fillz); - CalculatetRedstone(fillx,filly,fillz-1); - CalculatetRedstone(fillx,filly,fillz+1); - - CalculatetRedstone(fillx-1,filly-1,fillz); - CalculatetRedstone(fillx+1,filly-1,fillz); - CalculatetRedstone(fillx,filly-1,fillz-1); - CalculatetRedstone(fillx,filly-1,fillz+1); - - CalculatetRedstone(fillx-1,filly+1,fillz); - CalculatetRedstone(fillx+1,filly+1,fillz); - CalculatetRedstone(fillx,filly+1,fillz-1); - CalculatetRedstone(fillx,filly+1,fillz+1); + m_Direction = 0; + CalculatetRedstone( fillx+1, filly, fillz ); + m_Direction = 1; + CalculatetRedstone( fillx-1, filly, fillz ); + m_Direction = 2; + CalculatetRedstone( fillx, filly, fillz+1 ); + m_Direction = 3; + CalculatetRedstone( fillx, filly, fillz-1 ); + } + + } else { //default, check item for torch attached to it. If meta > 0 then turn that torch off, otherwise turn it on. This change needs to be passed to the next world tick. + //check for torch to east with meta 1 //turn off + //check for torch to west with meta 2 //turn off + //check for torch to south with meta 3 //turn off + //check for torch to north with meta 4 //turn off + //check for torch above with meta 5 //turn off + if ( (int)m_World->GetBlock( fillx, filly, fillz ) != E_BLOCK_AIR ) { + + if ( (int)m_Metadata > 0 ) { //wire powered + + //printf("bird: %i dog: %i \n",(int)m_World->GetBlock( fillx, filly+1, fillz ),(int)m_World->GetBlockMeta( fillx, filly+1, fillz)); + if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) == 1 ) ) { //east + m_World->FastSetBlock( fillx+1, filly, fillz, E_BLOCK_REDSTONE_TORCH_OFF, m_World->GetBlockMeta( fillx+1, filly, fillz) ); + m_World->m_RSList.push_back(fillx+1); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz); + m_World->m_RSList.push_back(00000); + } + if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) == 2 ) ) { //west + m_World->FastSetBlock( fillx-1, filly, fillz, E_BLOCK_REDSTONE_TORCH_OFF, m_World->GetBlockMeta( fillx-1, filly, fillz) ); + m_World->m_RSList.push_back(fillx-1); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz); + m_World->m_RSList.push_back(00000); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) == 3 ) ) { //south + m_World->FastSetBlock( fillx, filly, fillz+1, E_BLOCK_REDSTONE_TORCH_OFF, m_World->GetBlockMeta( fillx, filly, fillz+1) ); + m_World->m_RSList.push_back(fillx); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz+1); + m_World->m_RSList.push_back(00000); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) == 4 ) ) { //north + m_World->FastSetBlock( fillx, filly, fillz-1, E_BLOCK_REDSTONE_TORCH_OFF, m_World->GetBlockMeta( fillx, filly, fillz-1) ); + m_World->m_RSList.push_back(fillx); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz-1); + m_World->m_RSList.push_back(00000); + } + if ( ( (int)m_World->GetBlock( fillx, filly+1, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx, filly+1, fillz) == 5 ) ) { //top + m_World->FastSetBlock( fillx, filly+1, fillz, E_BLOCK_REDSTONE_TORCH_OFF, m_World->GetBlockMeta( fillx, filly+1, fillz) ); + m_World->m_RSList.push_back(fillx); + m_World->m_RSList.push_back(filly+1); + m_World->m_RSList.push_back(fillz); + m_World->m_RSList.push_back(00000); + } + + } else { //wire not powered + + bool BlockPowered = IsBlockPowered( fillx, filly, fillz ); //chck this block for other wire turned on or torch turned on below: + if (BlockPowered == false) { //if block is not bowered by something else then I need to check for off torches and turn them on. + + //printf("echo: %i cruiser: %i \n",(int)m_World->GetBlock( fillx, filly+1, fillz ),(int)m_World->GetBlockMeta( fillx, filly+1, fillz)); + if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) == 1 ) ) { //east + m_World->FastSetBlock( fillx+1, filly, fillz, E_BLOCK_REDSTONE_TORCH_ON, m_World->GetBlockMeta( fillx+1, filly, fillz) ); + m_World->m_RSList.push_back(fillx+1); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz); + m_World->m_RSList.push_back(11111); + } + if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) == 2 ) ) { //west + m_World->FastSetBlock( fillx-1, filly, fillz, E_BLOCK_REDSTONE_TORCH_ON, m_World->GetBlockMeta( fillx-1, filly, fillz) ); + m_World->m_RSList.push_back(fillx-1); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz); + m_World->m_RSList.push_back(11111); + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) == 3 ) ) { //south + m_World->FastSetBlock( fillx, filly, fillz+1, E_BLOCK_REDSTONE_TORCH_ON, m_World->GetBlockMeta( fillx, filly, fillz+1) ); + m_World->m_RSList.push_back(fillx); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz+1); + m_World->m_RSList.push_back(11111);; + } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) == 4 ) ) { //north + m_World->FastSetBlock( fillx, filly, fillz-1, E_BLOCK_REDSTONE_TORCH_ON, m_World->GetBlockMeta( fillx, filly, fillz-1) ); + m_World->m_RSList.push_back(fillx); + m_World->m_RSList.push_back(filly); + m_World->m_RSList.push_back(fillz-1); + m_World->m_RSList.push_back(11111); + } + if ( ( (int)m_World->GetBlock( fillx, filly+1, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx, filly+1, fillz) == 5 ) ) { //top + m_World->FastSetBlock( fillx, filly+1, fillz, E_BLOCK_REDSTONE_TORCH_ON, m_World->GetBlockMeta( fillx, filly+1, fillz) ); + m_World->m_RSList.push_back(fillx); + m_World->m_RSList.push_back(filly+1); + m_World->m_RSList.push_back(fillz); + m_World->m_RSList.push_back(11111); + } + + } + + } + + } + } +} + + +bool cRedstone::IsBlockPowered( int fillx, int filly, int fillz ) +{ + + if ( (int)m_World->GetBlock( fillx, filly-1, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) { return true; } + if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) > 0 ) ) { return true; } + if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) > 0 ) ) { return true; } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) > 0 ) ) { return true; } + if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) > 0 ) ) { return true; } + return false; } \ No newline at end of file diff --git a/source/cRedstone.h b/source/cRedstone.h index fae353818..92f01f5d9 100644 --- a/source/cRedstone.h +++ b/source/cRedstone.h @@ -24,10 +24,11 @@ static char RepeaterRotationToMetaData( float a_Rotation ) void CalculatetRedstone( int, int, int ); void ChangeRedstone( int, int, int, bool ); - +bool IsBlockPowered( int, int, int ); cWorld* m_World; char m_Metadata; - +char m_Direction; + }; diff --git a/source/cWorld.cpp b/source/cWorld.cpp index f372eb69d..ce5f2ed7a 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -1,5 +1,6 @@ #include "BlockID.h" #include "cWorld.h" +#include "cRedstone.h" #include "cChunk.h" #include "cClientHandle.h" #include "cPickup.h" @@ -112,6 +113,7 @@ cWorld::~cWorld() cWorld::cWorld( const char* a_WorldName ) : m_pState( new sWorldState ) , m_SpawnMonsterTime( 0.f ) + , m_RSList ( 0 ) { LOG("cWorld::cWorld(%s)", a_WorldName); m_pState->WorldName = a_WorldName; @@ -435,6 +437,39 @@ void cWorld::Tick(float a_Dt) } } } + + + + std::vector m_RSList_copy(m_RSList); + //copy(m_RSList.begin(), m_RSList.end(), m_RSList_copy.begin()); + m_RSList.erase(m_RSList.begin(),m_RSList.end()); + int tempX; + int tempY; + int tempZ; + int state; + + std::vector::const_iterator cii; + for(cii=m_RSList_copy.begin(); cii!=m_RSList_copy.end();) + { + tempX = *cii;cii++; + tempY = *cii;cii++; + tempZ = *cii;cii++; + state = *cii;cii++; + + //printf ("%i, %i, %i, %i\n",tempX,tempY,tempZ,state) ; + if ( (state == 00000) && ( (int)GetBlock( tempX, tempY, tempZ ) == E_BLOCK_REDSTONE_TORCH_OFF ) ) { + FastSetBlock( tempX, tempY, tempZ, E_BLOCK_REDSTONE_TORCH_OFF, (int)GetBlockMeta( tempX, tempY, tempZ ) ); + cRedstone Redstone(this); + Redstone.ChangeRedstone( tempX, tempY, tempZ, false ); + } else if ( (state == 11111) && ( (int)GetBlock( tempX, tempY, tempZ ) == E_BLOCK_REDSTONE_TORCH_ON ) ) { + FastSetBlock( tempX, tempY, tempZ, E_BLOCK_REDSTONE_TORCH_ON, (int)GetBlockMeta( tempX, tempY, tempZ ) ); + cRedstone Redstone(this); + Redstone.ChangeRedstone( tempX, tempY, tempZ, true ); + } + + } + m_RSList_copy.erase(m_RSList_copy.begin(),m_RSList_copy.end()); + } void cWorld::GrowTree( int a_X, int a_Y, int a_Z ) diff --git a/source/cWorld.h b/source/cWorld.h index 10e181e48..cff627d50 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -7,8 +7,10 @@ enum ENUM_ITEM_ID; #endif #include +#include class cPacket; +class cRedstone; class cWaterSimulator; class cLavaSimulator; class cChunkMap; @@ -26,6 +28,9 @@ public: typedef std::list< cEntity* > EntityList; typedef std::list< cChunk* > ChunkList; typedef std::list< cPlayer* > PlayerList; + std::vector m_RSList; + + static cWorld* GetWorld(); //tolua_export @@ -124,6 +129,7 @@ public: void RemoveSpread( cChunk* a_Chunk ); void InitializeSpawn(); + private: friend class cRoot; cWorld( const char* a_WorldName ); -- cgit v1.2.3