【问题标题】:Minecraft cannot put custom background我的世界无法放置自定义背景
【发布时间】:2021-12-28 03:39:21
【问题描述】:

我正在制作一个自定义的 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);
    }

然后将 GuiMainMenu(这是默认的 Minecraft 主菜单类)替换为 CustomMainMenu(这是我的主菜单类)然后我尝试运行它,它结果出现 2 个粉红色和黑色框,表示未找到 bg.jpg 的背景文件。控制台输出证实了这一点,该输出显示 java.io 文件未找到。我希望它显示我的背景图片,但它没有。

我尝试了一些事情:

  • 重新下载java
  • 更改背景图片
  • 将背景图像包从 MOON.gui 更改为 moon.guimoon 并返回到 moon.gui强>
  • 在制作discord server 的 Minecraft 客户端中寻求帮助。

我的 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;
        }
    }
}

我的文件结构是:

【问题讨论】:

  • 你能展示你的项目结构吗?
  • 资产文件夹或代码文件夹@Elikill58
  • 两者,类似于that
  • 这样好吗? i.imgur.com/kAv8ZXe.png@Elikill58
  • 让我来回答一下。只是,你能在你的问题中包含这个屏幕吗?

标签: java user-interface minecraft


【解决方案1】:

您说“找不到文件”。这可能是由多种原因引起的:

  • 文件不在插件中(似乎是你的情况

如何解决:

您应该检查它们的包装是否完好。在您的情况下,它们应该在src/resources,但您在其他地方写了它们。所以,将其移至src/resources/moon/gui/bg.jpg

  • 未在运行的 jar 中导出

如何解决:

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

  • 读取文件的权限不足

如何解决:

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

【讨论】:

  • 当你说'你应该检查它们是否包装完好。在您的情况下,它们应该在 src/resources 上,但您将它们写在其他地方。所以,把它移到 src/resources/moon/gui/bg.jpg' 那不是它是如何工作的,我的世界客户端的资源文件夹是用于我的世界纹理、着色器、声音(基本上所有minecraft 需要)而不是 gui,但我仍然对其进行了测试,但它仍然无法正常工作并导致再次找不到文件错误。
  • 哦,是的。你应该把整个assets/minecraft 放在 src/resources
  • 抱歉@Elikill58 回复晚了,但我尝试了您将资产文件夹放入资源文件夹的方法,它奏效了!谢谢
  • 没问题!慢慢来,这不是问题 x)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-17
  • 2012-02-12
  • 1970-01-01
  • 2014-10-30
  • 2022-08-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多