有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Minecraft无法放置自定义背景

我正在做一个定制的minecraft客户。为此,我想制作一个自定义主菜单,我尝试以下代码:

@Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        // draw a image
        mc.getTextureManager().bindTexture(new ResourceLocation("moon/gui/background.jpg"));
        this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, this.width, this.height, this.width, this.height);
        super.drawScreen(mouseX,mouseY,partialTicks);
    }

然后用CustomMainMenu(这是我的主菜单类)替换GuiMainMenu(这是默认的Minecraft主菜单类),然后我尝试运行它,结果是两个粉红色和黑色框,表示背景文件,即bg。没有找到jpg。控制台输出显示java,这一点得到了证实。未找到io文件。我想让它显示我的背景图像,但它没有

我试过几件事:

  • 重新下载java
  • 更改背景图像
  • MOON更改背景图像包。gui月亮。gui月亮并返回到月亮。图形用户界面
  • 在Minecraft客户制作discord server时寻求帮助

我的CustomMainMenu类的全部代码是:

package me.debug.moon.ui;

import net.minecraft.client.gui.*;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;

public class MainMenu extends GuiScreen {
    // create a override drawScreem
    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        // draw a image
        mc.getTextureManager().bindTexture(new ResourceLocation("moon/gui/bg.jpg"));
        this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, this.width, this.height, this.width, this.height);
        super.drawScreen(mouseX,mouseY,partialTicks);
    }

    // create override super initGui
    @Override
    public void initGui() {
        this.buttonList.add(new GuiButton(1, this.width / 2 - 40, this.height / 2 - 40, 200, 20, "Single-Player"));
        this.buttonList.add(new GuiButton(2, this.width / 2 - 15, this.height / 2 - 15, 200, 20, "Multi-Player"));
        this.buttonList.add(new GuiButton(3, this.width / 2 + 10, this.height / 2 + 10, 200, 20, "Settings"));
        this.buttonList.add(new GuiButton(4, this.width / 2 + 40, this.height / 2 + 40, 20, 20, "Exit"));
        super.initGui();
    }

    //create super override actionPerformed
    @Override
    protected void actionPerformed(GuiButton button) {
        switch (button.id) {
            case 1:
                this.mc.displayGuiScreen(new GuiSelectWorld(this));
                break;
            case 2:
                this.mc.displayGuiScreen(new GuiMultiplayer(this));
                break;
            case 3:
                this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
                break;
            case 4:
                mc.shutdown();
                break;
        }
    }
}

我的文件结构是:File Structure


共 (1) 个答案

  1. # 1 楼答案

    你说“找不到文件”。这可能是由多种因素造成的:

    • 文件不在插件中(似乎是您的案例

    如何修复:

    你应该检查一下包装是否完好。在您的情况下,它们应该在src/resources上,但您在其他地方编写了它们。因此,将其移动到src/resources/moon/gui/bg.jpg

    • 未在运行的jar中导出

    如何修复:

    这取决于您在maven/gradle/something之间使用了什么,以及它们的配置。但是默认情况下,src/resources的所有内容都包含在jar中

    • 没有足够的权限读取文件

    如何修复:

    您必须检查为什么没有权限,并添加“读取”烫发。例如,在linux上,它使用chmod命令