首页 > 解决方案 > 更改 Minecraft Hotbar 图标 / FileInputStream

问题描述

好吧,我想在快捷栏中更改 Minecraft 的图标。我已经知道我必须编辑源代码并且已经找到了设置图标的行(见下文)。我必须制作一个 InputStream,但我不知道将图标放入的路径以及原始图标的路径。

我已经尝试创建一个新的资产文件夹并将 png 文件放在那里或将它们直接放入 minecraft 文件夹。

提前谢谢你亚伦

调用 setWindowIcon() 方法:

     //Original Code InputStreams
     //InputStream inputstream = this.getPackFinder().getVanillaPack().getResourceStream(ResourcePackType.CLIENT_RESOURCES, new ResourceLocation("icons/icon_16x16.png"));
     //InputStream inputstream1 = this.getPackFinder().getVanillaPack().getResourceStream(ResourcePackType.CLIENT_RESOURCES, new ResourceLocation("icons/icon_32x32.png"));

     //My attempt on InputStreams
     InputStream inputstream = new FileInputStream("icons/icon_16x16.png");
     InputStream inputstream1 = new FileInputStream("icons/icon_32x32.png");
     this.mainWindow.setWindowIcon(inputstream, inputstream1);

setWindowIcon() 方法:

   public void setWindowIcon(InputStream p_216529_1_, InputStream p_216529_2_) {
  RenderSystem.assertThread(RenderSystem::isInInitPhase);

  try (MemoryStack memorystack = MemoryStack.stackPush()) {
     if (p_216529_1_ == null) {
        throw new FileNotFoundException("icons/icon_16x16.png");
     }

     if (p_216529_2_ == null) {
        throw new FileNotFoundException("icons/icon_32x32.png");
     }

     IntBuffer intbuffer = memorystack.mallocInt(1);
     IntBuffer intbuffer1 = memorystack.mallocInt(1);
     IntBuffer intbuffer2 = memorystack.mallocInt(1);
     Buffer buffer = GLFWImage.mallocStack(2, memorystack);
     ByteBuffer bytebuffer = this.loadIcon(p_216529_1_, intbuffer, intbuffer1, intbuffer2);
     if (bytebuffer == null) {
        throw new IllegalStateException("Could not load icon: " + STBImage.stbi_failure_reason());
     }

     buffer.position(0);
     buffer.width(intbuffer.get(0));
     buffer.height(intbuffer1.get(0));
     buffer.pixels(bytebuffer);
     ByteBuffer bytebuffer1 = this.loadIcon(p_216529_2_, intbuffer, intbuffer1, intbuffer2);
     if (bytebuffer1 == null) {
        throw new IllegalStateException("Could not load icon: " + STBImage.stbi_failure_reason());
     }

     buffer.position(1);
     buffer.width(intbuffer.get(0));
     buffer.height(intbuffer1.get(0));
     buffer.pixels(bytebuffer1);
     buffer.position(0);
     GLFW.glfwSetWindowIcon(this.handle, buffer);
     STBImage.stbi_image_free(bytebuffer);
     STBImage.stbi_image_free(bytebuffer1);
  } catch (IOException ioexception) {
     LOGGER.error("Couldn't set icon", (Throwable)ioexception);
  }

}

标签: javaiconsminecraftminecraft-forgemod

解决方案


推荐阅读