summaryrefslogtreecommitdiffstats
path: root/source/cRedstone.cpp
diff options
context:
space:
mode:
authoradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-06 21:39:44 +0100
committeradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-06 21:39:44 +0100
commitcc4e4345deebd36db77ec8befea4894c4169d0ed (patch)
tree0d5ba972628b757be1c7ae6fa0a088f1d5220969 /source/cRedstone.cpp
parentPatch with diff file created by Sebi (implemented some stuff like lava physics, drops are deleted when in lava, water is now slower, lava gives actual damage etc.). Pistons now work mostly as they should. They do not yet show the motion animation and do not emit sound. They do extend, push, and retract as they should though. Right now the only way to activate a piston is to light redstone wire adjacent to it with a redstone torch. (diff)
downloadcuberite-cc4e4345deebd36db77ec8befea4894c4169d0ed.tar
cuberite-cc4e4345deebd36db77ec8befea4894c4169d0ed.tar.gz
cuberite-cc4e4345deebd36db77ec8befea4894c4169d0ed.tar.bz2
cuberite-cc4e4345deebd36db77ec8befea4894c4169d0ed.tar.lz
cuberite-cc4e4345deebd36db77ec8befea4894c4169d0ed.tar.xz
cuberite-cc4e4345deebd36db77ec8befea4894c4169d0ed.tar.zst
cuberite-cc4e4345deebd36db77ec8befea4894c4169d0ed.zip
Diffstat (limited to 'source/cRedstone.cpp')
-rw-r--r--source/cRedstone.cpp232
1 files changed, 200 insertions, 32 deletions
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