Search in sources :

Example 1 with Hardware

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);
    }
}
Also used : AbstractWidgetGroup(gregtech.api.gui.widgets.AbstractWidgetGroup) IRenderContext(gregtech.api.gui.IRenderContext) Size(gregtech.api.util.Size) Constants(net.minecraftforge.common.util.Constants) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) ArrayList(java.util.ArrayList) TerminalRegistry(gregtech.api.terminal.TerminalRegistry) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) Widget(gregtech.api.gui.Widget) Minecraft(net.minecraft.client.Minecraft) RenderUtil(gregtech.client.utils.RenderUtil) net.minecraft.nbt(net.minecraft.nbt) LinkedList(java.util.LinkedList) TerminalBehaviour(gregtech.common.items.behaviors.TerminalBehaviour) DeviceHardware(gregtech.common.terminal.hardware.DeviceHardware) HardwareProvider(gregtech.api.terminal.hardware.HardwareProvider) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) Hardware(gregtech.api.terminal.hardware.Hardware) Collectors(java.util.stream.Collectors) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) IElectricItem(gregtech.api.capability.IElectricItem) AtomicLong(java.util.concurrent.atomic.AtomicLong) Position(gregtech.api.util.Position) List(java.util.List) GregtechCapabilities(gregtech.api.capability.GregtechCapabilities) TextureArea(gregtech.api.gui.resources.TextureArea) TerminalMenuWidget(gregtech.api.terminal.os.menu.TerminalMenuWidget) IGuiTexture(gregtech.api.gui.resources.IGuiTexture) ModularUI(gregtech.api.gui.ModularUI) Collections(java.util.Collections) OsSettings(gregtech.common.terminal.app.settings.widgets.OsSettings) PacketBuffer(net.minecraft.network.PacketBuffer) IElectricItem(gregtech.api.capability.IElectricItem) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) DeviceHardware(gregtech.common.terminal.hardware.DeviceHardware) Hardware(gregtech.api.terminal.hardware.Hardware)

Example 2 with Hardware

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");
            }
        }
    }
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) Hardware(gregtech.api.terminal.hardware.Hardware)

Example 3 with Hardware

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));
            }
        }
    }
}
Also used : HardwareProvider(gregtech.api.terminal.hardware.HardwareProvider) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) Hardware(gregtech.api.terminal.hardware.Hardware)

Example 4 with Hardware

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) WidgetGroup(gregtech.api.gui.widgets.WidgetGroup) Hardware(gregtech.api.terminal.hardware.Hardware) RectButtonWidget(gregtech.api.terminal.gui.widgets.RectButtonWidget)

Aggregations

Hardware (gregtech.api.terminal.hardware.Hardware)4 BatteryHardware (gregtech.common.terminal.hardware.BatteryHardware)3 IElectricItem (gregtech.api.capability.IElectricItem)2 AbstractApplication (gregtech.api.terminal.app.AbstractApplication)2 HardwareProvider (gregtech.api.terminal.hardware.HardwareProvider)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 WidgetGroup (gregtech.api.gui.widgets.WidgetGroup)1 TerminalRegistry (gregtech.api.terminal.TerminalRegistry)1 RectButtonWidget (gregtech.api.terminal.gui.widgets.RectButtonWidget)1 TerminalMenuWidget (gregtech.api.terminal.os.menu.TerminalMenuWidget)1 Position (gregtech.api.util.Position)1 Size (gregtech.api.util.Size)1 RenderUtil (gregtech.client.utils.RenderUtil)1 TerminalBehaviour (gregtech.common.items.behaviors.TerminalBehaviour)1