use of cofh.api.energy.IEnergyStorage in project PneumaticCraft by MineMaarten.
the class DroneInteractRFImport method doInteract.
@Override
public boolean doInteract(ChunkPosition pos, IDrone drone, IBlockInteractHandler interactHandler, boolean simulate) {
IEnergyStorage droneEnergy = CoFHCore.getEnergyStorage(drone);
if (droneEnergy.getEnergyStored() == droneEnergy.getMaxEnergyStored()) {
interactHandler.abort();
return false;
} else {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
if (te instanceof IEnergyProvider) {
IEnergyProvider provider = (IEnergyProvider) te;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (interactHandler.getSides()[d.ordinal()]) {
int transferedEnergy = droneEnergy.receiveEnergy(provider.extractEnergy(d, interactHandler.useCount() ? interactHandler.getRemainingCount() : Integer.MAX_VALUE, true), true);
if (transferedEnergy > 0) {
if (!simulate) {
interactHandler.decreaseCount(transferedEnergy);
droneEnergy.receiveEnergy(transferedEnergy, false);
provider.extractEnergy(d, transferedEnergy, false);
}
return true;
}
}
}
}
return false;
}
}
use of cofh.api.energy.IEnergyStorage in project PneumaticCraft by MineMaarten.
the class DroneInteractRFExport method doInteract.
@Override
public boolean doInteract(ChunkPosition pos, IDrone drone, IBlockInteractHandler interactHandler, boolean simulate) {
IEnergyStorage droneEnergy = CoFHCore.getEnergyStorage(drone);
if (droneEnergy.getEnergyStored() == 0) {
interactHandler.abort();
return false;
} else {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
if (te instanceof IEnergyReceiver) {
IEnergyReceiver receiver = (IEnergyReceiver) te;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (interactHandler.getSides()[d.ordinal()]) {
int transferedEnergy = droneEnergy.extractEnergy(receiver.receiveEnergy(d, interactHandler.useCount() ? interactHandler.getRemainingCount() : Integer.MAX_VALUE, true), true);
if (transferedEnergy > 0) {
if (!simulate) {
interactHandler.decreaseCount(transferedEnergy);
droneEnergy.extractEnergy(transferedEnergy, false);
receiver.receiveEnergy(d, transferedEnergy, false);
}
return true;
}
}
}
}
return false;
}
}
use of cofh.api.energy.IEnergyStorage in project LogisticsPipes by RS485.
the class LogisticsRoutingBoardRobot method lpUpdate.
public void lpUpdate() {
index();
if (robot.containsItems()) {
ticksWithContent++;
if (ticksWithContent > 20 * 2) {
startTransport();
ticksWithContent = 0;
}
} else {
ticksWithContent = 0;
acceptsItems = true;
if (currentTarget != null) {
startDelegateAI(new AIRobotGotoStation(robot, robot.getLinkedStation()));
currentTarget = null;
refreshRoutingTable();
} else if (robot.getDockingStation() == null) {
startDelegateAI(new AIRobotGotoStation(robot, robot.getLinkedStation()));
}
}
IEnergyStorage bat = robot.getBattery();
int need = bat.getMaxEnergyStored() - bat.getEnergyStored();
if (need <= 1000) {
return;
}
need = bat.receiveEnergy(need, true);
TileEntity tile = getLinkedStationPosition().getTileEntity(robot.worldObj);
if (tile instanceof LogisticsTileGenericPipe && ((LogisticsTileGenericPipe) tile).isRoutingPipe()) {
CoreRoutedPipe pipe = ((LogisticsTileGenericPipe) tile).getRoutingPipe();
boolean energyUsed = false;
int count = 0;
while (!energyUsed) {
if (pipe.useEnergy((int) (need * 1.5D * LogisticsPowerJunctionTileEntity.RFDivisor))) {
energyUsed = true;
}
if (count++ > 5) {
break;
}
}
if (energyUsed) {
bat.receiveEnergy(need, false);
}
}
}
Aggregations