Custom Engine/Storage
Speiger opened this issue · 1 comments
i made a custom Engine. Emmm i think its more like a storage.
First it works a little bit buggy but i works.
Now my trouble i found. I can only add energy to the system from the top or bottom. side won´t work. i know its buildcraft related (not modsided) but i make something wrong. so explain me how can i implement energy without problem?
Here My code (as much as you need):
public void SendMinecraftJoules()
{
for(int i = 0; i<6; i++)
{
//My Side sensitive Form of get TileEntity.
TileEntity tile = WorldReading.getTileEntity(worldObj, xCoord, yCoord, zCoord, i);
if(tile != null && this.isPoweredTile(tile, ForgeDirection.getOrientation(i)) && this.tileNeedsEnergy(tile, ForgeDirection.getOrientation(i)))
{
PowerReceiver pr = ((IPowerReceptor) tile).getPowerReceiver(ForgeDirection.getOrientation(i));
//Output: yeah i have a variables out. default is 10 MJ
float send = power.useEnergy(1, output, true);
if(send > 0)
{
float b = pr.receiveEnergy(Type.STORAGE, send, WorldReading.getDirectionFromNumber(WorldReading.getSidePerRotation(getFacing(), i)));
if(b > 0)
{
this.MJ += b;
b = 0;
}
}
}
}
}
public void MjToMinecraftJoules()
{
if(MJ > 0 && power.getEnergyStored() < 10000)
{
if(MJ >= 10 && power.getEnergyStored() <= 9990)
{
if(MJ >= 100 && power.getEnergyStored() <= 9900)
{
if(MJ >= 1000 && power.getEnergyStored() <= 9000)
{
MJ-=1000;
power.getPowerReceiver().receiveEnergy(Type.STORAGE, 1000, ForgeDirection.UP);
}
else
{
MJ-=100;
power.getPowerReceiver().receiveEnergy(Type.STORAGE, 100, ForgeDirection.UP);
}
}
else
{
MJ-=10;
power.getPowerReceiver().receiveEnergy(Type.STORAGE, 10, ForgeDirection.UP);
}
}
else
{
MJ--;
power.getPowerReceiver().receiveEnergy(Type.STORAGE, 1, ForgeDirection.UP);
}
}
}
private boolean tileNeedsEnergy(TileEntity tile, ForgeDirection par2)
{
if(tile instanceof IPowerReceptor)
{
PowerReceiver ipw = ((IPowerReceptor) tile).getPowerReceiver(par2);
if(ipw.powerRequest() > 0)
{
return true;
}
}
return false;
}
public boolean isPoweredTile(TileEntity tile, ForgeDirection side) {
if (tile instanceof IPowerReceptor) {
return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null;
}
return false;
}
if you want to see the block and what it does. A german guy has a video about it: