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

Execution failed for task ':compileJava'. - Issue 3 in this series

在这个问题因为已经被问到而关闭之前,据我所知这是一个模糊且常见的错误,因此这与其他问题不同。

我修复了之前 by installing a slightly different version of Forge, but have now reached Step 5 of this tutorial 中的错误。当我将 .\gradlew build 与示例 mod 一起使用时,一切似乎都运行良好(尽管我找不到控制台输出)但是当我将 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 构建时,我得到:

#################################################
         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 了解不多(我才刚刚开始学习),但我认为逐个字符地复制教程应该会产生无错误的程序。显然不是。

查看编译器上的错误输出,第一个错误是 'The import net cannot be resolved'(第 3 行)我不知道为什么。

非常感谢任何帮助, 本

(来自评论)

导入错误。你应该使用 net.minecraft.* 而不是 net.minecraft.init.* :

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;