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;
}
Aggregations