From 094456a1310853195b688b3fec740a9f5d6b54c7 Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Sun, 6 Nov 2011 21:20:38 +0000 Subject: Redstone wire now updates correctly when added and removed. it also updates all currently programmed redstone items and wire circuits. Also cleaned up the mess I left of the code. git-svn-id: http://mc-server.googlecode.com/svn/trunk@69 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 8 +- source/cRedstone.cpp | 231 ++++++++--------------------------------------- source/cRedstone.h | 2 +- 3 files changed, 47 insertions(+), 194 deletions(-) (limited to 'source') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index a2597a229..7239a083d 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -525,11 +525,15 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) { if (OldBlock == E_BLOCK_REDSTONE_TORCH_ON) { cRedstone Redstone(World); - Redstone.cRedstone::ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false ); + Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false ); } if (OldBlock == E_BLOCK_REDSTONE_TORCH_OFF) { cRedstone Redstone(World); - Redstone.cRedstone::ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false ); + Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false ); + } + if (OldBlock == E_BLOCK_REDSTONE_WIRE) { + cRedstone Redstone(World); + Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false ); } int helditem = m_Player->GetInventory().GetEquippedItem().m_ItemID; diff --git a/source/cRedstone.cpp b/source/cRedstone.cpp index ff357562f..6a0b1473a 100644 --- a/source/cRedstone.cpp +++ b/source/cRedstone.cpp @@ -13,86 +13,41 @@ cRedstone::cRedstone( cWorld* a_World ) void cRedstone::ChangeRedstoneTorch( int fillx, int filly, int fillz, bool added ) { - char metadata = 0; if (added) { - metadata = 15; m_Metadata = 15; } else { - metadata = 0; m_Metadata = 0; } - LightRedstone( fillx, filly, fillz, metadata ); + LightRedstone( fillx, filly, fillz ); if ( (int)m_World->GetBlock( fillx, filly, fillz ) == 0 ) { //we removed an item - //se we check each possible current connection around it. - //if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx+1, filly, fillz, m_Metadata ); - //} - //if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx-1, filly, fillz, m_Metadata ); - //} - //if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly, fillz+1, m_Metadata ); - //} - //if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly, fillz-1, m_Metadata ); - //} + LightRedstone( fillx+1, filly, fillz ); + m_Metadata = 0; + LightRedstone( fillx-1, filly, fillz ); + m_Metadata = 0; + LightRedstone( fillx, filly, fillz+1 ); + m_Metadata = 0; + LightRedstone( fillx, filly, fillz-1 ); + m_Metadata = 0; } + + if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE ) { //we added dust - //cWorld* World = cRoot::Get()->GetWorld(); -/* - while ((int)metadata == 0) { - if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx+1, filly, fillz, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx-1, filly, fillz, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx, filly, fillz+1, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx, filly, fillz-1, metadata ); - } - - if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx+1, filly-1, fillz, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx-1, filly-1, fillz, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx, filly-1, fillz+1, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx, filly-1, fillz-1, metadata ); - } - - if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx+1, filly+1, fillz, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx-1, filly+1, fillz, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx, filly+1, fillz+1, metadata ); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) ) { - metadata = LightRedstone( fillx, filly+1, fillz-1, metadata ); - } - break; + LightRedstone( fillx+1, filly, fillz ); + LightRedstone( fillx-1, filly, fillz ); + LightRedstone( fillx, filly, fillz+1 ); + LightRedstone( fillx, filly, fillz-1 ); + } -*/ + } -char cRedstone::LightRedstone( int fillx, int filly, int fillz, char metadata) +void cRedstone::LightRedstone( int fillx, int filly, int fillz) { - //while (m_Metadata == metadata) { - //printf("LightRedstone( %i, %i, %i, %i )\n)", fillx, filly, fillz, (int)metadata); if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) ) { cPiston Piston(m_World); if (m_Metadata > 0) { @@ -103,157 +58,51 @@ char cRedstone::LightRedstone( int fillx, int filly, int fillz, char metadata) } if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF ) { //I don't think notch knows on from off. >.> - //printf("1\n"); - metadata = 15; m_Metadata = 15; if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { - LightRedstone(fillx-1,filly,fillz,m_Metadata); + LightRedstone(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 ) ) { - LightRedstone(fillx+1,filly,fillz,m_Metadata); + LightRedstone(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 ) ) { - LightRedstone(fillx,filly,fillz-1,m_Metadata); + LightRedstone(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 ) ) { - LightRedstone(fillx,filly,fillz+1,m_Metadata); + LightRedstone(fillx,filly,fillz+1); } } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON ) { //if the torch is off - //printf("2\n"); - metadata = 0; if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { - LightRedstone(fillx-1,filly,fillz,m_Metadata); + LightRedstone(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 ) ) { - LightRedstone(fillx+1,filly,fillz,m_Metadata); + LightRedstone(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 ) ) { - LightRedstone(fillx,filly,fillz-1,m_Metadata); + LightRedstone(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 ) ) { - LightRedstone(fillx,filly,fillz+1,m_Metadata); - } - } - - - - - -/* - if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) == 15 ) ) { //if current block is redstone and is on - if ((int)m_Metadata == 15) { //and we want it to be on then we do nothing - } else { //we want it to be off - - //if (m_Metadata == metadata) { // only do this if another fill in the same class hasn't found a lit torch yet - - m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, metadata ); //turn it off then check each one around it - - if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { - LightRedstone(fillx-1,filly,fillz,m_Metadata); - } - if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) { - LightRedstone(fillx+1,filly,fillz,m_Metadata); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) { - LightRedstone(fillx,filly,fillz-1,m_Metadata); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) { - LightRedstone(fillx,filly,fillz+1,m_Metadata); - } - - //} - + LightRedstone(fillx,filly,fillz+1); } - } - - - - - if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) == 0 ) ) { //if current block is redstone and is off - if ((int)m_Metadata == 15) { //and we want it to be on then we check each object around it - - m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, m_Metadata ); //turn it off then check each one around it - - if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) { - LightRedstone(fillx-1,filly,fillz,m_Metadata); - } - if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) { - LightRedstone(fillx+1,filly,fillz,m_Metadata); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) { - LightRedstone(fillx,filly,fillz-1,m_Metadata); - } - if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) { - LightRedstone(fillx,filly,fillz+1,m_Metadata); - } - - } else { //we want it to be off - - - } - - } - */ - 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->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - //printf("3\n"); m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, m_Metadata ); - LightRedstone(fillx-1,filly,fillz,m_Metadata); - LightRedstone(fillx+1,filly,fillz,m_Metadata); - LightRedstone(fillx,filly,fillz-1,m_Metadata); - LightRedstone(fillx,filly,fillz+1,m_Metadata); - - LightRedstone(fillx-1,filly-1,fillz,m_Metadata); - LightRedstone(fillx+1,filly-1,fillz,m_Metadata); - LightRedstone(fillx,filly-1,fillz-1,m_Metadata); - LightRedstone(fillx,filly-1,fillz+1,m_Metadata); - - LightRedstone(fillx-1,filly+1,fillz,m_Metadata); - LightRedstone(fillx+1,filly+1,fillz,m_Metadata); - LightRedstone(fillx,filly+1,fillz-1,m_Metadata); - LightRedstone(fillx,filly+1,fillz+1,m_Metadata); - } -/* - if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != metadata ) ) { - m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, metadata ); - - //if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != metadata ) ) { - LightRedstone(fillx-1,filly,fillz,metadata); - //} - //if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != metadata ) ) { - LightRedstone(fillx+1,filly,fillz,metadata); - //} - //if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != metadata ) ) { - LightRedstone(fillx,filly,fillz-1,metadata); - //} - //if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != metadata ) ) { - LightRedstone(fillx,filly,fillz+1,metadata); - //} - - } - - if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != metadata ) ) { - m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, metadata ); - - //if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != metadata ) ) { - LightRedstone(fillx-1,filly,fillz,metadata); - //} - //if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != metadata ) ) { - LightRedstone(fillx+1,filly,fillz,metadata); - //} - //if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != metadata ) ) { - LightRedstone(fillx,filly,fillz-1,metadata); - //} - //if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != metadata ) ) { - LightRedstone(fillx,filly,fillz+1,metadata); - //} - + LightRedstone(fillx-1,filly,fillz); + LightRedstone(fillx+1,filly,fillz); + LightRedstone(fillx,filly,fillz-1); + LightRedstone(fillx,filly,fillz+1); + + LightRedstone(fillx-1,filly-1,fillz); + LightRedstone(fillx+1,filly-1,fillz); + LightRedstone(fillx,filly-1,fillz-1); + LightRedstone(fillx,filly-1,fillz+1); + + LightRedstone(fillx-1,filly+1,fillz); + LightRedstone(fillx+1,filly+1,fillz); + LightRedstone(fillx,filly+1,fillz-1); + LightRedstone(fillx,filly+1,fillz+1); } -*/ - return metadata; } \ No newline at end of file diff --git a/source/cRedstone.h b/source/cRedstone.h index 31af95e59..5735fb298 100644 --- a/source/cRedstone.h +++ b/source/cRedstone.h @@ -22,7 +22,7 @@ static char RepeaterRotationToMetaData( float a_Rotation ) } -char LightRedstone( int, int, int, char ); +void LightRedstone( int, int, int ); void ChangeRedstoneTorch( int, int, int, bool ); -- cgit v1.2.3