summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/cPiston.cpp400
-rw-r--r--source/cPiston.h14
-rw-r--r--source/cRedstone.cpp42
3 files changed, 408 insertions, 48 deletions
diff --git a/source/cPiston.cpp b/source/cPiston.cpp
index 966c96c5b..af424fc3d 100644
--- a/source/cPiston.cpp
+++ b/source/cPiston.cpp
@@ -11,40 +11,392 @@ cPiston::cPiston( cWorld* a_World )
//Todo: All piston stuff below.
void cPiston::ExtendPiston( int pistx, int pisty, int pistz )
{
- cWorld* World = cRoot::Get()->GetWorld();
- char metadata = World->GetBlockMeta( pistx, pisty, pistz);
+ //cWorld* World = cRoot::Get()->GetWorld();
+ char metadata = 0;
+ char extmetadata = 0;
+ int FirstFluidBlock = 0;
+ char piston;
+ piston = m_World->GetBlock( pistx, pisty, pistz );
- if ( ( (int)World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_STICKY_PISTON ) || ( (int)World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON ) ) {
- //find direction piston is facing base on meta.
- //verify piston is not already extended.
- //check all 16 blocks in front of it for the first airblock
- //if there's and air block move those found blocks by 1 and insert E_BLOCK_PISTON_EXTENSION in the spot infront of the piston facing right direction
+ printf("psPiston1\n");
- }
+ if ( piston == E_BLOCK_STICKY_PISTON ) {
+ printf("psPiston2\n");
+ extmetadata = 8;
+ }//if sticky piston than top nibble bit is set to 1;
+
+
+ if ( ( piston == E_BLOCK_STICKY_PISTON ) || ( piston == E_BLOCK_PISTON ) ) {
+ metadata = m_World->GetBlockMeta( pistx, pisty, pistz);
+ printf("psPiston3\n");
+ printf("metadata %c\n",metadata);
+
+ if (metadata < 5) { //piston not extended
+ printf("metadata %c\n",metadata);
+ metadata -= 8; //removing 8 from retracts it
+ switch (metadata) {
+ case 0:
+ FirstFluidBlock = FindFluidBlock ( pistx, pisty, pistz, pistx, pisty-16, pistz );
+ if (FirstFluidBlock > 0) {
+ ChainMove ( pistx, pisty, pistz, pistx, pisty-FirstFluidBlock, pistz );
+ }
+ m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
+ m_World->FastSetBlock( pistx, pisty-1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata );
+ break;
+ case 1:
+ FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx, pisty+16, pistz);
+ if (FirstFluidBlock > 0) {
+ ChainMove ( pistx, pisty, pistz, pistx, pisty+FirstFluidBlock, pistz );
+ }
+ m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
+ m_World->FastSetBlock( pistx, pisty+1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+1 );
+ break;
+ case 2:
+ FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx, pisty, pistz-16);
+ if (FirstFluidBlock > 0) {
+ ChainMove ( pistx, pisty, pistz, pistx, pisty, pistz-FirstFluidBlock );
+ }
+ m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
+ m_World->FastSetBlock( pistx, pisty, pistz-1, E_BLOCK_PISTON_EXTENSION, extmetadata+2 );
+ break;
+ case 3:
+ FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx, pisty, pistz+16);
+ if (FirstFluidBlock > 0) {
+ ChainMove ( pistx, pisty, pistz, pistx, pisty, pistz+FirstFluidBlock );
+ }
+ m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
+ m_World->FastSetBlock( pistx, pisty, pistz+1, E_BLOCK_PISTON_EXTENSION, extmetadata+3 );
+ break;
+ case 4:
+ FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx-16, pisty, pistz);
+ if (FirstFluidBlock > 0) {
+ ChainMove ( pistx, pisty, pistz, pistx-FirstFluidBlock, pisty, pistz );
+ }
+ m_World->FastSetBlock( pistx, pisty, pistz, piston, metadata + 8 );
+ m_World->FastSetBlock( pistx, pisty+1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+4 );
+ break;
+ case 5:
+ FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx+16, pisty, pistz);
+ if (FirstFluidBlock > 0) {
+ ChainMove ( pistx, pisty, pistz, pistx+FirstFluidBlock, pisty, pistz );
+ }
+ m_World->FastSetBlock( pistx, pisty, pistz, piston, metadata + 8 );
+ m_World->FastSetBlock( pistx, pisty+1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+5 );
+ break;
+ }
+ }
+ }
}
void cPiston::RetractPiston( int pistx, int pisty, int pistz )
{
- cWorld* World = cRoot::Get()->GetWorld();
- char metadata = World->GetBlockMeta( pistx, pisty, pistz);
-
- if ( (int)World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON ) {
- //find direction piston is facing base on meta.
- //verify piston is extended.
- //check block in front to see if it's an E_BLOCK_PISTON_EXTENSION
- //delete that block
- //set piston meta to unextended
+ char metadata = m_World->GetBlockMeta( pistx, pisty, pistz);
+
+ if ( (int)m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON ) {
+ if (metadata > 5) { //piston retracted
+ metadata -= 8;//set the piston to retracted state.
+
+ m_World->FastSetBlock( pistx, pisty, pistz, m_World->GetBlock( pistx, pisty, pistz ), metadata );
+ switch (metadata) {
+ case 0:
+ if ( m_World->GetBlock( pistx, pisty-1, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty-1, pistz, 0, 0 );
+ }
+ break;
+
+ case 1:
+ if ( m_World->GetBlock( pistx, pisty+1, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty+1, pistz, 0, 0 );
+ }
+ break;
+
+ case 2:
+ if ( m_World->GetBlock( pistx, pisty, pistz-1 ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty, pistz-1, 0, 0 );
+ }
+ break;
+
+ case 3:
+ if ( m_World->GetBlock( pistx, pisty, pistz+1 ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty, pistz+1, 0, 0 );
+ }
+ break;
+
+ case 4:
+ if ( m_World->GetBlock( pistx-1, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx-1, pisty, pistz, 0, 0 );
+ }
+ break;
+
+ case 5:
+ if ( m_World->GetBlock( pistx+1, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx+1, pisty, pistz, 0, 0 );
+ }
+ break;
+
+ }
+ }
}
- if ( (int)World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_STICKY_PISTON ) {
- //find direction piston is facing base on meta.
- //verify piston is extended.
- //check block in front to see if it's an E_BLOCK_PISTON_EXTENSION
- //delete that block
- //move block one more in front of it to postion E_BLOCK_PISTON_EXTENSION was facing.
- //set piston meta to unextended
+
+ if ( (int)m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON ) {
+ if (metadata > 5) { //piston retracted
+ metadata -= 8;//set the piston to retracted state.
+
+ m_World->FastSetBlock( pistx, pisty, pistz, m_World->GetBlock( pistx, pisty, pistz ), metadata );
+ switch (metadata) {
+ case 0:
+ if ( m_World->GetBlock( pistx, pisty-1, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty-1, pistz, m_World->GetBlock( pistx, pisty-2, pistz ), m_World->GetBlockMeta( pistx, pisty-2, pistz ) );
+ m_World->SetBlock( pistx, pisty-2, pistz, 0, 0 );
+ }
+ break;
+
+ case 1:
+ if ( m_World->GetBlock( pistx, pisty+1, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty-1, pistz, m_World->GetBlock( pistx, pisty-2, pistz ), m_World->GetBlockMeta( pistx, pisty-2, pistz ) );
+ m_World->SetBlock( pistx, pisty-2, pistz, 0, 0 );
+ }
+ break;
+
+ case 2:
+ if ( m_World->GetBlock( pistx, pisty, pistz-1) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty, pistz-1, m_World->GetBlock( pistx, pisty, pistz-2 ), m_World->GetBlockMeta( pistx, pisty, pistz-2 ) );
+ m_World->SetBlock( pistx, pisty, pistz-2, 0, 0 );
+ }
+ break;
+
+ case 3:
+ if ( m_World->GetBlock( pistx, pisty, pistz+1) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx, pisty, pistz+1, m_World->GetBlock( pistx, pisty, pistz+2 ), m_World->GetBlockMeta( pistx, pisty, pistz+2 ) );
+ m_World->SetBlock( pistx, pisty, pistz+2, 0, 0 );
+ }
+ break;
+
+ case 4:
+ if ( m_World->GetBlock( pistx-1, pisty, pistz) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx-1, pisty, pistz, m_World->GetBlock( pistx-2, pisty, pistz ), m_World->GetBlockMeta( pistx-2, pisty, pistz ) );
+ m_World->SetBlock( pistx-2, pisty, pistz, 0, 0 );
+ }
+ break;
+
+ case 5:
+ if ( m_World->GetBlock( pistx+1, pisty, pistz) == E_BLOCK_PISTON_EXTENSION ) {
+ m_World->SetBlock( pistx+1, pisty, pistz, m_World->GetBlock( pistx+2, pisty, pistz ), m_World->GetBlockMeta( pistx+2, pisty, pistz ) );
+ m_World->SetBlock( pistx+2, pisty, pistz, 0, 0 );
+ }
+ break;
+
+ }
+ }
+ }
+}
+
+void cPiston::ChainMove ( int ax, int ay, int az, int bx, int by, int bz )
+{
+
+char lastmeta;
+char lastblock;
+
+ if ( ( ax != bx ) && ( ay == by ) && ( az == bz ) ) { //move x
+
+ if ( ax < bx ) {
+
+ while ( ax > bx ) {
+
+ lastmeta = m_World->GetBlockMeta( bx+1, by, bz);
+ lastblock = m_World->GetBlockMeta( bx+1, by, bz);
+ m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
+ bx+1;
+
+ }
+
+ } else {
+
+ while ( ax < bx ) {
+
+ lastmeta = m_World->GetBlockMeta( bx-1, by, bz);
+ lastblock = m_World->GetBlockMeta( bx-1, by, bz);
+ m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
+ bx-1;
+
+ }
+
+ }
+
+ m_World->SetBlock( ax, ay, az, 0, 0 );
+
+ } else if ( ( ax == bx ) && ( ay != by ) && ( az == bz ) ) { //move y
+
+ if ( ay < by ) {
+
+ while ( ay > by ) {
+
+ lastmeta = m_World->GetBlockMeta( bx, by+1, bz);
+ lastblock = m_World->GetBlockMeta( bx, by+1, bz);
+ m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
+ by+1;
+
+ }
+
+ } else {
+
+ while ( ay < by ) {
+
+ lastmeta = m_World->GetBlockMeta( bx, by-1, bz);
+ lastblock = m_World->GetBlockMeta( bx, by-1, bz);
+ m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
+ by-1;
+
+ }
+
+ }
+
+ m_World->SetBlock( ax, ay, az, 0, 0 );
+
+ } else if ( ( ax == bx ) && ( ay == by ) && ( az != bz ) ) { //move z
+
+ if ( az < bz ) {
+
+ while ( az > bz ) {
+
+ lastmeta = m_World->GetBlockMeta( bx, by, bz+1 );
+ lastblock = m_World->GetBlockMeta( bx, by, bz+1 );
+ m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
+ bz+1;
+
+ }
+
+ } else {
+
+ while ( az < bz ) {
+
+ lastmeta = m_World->GetBlockMeta( bx, by, bz-1 );
+ lastblock = m_World->GetBlockMeta( bx, by, bz-1 );
+ m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
+ bz-1;
+
+ }
+
+ }
+
+ m_World->SetBlock( ax, ay, az, 0, 0 );
+
+ } else {
+
+ //LOG("Bad coords fed into cPiston::ChainMove");
+
+ }
+
+
+}
+
+
+int cPiston::FindFluidBlock ( int ax, int ay, int az, int bx, int by, int bz )
+{
+
+char thisblock;
+int cnt = 0;
+ if ( ( ax != bx ) && ( ay == by ) && ( az == bz ) ) { //check x
+
+ if ( ax < bx ) {
+
+ while ( ax < bx ) {
+
+ thisblock = m_World->GetBlock( ax, ay, az);
+ if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
+ return cnt;
+ }
+ cnt++;
+ ax+1;
+ }
+
+ } else {
+
+ while ( ax > bx ) {
+
+ thisblock = m_World->GetBlock( ax, ay, az);
+ if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
+ return cnt;
+ }
+ cnt++;
+ ax-1;
+
+ }
+
+ }
+
+ m_World->SetBlock( ax, ay, az, 0, 0 );
+
+ } else if ( ( ax == bx ) && ( ay != by ) && ( az == bz ) ) { //check y
+
+ if ( ay < by ) {
+
+ while ( ay < by ) {
+
+ thisblock = m_World->GetBlock( bx, by, bz);
+ if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
+ return cnt;
+ }
+ cnt++;
+ ay+1;
+
+ }
+
+ } else {
+
+ while ( ay > by ) {
+
+ thisblock = m_World->GetBlock( bx, by, bz);
+ if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
+ return cnt;
+ }
+ cnt++;
+ ay-1;
+
+ }
+
+ }
+
+ m_World->SetBlock( ax, ay, az, 0, 0 );
+
+ } else if ( ( ax == bx ) && ( ay == by ) && ( az != bz ) ) { //check z
+
+ if ( az < bz ) {
+
+ while ( az < bz ) {
+
+ thisblock = m_World->GetBlock( ax, ay, az);
+ if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
+ return cnt;
+ }
+ cnt++;
+ az+1;
+
+ }
+
+ } else {
+
+ while ( az > bz ) {
+
+ thisblock = m_World->GetBlock( ax, ay, az);
+ if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
+ return cnt;
+ }
+ cnt++;
+ az-1;
+
+ }
+
+ }
+
+ } else {
+
+ return cnt;
+
}
+
}
diff --git a/source/cPiston.h b/source/cPiston.h
index 46d7d2b20..9c4f38099 100644
--- a/source/cPiston.h
+++ b/source/cPiston.h
@@ -9,9 +9,6 @@ cPiston( cWorld* a_World );
static char RotationPitchToMetaData( float a_Rotation, float a_Pitch )
{
- //if pitch higher than this value set up
- //else if pitch lower than this value set down,
- //else just do rotation:
std::printf("pre:a_Rotation %f \n",a_Rotation);
std::printf("a_Pitch %f \n",a_Pitch);
@@ -26,19 +23,20 @@ static char RotationPitchToMetaData( float a_Rotation, float a_Pitch )
if( a_Rotation > 360.f ) a_Rotation -= 360.f;
if( a_Rotation >= 0.f && a_Rotation < 90.f )
- return 0x4;
+ { std::printf("1111\n");return 0x4;}
else if( a_Rotation >= 180 && a_Rotation < 270 )
- return 0x5;
+ { std::printf("2222\n");return 0x5;}
else if( a_Rotation >= 90 && a_Rotation < 180 )
- return 0x2;
+ { std::printf("3333\n");return 0x2;}
else
- return 0x3;
+ { std::printf("4444\n");return 0x3;}
}
}
-
void ExtendPiston( int, int, int );
void RetractPiston( int, int, int );
+void ChainMove( int, int, int, int, int, int );
+int FindFluidBlock( int, int, int, int, int, int );
cWorld* m_World;
diff --git a/source/cRedstone.cpp b/source/cRedstone.cpp
index 1d865373b..111c012e2 100644
--- a/source/cRedstone.cpp
+++ b/source/cRedstone.cpp
@@ -1,4 +1,5 @@
#include "cRedstone.h"
+#include "cPiston.h"
#include "cRoot.h"
#include "cWorld.h"
#include "BlockID.h"
@@ -62,23 +63,32 @@ void cRedstone::ChangeRedstoneTorch( int fillx, int filly, int fillz, bool added
void cRedstone::LightRedstone( int fillx, int filly, int fillz, char metadata)
{
- //cWorld* World = cRoot::Get()->GetWorld();
- 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);
+ if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) ) {
+ printf("rsPiston 1\n");
+ cPiston Piston(m_World);
+ if (metadata > 0) {
+ printf("rsPiston 2\n");
+ Piston.ExtendPiston(fillx, filly, fillz);
+ } else {
+ printf("rsPiston 3\n");
+ 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);
- 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);
+ }
}