1

我不得不使用 Minecraft Forge 更改 Minecraft 的主菜单。我设法更改了基本代码以将保存文件复制到 Saves 文件夹,然后加载该保存。但是当我编译它时它不起作用。我猜这是因为它是我编辑过的基类并且它没有包含在编译中。我也明白我不应该编辑基类,但它不会干扰任何东西,所以应该没问题。无论如何编译已编辑的基类,或者可能是另一种编辑主菜单的方式。我读过关于中断 GUI 的负载并用我自己的替换它,但我还没有找到任何好的方法来做到这一点。

下面是代码,稍微精简一下:net.minecraft.client.gui.GuiMainMenu.java

private void addSingleplayerMultiplayerButtons(int p_73969_1_, int p_73969_2_)
{
    this.buttonList.add(new GuiButton(15, this.width / 2 - 100, p_73969_1_, I18n.format("Quickplay", new Object[0])));
}

protected void actionPerformed(GuiButton p_146284_1_)
{
    if (p_146284_1_.id == 15)
    {
        // Clone and create new map
        File srcFolder = new File(System.getProperty("user.dir") + "\\quickMap");
        File destFolder = new File(System.getProperty("user.dir") + "\\saves\\tempQuickMap");

        //make sure source exists
        if(!srcFolder.exists()){

           //System.out.println("Directory does not exist.");
           //just exit
           //System.exit(0);

        }else{

           try{
            copyFolder(srcFolder,destFolder);
           }catch(IOException e){
            e.printStackTrace();
            //error, just exit
                //System.exit(0);
           }
        }

        //System.out.println("Done");
        // Cloning done

        if (this.mc.getSaveLoader().canLoadWorld("tempQuickMap"))
        {
            FMLClientHandler.instance().tryLoadExistingWorldMainMenu(this, "tempQuickMap", "Quickplay map");
        }
    }
}
4

1 回答 1

0

您可以在 1.7.x 中使用 ASM,但是对于您的目的来说它是复杂且不必要的。订阅 GuiOpenEvent,检查 gui 是否是主菜单,如果是,则调用 event.setGui 方法将其设置为您的 GUI。

于 2016-07-02T12:12:48.147 回答