use of gregtech.common.terminal.hardware.BatteryHardware in project GregTech by GregTechCEu.
the class TerminalOSWidget method openApplication.
public void openApplication(AbstractApplication application, boolean isClient) {
desktop.removeAllDialogs();
NBTTagCompound nbt = tabletNBT.getCompoundTag(application.getRegistryName());
if (!TerminalBehaviour.isCreative(itemStack)) {
List<Hardware> hwDemand = TerminalRegistry.getAppHardwareDemand(application.getRegistryName(), Math.min(nbt.getInteger("_tier"), application.getMaxTier()));
List<Hardware> unMatch = hwDemand.stream().filter(demand -> getHardware().stream().noneMatch(hw -> hw.isHardwareAdequate(demand))).collect(Collectors.toList());
if (unMatch.size() > 0) {
if (isClient) {
StringBuilder tooltips = new StringBuilder("\n");
for (Hardware match : unMatch) {
String info = match.addInformation();
String name = match.getLocalizedName();
if (info == null) {
tooltips.append(name);
} else if (match instanceof BatteryHardware) {
IElectricItem energyItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (energyItem != null && energyItem.getCharge() <= 0) {
tooltips.append(I18n.format("terminal.battery.low_energy"));
} else {
tooltips.append(String.format("%s (%s+)", name, info));
}
} else {
tooltips.append(String.format("%s (%s)", name, info));
}
tooltips.append(" ");
}
TerminalDialogWidget.showInfoDialog(this, "terminal.component.error", I18n.format("terminal.os.hw_demand") + tooltips).setClientSide().open();
}
return;
}
}
if (!application.canPlayerUse(gui.entityPlayer)) {
return;
}
if (focusApp != null) {
closeApplication(focusApp, isClient);
}
for (AbstractApplication app : openedApps) {
if (app.getRegistryName().equals(application.getRegistryName()) && application.canLaunchConcurrently(app)) {
app.onOSSizeUpdate(this.getSize().width, this.getSize().height);
maximizeApplication(app, isClient);
return;
}
}
AbstractApplication app = application.createAppInstance(this, isClient, nbt);
if (app != null) {
desktop.addWidget(app);
app.setOs(this).initApp();
app.onOSSizeUpdate(this.getSize().width, this.getSize().height);
openedApps.add(app);
maximizeApplication(app, isClient);
}
}
use of gregtech.common.terminal.hardware.BatteryHardware in project GregTech by GregTechCEu.
the class TerminalOSWidget method readUpdateInfo.
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
if (id == -1) {
// disCharge
long charge = buffer.readLong();
IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (electricItem instanceof BatteryHardware) {
((BatteryHardware) electricItem).setCharge(charge);
}
if (charge <= 0) {
List<AbstractApplication> toClosed = new LinkedList<>();
for (AbstractApplication openedApp : openedApps) {
TerminalRegistry.getAppHardwareDemand(openedApp.getRegistryName(), openedApp.getAppTier()).stream().filter(i -> i instanceof BatteryHardware).findFirst().ifPresent(x -> toClosed.add(openedApp));
}
for (AbstractApplication close : toClosed) {
this.closeApplication(close, true);
}
TerminalDialogWidget.showInfoDialog(this, "terminal.component.warning", "terminal.battery.low_energy").setClientSide().open();
}
} else if (id == -2) {
// shutdown
shutdown(true);
} else {
super.readUpdateInfo(id, buffer);
}
}
use of gregtech.common.terminal.hardware.BatteryHardware in project GregTech by GregTechCEu.
the class TerminalRegistry method init.
public static void init() {
// register hardware
registerHardware(new BatteryHardware());
int deviceSize = DeviceHardware.DEVICE.values().length;
for (int i = 1; i < deviceSize; i++) {
registerHardware(new DeviceHardware(i));
}
// register applications
AppRegistryBuilder.create(new SimpleMachineGuideApp()).defaultApp().build();
AppRegistryBuilder.create(new MultiBlockGuideApp()).defaultApp().build();
AppRegistryBuilder.create(new ItemGuideApp()).defaultApp().build();
AppRegistryBuilder.create(new TutorialGuideApp()).defaultApp().build();
AppRegistryBuilder.create(new GuideEditorApp()).defaultApp().build();
AppRegistryBuilder.create(new SettingsApp()).defaultApp().build();
AppRegistryBuilder.create(new PongApp()).battery(GTValues.LV, 75).build();
AppRegistryBuilder.create(new MazeApp()).battery(GTValues.LV, 150).build();
AppRegistryBuilder.create(new MinesweeperApp()).battery(GTValues.LV, 150).build();
AppRegistryBuilder.create(new ProspectorApp(0)).battery(0, GTValues.LV, 640).battery(1, GTValues.LV, 640).battery(2, GTValues.MV, 1000).battery(3, GTValues.HV, 1500).battery(4, GTValues.HV, 1500).upgrade(0, MetaItems.SENSOR_LV.getStackForm(1)).upgrade(1, MetaItems.SENSOR_HV.getStackForm(1)).upgrade(2, MetaItems.SENSOR_EV.getStackForm(1)).upgrade(3, MetaItems.SENSOR_IV.getStackForm(1)).upgrade(4, MetaItems.SENSOR_LuV.getStackForm(1)).device(0, DeviceHardware.DEVICE.PROSPECTOR_LV).device(1, DeviceHardware.DEVICE.PROSPECTOR_LV).device(2, DeviceHardware.DEVICE.PROSPECTOR_LV).device(3, DeviceHardware.DEVICE.PROSPECTOR_HV).device(4, DeviceHardware.DEVICE.PROSPECTOR_HV).build();
AppRegistryBuilder.create(new ProspectorApp(1)).battery(0, GTValues.MV, 1000).battery(1, GTValues.MV, 1000).battery(2, GTValues.HV, 1500).battery(3, GTValues.HV, 1500).battery(4, GTValues.HV, 1500).upgrade(0, MetaItems.SENSOR_HV.getStackForm(1)).upgrade(1, MetaItems.SENSOR_HV.getStackForm(3)).upgrade(2, MetaItems.SENSOR_EV.getStackForm(1)).upgrade(3, MetaItems.SENSOR_IV.getStackForm(1)).upgrade(4, MetaItems.SENSOR_LuV.getStackForm(1)).device(DeviceHardware.DEVICE.PROSPECTOR_HV).build();
AppRegistryBuilder.create(new MultiBlockPreviewARApp()).battery(GTValues.LV, 128).device(DeviceHardware.DEVICE.CAMERA).upgrade(1, MetaItems.EMITTER_HV.getStackForm(4), MetaItems.WORKSTATION_EV.getStackForm(2)).defaultApp().build();
if (Loader.isModLoaded(GTValues.MODID_JEI)) {
AppRegistryBuilder.create(new RecipeChartApp()).battery(GTValues.LV, 160).upgrade(0, new ItemStack(Items.PAPER, 32)).upgrade(1, new ItemStack(Items.PAPER, 64)).upgrade(2, MetaItems.RANDOM_ACCESS_MEMORY.getStackForm(16)).upgrade(3, MetaItems.RANDOM_ACCESS_MEMORY.getStackForm(32)).build();
}
AppRegistryBuilder.create(new ConsoleApp()).battery(GTValues.LV, 500).device(DeviceHardware.DEVICE.WIRELESS).build();
AppRegistryBuilder.create(new BatteryManagerApp()).defaultApp().battery(GTValues.ULV, 0).build();
AppRegistryBuilder.create(new HardwareManagerApp()).defaultApp().build();
AppRegistryBuilder.create(new AppStoreApp()).defaultApp().build();
AppRegistryBuilder.create(new WorldProspectorARApp()).battery(GTValues.LV, 320).upgrade(0, MetaItems.EMITTER_LV.getStackForm(2)).upgrade(1, MetaItems.EMITTER_MV.getStackForm(2)).upgrade(2, MetaItems.EMITTER_HV.getStackForm(2)).device(DeviceHardware.DEVICE.CAMERA).build();
AppRegistryBuilder.create(new VirtualTankApp()).battery(GTValues.MV, 500).device(DeviceHardware.DEVICE.WIRELESS).build();
AppRegistryBuilder.create(new CapeSelectorApp()).battery(GTValues.ULV, 8).build();
if (Loader.isModLoaded(GTValues.MODID_CT)) {
// handle CT register
CTTerminalRegistry.register();
}
}
use of gregtech.common.terminal.hardware.BatteryHardware in project GregTech by GregTechCEu.
the class TerminalBehaviour method onUpdate.
@Override
public void onUpdate(ItemStack itemStack, Entity entity) {
NBTTagCompound tabletNBT = itemStack.getOrCreateSubCompound("terminal");
if (tabletNBT.hasKey("_ar")) {
String appName = tabletNBT.getString("_ar");
int tier = TerminalRegistry.getApplication(appName).getMaxTier();
if (!TerminalBehaviour.isCreative(itemStack)) {
tier = Math.min(tabletNBT.getCompoundTag(appName).getInteger("_tier"), tier);
}
long cost = 0;
for (Hardware hardware : TerminalRegistry.getAppHardwareDemand(appName, tier)) {
if (hardware instanceof BatteryHardware) {
cost = ((BatteryHardware) hardware).getCharge();
break;
}
}
if (cost > 0) {
IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (electricItem != null) {
long back = electricItem.discharge(cost, 999, true, false, false);
if (back != cost) {
tabletNBT.removeTag("_ar");
}
} else {
tabletNBT.removeTag("_ar");
}
}
}
}
use of gregtech.common.terminal.hardware.BatteryHardware in project GregTech by GregTechCEu.
the class BatteryManagerApp method addBatteryApps.
private void addBatteryApps() {
AtomicInteger index = new AtomicInteger();
for (AbstractApplication installed : getOs().installedApps) {
TerminalRegistry.getAppHardwareDemand(installed.getRegistryName(), getOs().tabletNBT.getCompoundTag(installed.getRegistryName()).getInteger("_tier")).stream().filter(i -> i instanceof BatteryHardware).findFirst().ifPresent(battery -> {
long charge = ((BatteryHardware) battery).getCharge();
this.addWidget(new RectButtonWidget(180 + (index.get() % 5) * 30, 15 + (index.get() / 5) * 30, 20, 20, 2).setIcon(installed.getIcon()).setHoverText(I18n.format("terminal.battery.hover", I18n.format(installed.getUnlocalizedName()), charge)).setColors(0, TerminalTheme.COLOR_7.getColor(), 0));
index.getAndIncrement();
});
}
}
Aggregations