任务':compileJava'的执行失败。 -本系列第3期

时间:2019-10-27 15:15:50

标签: java gradle minecraft minecraft-forge

据我所知,这是一个模糊且常见的错误,因此已经不同于其他问题。

我通过安装稍有不同的Forge版本修复了先前的post中的错误,但现在已达到this tutorial的第5步。当我在示例mod中使用。\ gradlew构建时,一切似乎都可以正常工作(尽管我找不到控制台输出),但是当我按照作者的描述编辑mod时,会出现很多错误。

示例mod:

package com.example.examplemod;

import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;

@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
    public static final String MODID = "examplemod";
    public static final String VERSION = "1.0";

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        // some example code
        System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName());
    }
}

如何按照教程进行更改:

package com.example.examplemod;

import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;

@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
    public static final String MODID = "examplemod";
    public static final String VERSION = "1.1";

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        Block amethystOre = new ModBlock(Material.rock, "amethystOre");
        GameRegistry.registerBlock(amethystOre, "amethystOre");
    }

    private class ModBlock extends Block
    {
        public ModBlock(Material material, String blockName)
        {
            super(material);
            this.setBlockName(blockName);
            this.setBlockTextureName(MODID + ":" + blockName);
            this.setCreativeTab(CreativeTabs.tabBlock);
        }
    }

}

运行。\ gradlew build时,我得到:

#################################################
         ForgeGradle 1.2-SNAPSHOT-fb514d3
  https://github.com/MinecraftForge/ForgeGradle
#################################################
               Powered by MCP unknown
             http://modcoderpack.com
         by: Searge, ProfMobius, Fesh0r,
         R4wk, ZeuX, IngisKahn, bspkrs
#################################################
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava UP-TO-DATE
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:21: error: cannot find symbol
    private class ModBlock extends Block
                                   ^
  symbol:   class Block
  location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:23: error: cannot find symbol
        public ModBlock(Material material, String blockName)
                        ^
  symbol:   class Material
  location: class ExampleMod.ModBlock
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:17: error: cannot find symbol
        Block amethystOre = new ModBlock(Material.rock, "amethystOre");
        ^
  symbol:   class Block
  location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:17: error: cannot find symbol
        Block amethystOre = new ModBlock(Material.rock, "amethystOre");
                                         ^
  symbol:   variable Material
  location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:18: error: cannot find symbol
        GameRegistry.registerBlock(amethystOre, "amethystOre");
        ^
  symbol:   variable GameRegistry
  location: class ExampleMod
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:26: error: cannot find symbol
            this.setBlockName(blockName);
                ^
  symbol: method setBlockName(String)
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:27: error: cannot find symbol
            this.setBlockTextureName(MODID + ":" + blockName);
                ^
  symbol: method setBlockTextureName(String)
C:\Users\benji\MinecraftWorkspace\forge-1.7.10-10.13.4.1558-1.7.10-src\build\sources\java\com\example\examplemod\ExampleMod.java:28: error: cannot find symbol
            this.setCreativeTab(CreativeTabs.tabBlock);
                                ^
  symbol:   variable CreativeTabs
  location: class ExampleMod.ModBlock
8 errors
1 warning
:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

我对Java并不了解很多(我刚刚开始学习它),但是我认为复制教程字符转换应该会导致程序无错误。显然不是。

看看编译器上的错误输出,第一个错误是“无法解决导入网络”(第3行),我不知道为什么。

非常感谢您的帮助, 本

0 个答案:

没有答案