java - 更改 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);
}
}
解决方案
推荐阅读
- python - 使用 fasttext 进行单词相似度查询
- python - Google Chrome 不会使用 xml-stylesheet 呈现 XML
- xml - 使用 JAXB 将 java.Util.Properties 类编组为 XML
- java - 相对布局的问题:右上角的锚定元素
- python - 我试图使用带有代码“pipenv install python”的pipenv安装numpy,但它不断出现错误
- amazon-web-services - 我可以将静态 IP 关联到我的 AWS Classic 负载均衡器吗
- javascript - createHtmlOutputFromFile 然后将变量附加为函数中的对象
- server - Windows 管理中心和无进度上传文件
- java - 在访问两个不同的 servlet 时,一个可用,另一个抛出 servlet not found 错误
- html - 移动响应式 CSS 无法正常工作的问题