use of gregtech.api.terminal.hardware.Hardware 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.api.terminal.hardware.Hardware 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.api.terminal.hardware.Hardware in project GregTech by GregTechCEu.
the class TerminalBehaviour method addInformation.
@Override
public void addInformation(ItemStack itemStack, List<String> lines) {
HardwareProvider provider = itemStack.getCapability(GregtechCapabilities.CAPABILITY_HARDWARE_PROVIDER, null);
if (isCreative(itemStack)) {
lines.add(I18n.format("metaitem.terminal.tooltip.creative"));
}
if (provider != null) {
List<Hardware> hardware = provider.getHardware();
lines.add(I18n.format("metaitem.terminal.tooltip.hardware", hardware.size()));
for (Hardware hw : hardware) {
String info = hw.addInformation();
if (info == null) {
lines.add(hw.getLocalizedName());
} else {
lines.add(String.format("%s (%s)", hw.getLocalizedName(), info));
}
}
}
}
use of gregtech.api.terminal.hardware.Hardware in project GregTech by GregTechCEu.
the class HardwareManagerApp method initApp.
@Override
public AbstractApplication initApp() {
apps = new WidgetGroup();
this.addWidget(apps);
int x = 10;
int y = 65;
for (Hardware hardware : os.hardwareProvider.getProviders().values()) {
HardwareSlotWidget hardwareSlotWidget = new HardwareSlotWidget(x, y, os, hardware);
this.addWidget(hardwareSlotWidget);
hardwareSlotWidget.setOnSelected(() -> {
selected = hardwareSlotWidget;
apps.clearAllWidgets();
AtomicInteger index = new AtomicInteger(0);
for (AbstractApplication installed : getOs().installedApps) {
TerminalRegistry.getAppHardwareDemand(installed.getRegistryName(), getOs().tabletNBT.getCompoundTag(installed.getRegistryName()).getInteger("_tier")).stream().filter(hardware::isHardwareAdequate).findFirst().ifPresent(X -> {
apps.addWidget(new RectButtonWidget(162 + (index.get() % 4) * 25, 122 + (index.get() / 4) * 30, 20, 20, 2).setIcon(installed.getIcon()).setHoverText(installed.getUnlocalizedName()).setColors(0, TerminalTheme.COLOR_7.getColor(), 0));
index.getAndIncrement();
});
}
});
x += 25;
}
return this;
}
Aggregations