list<emitter> emitters;
int current_emitter = 0;
class emitter
{
int x, y, z;
int cx, cy, cz;
int px, py, pz, ploss;
byte d, dx, dy, dz;
emitter(a, b, c)
{
x = a;
y = b;
z = c;
changed();
}
void changed()
{
d = block_facing(x, y, z);
switch(d) //for each direction
{
case 0: dx = 0; dy = 0; dz = 1; break;
case 1: dx = 0; dy = 1; dz = 0; break;
case 2: dx = 1; dy = 0; dz = 0; break;
case 3: dx =-1; dy = 0; dz = 0; break;
case 4: dx = 0; dy =-1; dz = 0; break;
case 5: dx = 0; dy = 0; dz =-1; break;
}
cx = x + dx;
cy = y + dy;
cz = z + dz;
px = x;
py = y;
pz = z;
ploss = 0;
}
}
//called everytime a new emitter is added to the world
// not sure exactly how MC works on chunkdata or whether
// it needs to be stored in a separate file, but this is
// pseudo-code anyway
void add_emitter(x, y, z)
{
emitters.add(new emitter(x,y,z));
}
//called everytime an emitter is destroyed or removed
// from the world given the location
void delete_emitter(x, y, z)
{
foreach(emitter i in emitters)
{
if((i.x == x) && (i.y == y) && (i.z == z))
{
emitters.delete(i);
break;
}
}
}
//called whenever you hit the emitter with the wrench
// to change its orientation
void change_emitter(x, y, z)
{
foreach(emitter i in emitters)
{
if((i.x == x) && (i.y == y) && (i.z == z))
{
i.changed();
break;
}
}
}
//called each tick
void tick_update()
{
foreach(emitter i in emitters)
{
//check if connected to collector and that the
// collector is facing the right direction
block b = block_at(i.px, i.py, i.pz);
if((b == Collector) && ((block_facing(i.px, i.py, i.pz) + i.d) == 5))
{
//give it a packet
if(Emitter::is_ready(i.x, i.y, i.z))
Collector::add_energy(512 - i.ploss);
}
//slowly cycle through blocks from emitter to check for
// emitters and obstructions. This is slow to resolve
// lag issues on long distances. Again, not sure how
// MC does locations/chunks that are not loaded.
b = block_at(i.cx, i.cy, i.cz);
if(b == Air)
{
//about 0.2% loss per block, better than
// 0.78125% of 2xIns Gold but less than
// 0.00976% of Fibre Cable
i.ploss += 1;
i.cx += i.dx;
i.cy += i.dy;
i.cz += i.dz;
continue;
}
if(b == Collector)
{
i.px = i.cx;
i.py = i.cy;
i.pz = i.cz;
//there will always be 1 EU no matter what.
// You did use a lot of solar panels, and
// there has to be SOME light that hits them
//this is also to let you know if you even are
// in line with the emitter
i.ploss = min(511, i.ploss);
continue;
}
if(b == Glass)
{
//about 1.9% loss through glass due to refraction
i.ploss += 10;
continue;
}
if(b == ReinforcedGlass)
{
//about 19.5% loss through reinforced glass
i.ploss += 100;
continue;
}
//reset and have another go later
i.cx = i.x + i.dx;
i.dy = i.y + i.dy;
i.dz = i.z + i.dz;
i.px = i.x;
i.py = i.y;
i.pz = i.z;
}
}