A powered block has several input/output connections, but at a starting point, we do not know whenever it is input or output.
Each block has a "Voltage" which is the energy that arrive to it minus the lost/used.
A powered block will provide power to all surrounding blocks, and each block take as input the higher voltage from surrounding blocks.
You could also complicate the system by defining an Intensity, but I will stay with Voltage only for simplicity.
Every time a change is performed to the circuit, by adding/removing blocks, or by the circuit itself, the change need to be propagate to all the circuit until stability.
I would suggest you to design an interface for any powered object (cube in MC):
bool isActive = false;
virtual void propagate(double inEnergy) = 0;
virtual void addSibling(shared_ptr<PowerInterface> newSibling) = 0;
virtual void removeSibling( shared_ptr<PowerInterface> remSibling) =0;
So supposing you implement the addSibling and removeSibling, the most important part is the propagate function:
void PoweredCube::propagate( double inEnergy )
// Define the behaviour
energy = inEnergy-1.0; // Normal device
energy = inEnergy-0.1; // Normal cable
energy = 10.0; // Normal source of power.
energy = 0.0;
isActive = false;
// No energy, so do not propagate anymore
isActive = true;
for (auto &s: sibling)
// Only propagate to sibling with less energy.
if (energy > s->energy) s->propagate( energy);
As a recursive solution, each block should reduce a bit the energy, never increase it. The source of power can set a fixed value, but never increase based on inputs. That should not be an issue as all "real" system work in this way.