2011-11-03 22:01:55 -07:00
|
|
|
#include "cRedstone.h"
|
2011-11-05 19:36:05 -07:00
|
|
|
#include "cPiston.h"
|
2011-11-04 00:50:18 -07:00
|
|
|
#include "cRoot.h"
|
2011-11-03 22:01:55 -07:00
|
|
|
#include "cWorld.h"
|
2011-11-04 09:05:18 -07:00
|
|
|
#include "BlockID.h"
|
2011-11-03 22:01:55 -07:00
|
|
|
|
|
|
|
cRedstone::cRedstone( cWorld* a_World )
|
|
|
|
:m_World ( a_World )
|
2011-11-06 12:39:44 -08:00
|
|
|
,m_Metadata ( 0 )
|
2011-11-03 22:01:55 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void cRedstone::ChangeRedstoneTorch( int fillx, int filly, int fillz, bool added )
|
|
|
|
{
|
|
|
|
if (added) {
|
2011-11-06 12:39:44 -08:00
|
|
|
m_Metadata = 15;
|
2011-11-03 22:01:55 -07:00
|
|
|
} else {
|
2011-11-06 12:39:44 -08:00
|
|
|
m_Metadata = 0;
|
2011-11-03 22:01:55 -07:00
|
|
|
}
|
2011-11-04 00:50:18 -07:00
|
|
|
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone( fillx, filly, fillz );
|
2011-11-06 12:39:44 -08:00
|
|
|
|
|
|
|
if ( (int)m_World->GetBlock( fillx, filly, fillz ) == 0 ) { //we removed an item
|
|
|
|
|
2011-11-06 13:20:38 -08:00
|
|
|
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;
|
2011-11-06 12:39:44 -08:00
|
|
|
|
|
|
|
}
|
2011-11-06 13:20:38 -08:00
|
|
|
|
|
|
|
if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE ) { //we added dust
|
2011-11-04 00:50:18 -07:00
|
|
|
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone( fillx+1, filly, fillz );
|
|
|
|
LightRedstone( fillx-1, filly, fillz );
|
|
|
|
LightRedstone( fillx, filly, fillz+1 );
|
|
|
|
LightRedstone( fillx, filly, fillz-1 );
|
|
|
|
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
2011-11-06 13:20:38 -08:00
|
|
|
|
2011-11-03 22:01:55 -07:00
|
|
|
}
|
|
|
|
|
2011-11-06 13:20:38 -08:00
|
|
|
void cRedstone::LightRedstone( int fillx, int filly, int fillz)
|
2011-11-03 22:01:55 -07:00
|
|
|
{
|
2011-11-06 12:39:44 -08:00
|
|
|
|
2011-11-05 19:36:05 -07:00
|
|
|
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);
|
2011-11-06 12:39:44 -08:00
|
|
|
if (m_Metadata > 0) {
|
2011-11-05 19:36:05 -07:00
|
|
|
Piston.ExtendPiston(fillx, filly, fillz);
|
|
|
|
} else {
|
|
|
|
Piston.RetractPiston(fillx, filly, fillz);
|
|
|
|
}
|
|
|
|
}
|
2011-11-03 22:01:55 -07:00
|
|
|
|
2011-11-06 12:39:44 -08:00
|
|
|
if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF ) { //I don't think notch knows on from off. >.>
|
|
|
|
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 ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx-1,filly,fillz);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx+1,filly,fillz);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx,filly,fillz-1);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx,filly,fillz+1);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
} else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON ) { //if the torch is off
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx-1,filly,fillz);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx+1,filly,fillz);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx,filly,fillz-1);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
|
2011-11-06 13:20:38 -08:00
|
|
|
LightRedstone(fillx,filly,fillz+1);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != m_Metadata ) ) {
|
|
|
|
m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, m_Metadata );
|
2011-11-06 13:20:38 -08:00
|
|
|
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);
|
2011-11-06 12:39:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|