本篇教程由作者设定使用 CC BY-NC-SA 协议。

本教程仅指明创建自定义的太阳能板动画材质出现的问题。(仅测试1.12.2版本,其他版本未测试)

创建自定义的太阳能板的教程 论坛已经有而且很详细,这里就不重复了。

起初制作自定义太阳能的时候发现动态材质并不能识别,翻了翻源代码知道发现是因为写法错误。

自定义太阳能的名字 是被作者复写进去模组的。在自定义的名字前面加了"custom_solar_panel_",材质文件的名字也是被复写的。问题就出在这里。

附上源代码:

if(si.isCustom)
{
  ResourceLocation textures_blocks_base = new ResourceLocation(reg.getNamespace(), "textures/blocks/" + reg.getPath() + "_base.png");
  ResourceLocation textures_blocks_top = new ResourceLocation(reg.getNamespace(), "textures/blocks/" + reg.getPath() + "_top.png");
  ResourceLocation textures_blocks_base_mcmeta = new ResourceLocation(reg.getNamespace(), "textures/blocks/" + reg.getPath() + "_base.png.mcmeta");
  ResourceLocation textures_blocks_top_mcmeta = new ResourceLocation(reg.getNamespace(), "textures/blocks/" + reg.getPath() + "_top.png.mcmeta");
  {
     String n = reg.getPath().startsWith("custom_solar_panel_") ? reg.getPath().substring(19) : reg.getPath().substring(12);
     resourceMap.put(textures_blocks_base, ofFile(() -> new File(new File(SolarsSF.getConfigDir(), "textures"), n + "_base.png")));
     resourceMap.put(textures_blocks_base_mcmeta, ofFile(() -> new File(new File(SolarsSF.getConfigDir(), "textures"), n + "_base.mcmeta")));
     resourceMap.put(textures_blocks_top, ofFile(() -> new File(new File(SolarsSF.getConfigDir(), "textures"), n + "_top.png")));
     resourceMap.put(textures_blocks_top_mcmeta, ofFile(() -> new File(new File(SolarsSF.getConfigDir(), "textures"), n + "_top.mcmeta")));
  }
}

红色字体与绿色字体比较可以发现,在复写材质mcmeta文件的时候,识别玩家自定义材质mcmeta文件的时候名字并不是按常规的名字识别的,

常规材质与mcmeta文件的命名是:example_top.png对应 example_top.png.mcmeta;example_base.png对应 example_base.png.mcmeta。

这里要复写材质文件名称,在提取mcmeta文件名字的时候变成了 example_top.mcmeta; example_base.mcmeta。

所以如果想给材质加上mcmeta文件的话 只需要mcmeta文件名字跟材质图片名字一样就可以了,并不需要加速图片类型(.png)。

我想作者的本意是为了帮助小白在不知道命名规则的情况下,直接将材质图片跟mcmeta文件命名相同的名字,就能起作用。这一点反而误导了那些有对命名规则有一定了解的人。

粗鄙之见,希望能够帮助到您。