From cc4e4345deebd36db77ec8befea4894c4169d0ed Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Sun, 6 Nov 2011 20:39:44 +0000 Subject: Redstone is now self aware. It's not quite as dumb as it used to be at any rate. Redstone wires have no range and understand they are supposed to stay on whenever there's an active torch touching it. (Need to add other power devices) git-svn-id: http://mc-server.googlecode.com/svn/trunk@68 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 38 ++++++-- source/cRedstone.cpp | 232 ++++++++++++++++++++++++++++++++++++++++------- source/cRedstone.h | 4 +- 3 files changed, 232 insertions(+), 42 deletions(-) (limited to 'source') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 515134683..a2597a229 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -647,6 +647,8 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) //printf("Place Dir:%i %i %i %i : %i\n", PacketData->m_Direction, PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, PacketData->m_ItemType); // 'use' useable items instead of placing blocks bool bPlaceBlock = true; + bool UpdateRedstone = false; + bool AddedCurrent = false; if( PacketData->m_Direction >= 0 ) { ENUM_BLOCK_ID BlockID = (ENUM_BLOCK_ID)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ ); @@ -655,6 +657,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) case E_BLOCK_REDSTONE_REPEATER_ON: case E_BLOCK_REDSTONE_REPEATER_OFF: { + //no need to update redstone current with a repeater //todo: Find meta value of repeater and change it to one step more. } break; @@ -761,35 +764,48 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) break; case E_BLOCK_REDSTONE_TORCH_OFF: { - MetaData = cTorch::DirectionToMetaData( PacketData->m_Direction ); + MetaData = cTorch::DirectionToMetaData( PacketData->m_Direction ); //check redstone circuit: - //if( GetBlock( X, Y+1, Z ) == E_BLOCK_AIR ) if( g_BlockTransparent[ (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY+2, PacketData->m_PosZ ) ] == true ) {//if block above is transparent //printf("transparent above me\n"); } else { //printf("transparent not above me\n"); } - - cRedstone Redstone(m_Player->GetWorld()); - Redstone.cRedstone::ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, true ); - - break; + //PacketData->m_ItemType = E_BLOCK_REDSTONE_TORCH_ON; + UpdateRedstone = true; + AddedCurrent = true; + //cRedstone Redstone(m_Player->GetWorld()); + //Redstone.cRedstone::ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, true ); + break; } case E_BLOCK_REDSTONE_TORCH_ON: - MetaData = cTorch::DirectionToMetaData( PacketData->m_Direction ); - break; + { + MetaData = cTorch::DirectionToMetaData( PacketData->m_Direction ); + //PacketData->m_ItemType = E_BLOCK_REDSTONE_TORCH_ON; + UpdateRedstone = true; + AddedCurrent = false; + //cRedstone Redstone(m_Player->GetWorld()); + //Redstone.cRedstone::ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, true ); + break; + } case E_ITEM_REDSTONE_DUST: MetaData = 0; PacketData->m_ItemType = E_BLOCK_REDSTONE_WIRE; + UpdateRedstone = true; + AddedCurrent = false; break; case E_ITEM_REDSTONE_REPEATER: MetaData = cRedstone::RepeaterRotationToMetaData( m_Player->GetRotation() ); PacketData->m_ItemType = E_BLOCK_REDSTONE_REPEATER_OFF; + UpdateRedstone = true; + AddedCurrent = false; break; case E_BLOCK_PISTON: case E_BLOCK_STICKY_PISTON: MetaData = cPiston::RotationPitchToMetaData( m_Player->GetRotation(), m_Player->GetPitch() ); + UpdateRedstone = true; + AddedCurrent = false; break; case E_BLOCK_COBBLESTONE_STAIRS: case E_BLOCK_BRICK_STAIRS: @@ -829,6 +845,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) AddDirection( X, Y, Z, PacketData->m_Direction ); m_Player->GetWorld()->SetBlock( X, Y, Z, (char)PacketData->m_ItemType, MetaData ); + if (UpdateRedstone) { + cRedstone Redstone(m_Player->GetWorld()); + Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, AddedCurrent ); + } } } } diff --git a/source/cRedstone.cpp b/source/cRedstone.cpp index 77a3400fc..ff357562f 100644 --- a/source/cRedstone.cpp +++ b/source/cRedstone.cpp @@ -6,6 +6,7 @@ cRedstone::cRedstone( cWorld* a_World ) :m_World ( a_World ) + ,m_Metadata ( 0 ) { } @@ -15,77 +16,244 @@ 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; } - //cWorld* World = cRoot::Get()->GetWorld(); + LightRedstone( fillx, filly, fillz, metadata ); + + 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 ); + //} + + } + //cWorld* World = cRoot::Get()->GetWorld(); +/* + while ((int)metadata == 0) { if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx+1, filly, fillz, metadata ); + metadata = LightRedstone( fillx+1, filly, fillz, metadata ); } if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx-1, filly, fillz, metadata ); + metadata = LightRedstone( fillx-1, filly, fillz, metadata ); } if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly, fillz+1, metadata ); + metadata = LightRedstone( fillx, filly, fillz+1, metadata ); } if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly, fillz-1, metadata ); + metadata = LightRedstone( fillx, filly, fillz-1, metadata ); } if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx+1, filly-1, fillz, metadata ); + metadata = LightRedstone( fillx+1, filly-1, fillz, metadata ); } if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx-1, filly-1, fillz, metadata ); + metadata = LightRedstone( fillx-1, filly-1, fillz, metadata ); } if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly-1, fillz+1, metadata ); + metadata = LightRedstone( fillx, filly-1, fillz+1, metadata ); } if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly-1, fillz-1, metadata ); + metadata = LightRedstone( fillx, filly-1, fillz-1, metadata ); } if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx+1, filly+1, fillz, metadata ); + metadata = LightRedstone( fillx+1, filly+1, fillz, metadata ); } if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx-1, filly+1, fillz, metadata ); + metadata = LightRedstone( fillx-1, filly+1, fillz, metadata ); } if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly+1, fillz+1, metadata ); + metadata = LightRedstone( fillx, filly+1, fillz+1, metadata ); } if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) ) { - LightRedstone( fillx, filly+1, fillz-1, metadata ); + metadata = LightRedstone( fillx, filly+1, fillz-1, metadata ); } + break; + } +*/ } -void cRedstone::LightRedstone( int fillx, int filly, int fillz, char metadata) +char cRedstone::LightRedstone( int fillx, int filly, int fillz, char metadata) { + //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 (metadata > 0) { + if (m_Metadata > 0) { Piston.ExtendPiston(fillx, filly, fillz); } else { Piston.RetractPiston(fillx, filly, fillz); } - } else 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 ); - LightRedstone(fillx-1,filly,fillz,metadata); - LightRedstone(fillx+1,filly,fillz,metadata); - LightRedstone(fillx,filly,fillz-1,metadata); - LightRedstone(fillx,filly,fillz+1,metadata); - - LightRedstone(fillx-1,filly-1,fillz,metadata); - LightRedstone(fillx+1,filly-1,fillz,metadata); - LightRedstone(fillx,filly-1,fillz-1,metadata); - LightRedstone(fillx,filly-1,fillz+1,metadata); - - LightRedstone(fillx-1,filly+1,fillz,metadata); - LightRedstone(fillx+1,filly+1,fillz,metadata); - LightRedstone(fillx,filly+1,fillz-1,metadata); - LightRedstone(fillx,filly+1,fillz+1,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); + } + 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 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); + } + 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); + } + } + + + + + +/* + 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); + } + + //} + + } + + } + + + + + + + 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); + //} + + } +*/ + return metadata; + +} \ No newline at end of file diff --git a/source/cRedstone.h b/source/cRedstone.h index b4f8e7eed..31af95e59 100644 --- a/source/cRedstone.h +++ b/source/cRedstone.h @@ -22,10 +22,12 @@ static char RepeaterRotationToMetaData( float a_Rotation ) } -void LightRedstone( int, int, int, char ); +char LightRedstone( int, int, int, char ); void ChangeRedstoneTorch( int, int, int, bool ); cWorld* m_World; +char m_Metadata; + }; -- cgit v1.2.3