Search in sources :

Example 6 with BatteryHardware

use of gregtech.common.terminal.hardware.BatteryHardware in project GregTech by GregTechCEu.

the class TerminalOSWidget method disCharge.

private long disCharge() {
    IElectricItem electricItem = hardwareProvider.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
    if (electricItem != null && !TerminalBehaviour.isCreative(itemStack)) {
        AtomicLong costs = new AtomicLong(0);
        List<AbstractApplication> charged = new ArrayList<>();
        for (AbstractApplication openedApp : openedApps) {
            TerminalRegistry.getAppHardwareDemand(openedApp.getRegistryName(), openedApp.getAppTier()).stream().filter(i -> i instanceof BatteryHardware).findFirst().ifPresent(battery -> {
                costs.addAndGet(((BatteryHardware) battery).getCharge());
                charged.add(openedApp);
            });
        }
        for (DeviceHardware hardware : getHardware(DeviceHardware.class)) {
            if (hardware.getDevice() == DeviceHardware.DEVICE.SOLAR_LV) {
                costs.addAndGet(-200);
            }
        }
        if (costs.get() > 0 && electricItem.discharge(costs.get(), 999, true, false, false) != costs.get()) {
            charged.forEach(app -> closeApplication(app, false));
        } else if (costs.get() < 0) {
            electricItem.charge(-costs.get(), 999, true, false);
        }
        return electricItem.getCharge();
    }
    return lastCharge;
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) ArrayList(java.util.ArrayList) DeviceHardware(gregtech.common.terminal.hardware.DeviceHardware)

Aggregations

BatteryHardware (gregtech.common.terminal.hardware.BatteryHardware)6 IElectricItem (gregtech.api.capability.IElectricItem)4 AbstractApplication (gregtech.api.terminal.app.AbstractApplication)4 DeviceHardware (gregtech.common.terminal.hardware.DeviceHardware)3 Hardware (gregtech.api.terminal.hardware.Hardware)2 LinkedList (java.util.LinkedList)2 ItemStack (net.minecraft.item.ItemStack)2 GregtechCapabilities (gregtech.api.capability.GregtechCapabilities)1 IRenderContext (gregtech.api.gui.IRenderContext)1 ModularUI (gregtech.api.gui.ModularUI)1 Widget (gregtech.api.gui.Widget)1 IGuiTexture (gregtech.api.gui.resources.IGuiTexture)1 TextureArea (gregtech.api.gui.resources.TextureArea)1 AbstractWidgetGroup (gregtech.api.gui.widgets.AbstractWidgetGroup)1 TerminalRegistry (gregtech.api.terminal.TerminalRegistry)1 RectButtonWidget (gregtech.api.terminal.gui.widgets.RectButtonWidget)1 HardwareProvider (gregtech.api.terminal.hardware.HardwareProvider)1 TerminalMenuWidget (gregtech.api.terminal.os.menu.TerminalMenuWidget)1 Position (gregtech.api.util.Position)1 Size (gregtech.api.util.Size)1