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
{
}
2011-11-07 14:59:29 -08:00
void cRedstone : : ChangeRedstone ( int fillx , int filly , int fillz , bool added )
2011-11-03 22:01:55 -07:00
{
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-07 14:59:29 -08:00
CalculatetRedstone ( fillx , filly , fillz ) ;
2011-11-06 12:39:44 -08:00
2011-11-07 14:59:29 -08:00
if ( ( ( int ) m_World - > GetBlock ( fillx , filly , fillz ) = = E_BLOCK_AIR ) | | ( ( int ) m_World - > GetBlock ( fillx , filly , fillz ) = = E_BLOCK_PISTON_EXTENSION ) ) {
2011-11-06 12:39:44 -08:00
2011-11-06 13:20:38 -08:00
m_Metadata = 0 ;
2011-11-07 14:59:29 -08:00
CalculatetRedstone ( fillx + 1 , filly , fillz ) ;
2011-11-06 13:20:38 -08:00
m_Metadata = 0 ;
2011-11-07 14:59:29 -08:00
CalculatetRedstone ( fillx - 1 , filly , fillz ) ;
2011-11-06 13:20:38 -08:00
m_Metadata = 0 ;
2011-11-07 14:59:29 -08:00
CalculatetRedstone ( fillx , filly , fillz + 1 ) ;
2011-11-06 13:20:38 -08:00
m_Metadata = 0 ;
2011-11-07 14:59:29 -08:00
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 ;
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-07 14:59:29 -08:00
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 ) ;
}
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 ;
2011-11-06 13:20:38 -08:00
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-07 14:59:29 -08:00
void cRedstone : : CalculatetRedstone ( 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 ) ) {
2011-11-07 14:59:29 -08:00
char pistonMeta = m_World - > GetBlockMeta ( fillx , filly , fillz ) ;
2011-11-06 12:39:44 -08:00
if ( m_Metadata > 0 ) {
2011-11-07 14:59:29 -08:00
if ( pistonMeta < 6 ) { // only extend if piston is not already extended
cPiston Piston ( m_World ) ;
Piston . ExtendPiston ( fillx , filly , fillz ) ;
}
2011-11-05 19:36:05 -07:00
} else {
2011-11-07 14:59:29 -08:00
if ( pistonMeta > 6 ) { // only retract if piston is not already retracted
cPiston Piston ( m_World ) ;
Piston . RetractPiston ( fillx , filly , fillz ) ;
}
2011-11-05 19:36:05 -07:00
}
}
2011-11-03 22:01:55 -07:00
2011-11-07 14:59:29 -08:00
if ( ( int ) m_World - > GetBlock ( fillx , filly , fillz ) = = E_BLOCK_REDSTONE_TORCH_ON ) { //If torch is on
2011-11-06 12:39:44 -08:00
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-07 14:59:29 -08:00
CalculatetRedstone ( 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-07 14:59:29 -08:00
CalculatetRedstone ( 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-07 14:59:29 -08:00
CalculatetRedstone ( 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-07 14:59:29 -08:00
CalculatetRedstone ( fillx , filly , fillz + 1 ) ;
2011-11-06 12:39:44 -08:00
}
2011-11-07 14:59:29 -08:00
} else if ( ( int ) m_World - > GetBlock ( fillx , filly , fillz ) = = E_BLOCK_REDSTONE_TORCH_OFF ) { //if the torch is off
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-07 14:59:29 -08:00
CalculatetRedstone ( 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-07 14:59:29 -08:00
CalculatetRedstone ( 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-07 14:59:29 -08:00
CalculatetRedstone ( 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-07 14:59:29 -08:00
CalculatetRedstone ( 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-07 14:59:29 -08:00
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 ) ;
2011-11-06 12:39:44 -08:00
}
}