Search in sources :

Example 1 with GuideApp

use of gregtech.common.terminal.app.guide.GuideApp in project GregTech by GregTechCEu.

the class GuideConfigEditor method loadJson.

public void loadJson() {
    if (pageEditor != null) {
        File file = new File(TerminalRegistry.TERMINAL_PATH, "guide");
        TerminalDialogWidget.showFileDialog(app.getOs(), "terminal.component.load_file", file, true, result -> {
            if (result != null && result.isFile()) {
                try {
                    JsonObject config = Objects.requireNonNull(FileUtility.loadJson(result)).getAsJsonObject();
                    pageEditor.loadJsonConfig(config);
                    getPageEditor().setSection(config.get("section").getAsString());
                    updateTitle(config.get("title").getAsString());
                    for (AbstractApplication app : TerminalRegistry.getAllApps()) {
                        if (app instanceof GuideApp) {
                            Object object = ((GuideApp<?>) app).ofJson(config);
                            if (object != null) {
                                type = app.getUnlocalizedName();
                                if (object instanceof ItemGuideApp.GuideItem) {
                                    handler.setStackInSlot(0, ((ItemGuideApp.GuideItem) object).stack.copy());
                                } else if (object instanceof MetaTileEntity) {
                                    handler.setStackInSlot(0, ((MetaTileEntity) object).getStackForm());
                                } else if (object instanceof ItemStack) {
                                    handler.setStackInSlot(0, ((ItemStack) object).copy());
                                } else {
                                    handler.setStackInSlot(0, ItemStack.EMPTY);
                                }
                                break;
                            }
                        }
                    }
                } catch (Exception e) {
                    TerminalDialogWidget.showInfoDialog(app.getOs(), "terminal.component.error", "terminal.component.load_file.error").setClientSide().open();
                }
            }
        }).setClientSide().open();
    }
}
Also used : AbstractApplication(gregtech.api.terminal.app.AbstractApplication) JsonObject(com.google.gson.JsonObject) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) JsonObject(com.google.gson.JsonObject) MultiBlockGuideApp(gregtech.common.terminal.app.guide.MultiBlockGuideApp) SimpleMachineGuideApp(gregtech.common.terminal.app.guide.SimpleMachineGuideApp) GuideApp(gregtech.common.terminal.app.guide.GuideApp) ItemGuideApp(gregtech.common.terminal.app.guide.ItemGuideApp) ItemStack(net.minecraft.item.ItemStack) File(java.io.File)

Aggregations

JsonObject (com.google.gson.JsonObject)1 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 AbstractApplication (gregtech.api.terminal.app.AbstractApplication)1 GuideApp (gregtech.common.terminal.app.guide.GuideApp)1 ItemGuideApp (gregtech.common.terminal.app.guide.ItemGuideApp)1 MultiBlockGuideApp (gregtech.common.terminal.app.guide.MultiBlockGuideApp)1 SimpleMachineGuideApp (gregtech.common.terminal.app.guide.SimpleMachineGuideApp)1 File (java.io.File)1 ItemStack (net.minecraft.item.ItemStack)1