执行任务';失败:编译Java';。-本系列第三期
在此问题因已被提出而关闭之前,据我所知,这是一个模糊且常见的错误,因此此问题与其他问题不同。
我通过安装略微不同的Forge版本修复了以前post中的错误,但现在已达到this tutorial的第5步。当我将.gradlew构建与示例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:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:21: error: cannot find symbol
private class ModBlock extends Block
^
symbol: class Block
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:23: error: cannot find symbol
public ModBlock(Material material, String blockName)
^
symbol: class Material
location: class ExampleMod.ModBlock
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:17: error: cannot find symbol
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
^
symbol: class Block
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:17: error: cannot find symbol
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
^
symbol: variable Material
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:18: error: cannot find symbol
GameRegistry.registerBlock(amethystOre, "amethystOre");
^
symbol: variable GameRegistry
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:26: error: cannot find symbol
this.setBlockName(blockName);
^
symbol: method setBlockName(String)
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:27: error: cannot find symbol
this.setBlockTextureName(MODID + ":" + blockName);
^
symbol: method setBlockTextureName(String)
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.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行),但我不知道原因。
任何帮助都非常感谢, 本
解决方案
(来自评论)
导入错误。您应该使用net.minecraft.*
而不是net.minecraft.init.*
:
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
相关文章