ferag 发表于 2025-2-7 12:13:27

开发我的世界1.20.1forge模组时出错

我就写了几个物品,用DataGenerators给模组生成模型文件,然后运行rundata命令时就出现错误,提示找不到资源文件,其实资源文件在相关的目录下,代码也没有错误,但是就是出现这种错误,求助各位大佬。源代码放出来了,有没有人知道是什么问题?数据生成器代码:package com.example.mymod;

import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID,bus=Mod.EventBusSubscriber.Bus.MOD)
public class DataGenerators {

    //这个注释表明这个方法要被模组事件总线所监视,这个方法是事件触发时的回调
    @SubscribeEvent
    public static void gatherData(GatherDataEvent event){
      //创建一堆东西,照着写就行,以后有机会会介绍
      DataGenerator generator=event.getGenerator();
      PackOutput output=generator.getPackOutput();
      event.getLookupProvider();
      ExistingFileHelper helper=event.getExistingFileHelper();


      //添加生成对应文件的生成器
      //第一个参数表示在客户端还是服务端,这里我们选择客户端,第二个传进一个生成的对象,就是我们之前自己写的类
      generator.addProvider(event.includeClient(),new ModItemModelGen(output,helper));
      //en_us表示英文名称的文件,还可以根据需求设置多种语言
      generator.addProvider(event.includeClient(),new ModLangGen(output,"en_US"));
      //添加生成方块json文件的类
      generator.addProvider(event.includeClient(),new ModBlockModelGen(output,helper));

    }
}
物品模型生成器代码:package com.example.mymod;

import net.minecraft.data.PackOutput;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;

public class ModItemModelGen extends ItemModelProvider {

    //构造函数
    public ModItemModelGen(PackOutput output, ExistingFileHelper existingFileHelper) {
      //第二个参数要填自己的modid
      super(output, ExampleMod.MOD_ID, existingFileHelper);
    }

    //重写该方法,在这个方法里面填写要生成数据的物品
    @Override
    protected void registerModels() {
      // 武器模型(使用原版手持模型)
      withExistingParent("test_weapon", mcLoc("item/handheld"))
                .texture("layer0", "mymod:item/test_weapon");

      // 普通物品(使用原版生成模型)
      basicItem(ModItems.CUSTOM_FOOD.getId());
      basicItem(ModItems.TEST_POTION.getId());
    }
}
报错:Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:32)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:108)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:78)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)         at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) Caused by: java.lang.reflect.InvocationTargetException         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) Caused by: java.lang.reflect.InvocationTargetException        at java.base/java.lang.reflect.Method.invoke(Method.java:569)         at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.CommonLaunchHandler.runTarget(CommonLaunchHandler.java:111)         at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.CommonLaunchHandler.dataService(CommonLaunchHandler.java:107)         at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.ForgeDataUserdevLaunchHandler.devService(ForgeDataUserdevLaunchHandler.java:22)         at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.CommonDevLaunchHandler.lambda$makeService$7(CommonDevLaunchHandler.java:135)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30)         ... 7 more Caused by: java.lang.IllegalArgumentException: Texture mymod:item/test_weapon does not exist in any known resource pack Caused by: java.lang.IllegalArgumentException: Texture mymod:item/test_weapon does not exist in any known resource pack        at MC-BOOTSTRAP/[email protected]/com.google.common.base.Preconditions.checkArgument(Preconditions.java:220)         at TRANSFORMER/[email protected]/net.minecraftforge.client.model.generators.ModelBuilder.texture(ModelBuilder.java:145)         at TRANSFORMER/[email protected]/net.minecraftforge.client.model.generators.ModelBuilder.texture(ModelBuilder.java:126)         at TRANSFORMER/[email protected]/com.example.mymod.ModItemModelGen.registerModels(ModItemModelGen.java:20)         at TRANSFORMER/[email protected]/net.minecraftforge.client.model.generators.ModelProvider.run(ModelProvider.java:396)         at TRANSFORMER/[email protected]/net.minecraft.data.HashCache.generateUpdate(HashCache.java:92)         at TRANSFORMER/[email protected]/net.minecraft.data.DataGenerator.lambda$run$0(DataGenerator.java:44)         at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)         at TRANSFORMER/[email protected]/net.minecraft.data.DataGenerator.run(DataGenerator.java:37)         at TRANSFORMER/[email protected]/net.minecraftforge.data.event.GatherDataEvent$DataGeneratorConfig.lambda$runAll$2(GatherDataEvent.java:111)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.api.LamdbaExceptionUtils.lambda$rethrowConsumer$0(LamdbaExceptionUtils.java:34)         at java.base/java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:647)         at TRANSFORMER/[email protected]/net.minecraftforge.data.event.GatherDataEvent$DataGeneratorConfig.runAll(GatherDataEvent.java:107)         at TRANSFORMER/[email protected]/net.minecraftforge.data.loading.DatagenModLoader.begin(DatagenModLoader.java:54)         at TRANSFORMER/[email protected]/net.minecraft.data.Main.main(Main.java:90)         ... 16 more> Task :runData FAILEDExecution failed for task ':runData'. > Process 'command 'D:\zulu17.56.15-ca-jdk17.0.14-win_x64\bin\java.exe'' finished with non-zero exit value 1* Try: > Run with --stacktrace option to get the stack trace. > Run with --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD FAILED in 11s 10 actionable tasks: 3 executed, 7 up-to-date Watched directory hierarchies:
Caused by: java.lang.IllegalArgumentException: Texture mymod:item/test_weapon does not exist in any known resource pack
可以清楚的看到,相关的纹理文件确实在相关目录下,这时候提示找不到纹理文件,这是什么原因?

ABlueCat 发表于 2025-2-7 23:46:27

关于这个问题,我貌似之前有个解决方案,不过最近帖子存档服务器关了,等好了之后我发一下。

ferag 发表于 2025-2-8 19:56:14

ABlueCat 发表于 2025-2-7 23:46
关于这个问题,我貌似之前有个解决方案,不过最近帖子存档服务器关了,等好了之后我发一下。 ...

我感觉这个东西挺玄,有时候清理一下idea缓存,把build.gradle改成最开始的代码问题就解决了,说明问题在缓存和build.gradle身上

ABlueCat 发表于 2025-2-9 17:31:01

ferag 发表于 2025-2-8 19:56
我感觉这个东西挺玄,有时候清理一下idea缓存,把build.gradle改成最开始的代码问题就解决了,说明问题在 ...

找到了,你看看:
https://archives.mcbbs.co/read.php?tid=1173660
页: [1]
查看完整版本: 开发我的世界1.20.1forge模组时出错