cofh.api.energy.IEnergyProvider Java Examples

The following examples show how to use cofh.api.energy.IEnergyProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DroneInteractRFImport.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example #2
Source File: AdapterEnergyProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Class<?> getTargetClass() {
	return IEnergyProvider.class;
}
 
Example #3
Source File: AdapterEnergyProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the energy stored in the machine.", returnTypes = ReturnType.NUMBER)
public int getEnergyStored(IEnergyProvider tileEntity,
		@Optionals @Arg(name = "side", description = "The direction you are interested in. (north, south, east, west, up or down)") ForgeDirection side) {
	return tileEntity.getEnergyStored(side != null? side : ForgeDirection.UNKNOWN);
}
 
Example #4
Source File: AdapterEnergyProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the max energy stored in the machine.", returnTypes = ReturnType.NUMBER)
public int getMaxEnergyStored(IEnergyProvider tileEntity,
		@Optionals @Arg(name = "side", description = "The direction you are interested in. (north, south, east, west, up or down)") ForgeDirection side) {
	return tileEntity.getMaxEnergyStored(side != null? side : ForgeDirection.UNKNOWN);
}
 
Example #5
Source File: ItemJetpackFueller.java    From SimplyJetpacks with MIT License 4 votes vote down vote up
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
            
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
 
Example #6
Source File: BeefGuiPowerBar.java    From BigReactors with MIT License 4 votes vote down vote up
public BeefGuiPowerBar(BeefGuiBase container, int x, int y, IEnergyProvider entity) {
	super(container, x, y);
	_entity = entity;
}