Search in sources :

Example 1 with IEnergyStorage

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;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEnergyProvider(cofh.api.energy.IEnergyProvider) IEnergyStorage(cofh.api.energy.IEnergyStorage) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 2 with IEnergyStorage

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;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEnergyStorage(cofh.api.energy.IEnergyStorage) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IEnergyReceiver(cofh.api.energy.IEnergyReceiver)

Example 3 with IEnergyStorage

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);
        }
    }
}
Also used : LogisticsPowerJunctionTileEntity(logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AIRobotGotoStation(buildcraft.robotics.ai.AIRobotGotoStation) IEnergyStorage(cofh.api.energy.IEnergyStorage) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe)

Aggregations

IEnergyStorage (cofh.api.energy.IEnergyStorage)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 AIRobotGotoStation (buildcraft.robotics.ai.AIRobotGotoStation)1 IEnergyProvider (cofh.api.energy.IEnergyProvider)1 IEnergyReceiver (cofh.api.energy.IEnergyReceiver)1 LogisticsPowerJunctionTileEntity (logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity)1 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)1 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)1