Search in sources :

Example 1 with BatteryHardware

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);
    }
}
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 BatteryHardware

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);
    }
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) LinkedList(java.util.LinkedList)

Example 3 with BatteryHardware

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();
    }
}
Also used : MinesweeperApp(gregtech.common.terminal.app.game.minesweeper.MinesweeperApp) WorldProspectorARApp(gregtech.common.terminal.app.worldprospector.WorldProspectorARApp) VirtualTankApp(gregtech.common.terminal.app.VirtualTankApp) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) MultiBlockGuideApp(gregtech.common.terminal.app.guide.MultiBlockGuideApp) RecipeChartApp(gregtech.common.terminal.app.recipechart.RecipeChartApp) BatteryManagerApp(gregtech.common.terminal.app.batterymanager.BatteryManagerApp) SimpleMachineGuideApp(gregtech.common.terminal.app.guide.SimpleMachineGuideApp) MazeApp(gregtech.common.terminal.app.game.maze.MazeApp) CapeSelectorApp(gregtech.common.terminal.app.capeselector.CapeSelectorApp) SettingsApp(gregtech.common.terminal.app.settings.SettingsApp) HardwareManagerApp(gregtech.common.terminal.app.hardwaremanager.HardwareManagerApp) GuideEditorApp(gregtech.common.terminal.app.guideeditor.GuideEditorApp) MultiBlockPreviewARApp(gregtech.common.terminal.app.multiblockhelper.MultiBlockPreviewARApp) PongApp(gregtech.common.terminal.app.game.pong.PongApp) AppStoreApp(gregtech.common.terminal.app.appstore.AppStoreApp) ItemGuideApp(gregtech.common.terminal.app.guide.ItemGuideApp) ConsoleApp(gregtech.common.terminal.app.console.ConsoleApp) ProspectorApp(gregtech.common.terminal.app.prospector.ProspectorApp) TutorialGuideApp(gregtech.common.terminal.app.guide.TutorialGuideApp) ItemStack(net.minecraft.item.ItemStack) DeviceHardware(gregtech.common.terminal.hardware.DeviceHardware)

Example 4 with BatteryHardware

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");
            }
        }
    }
}
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 5 with BatteryHardware

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

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