问题
Before this question gets closed for already being asked, as far as I can see it is a vague and common error so this is different from other questions.
I fixed the error in my previous post by installing a slightly different version of Forge, but have now reached Step 5 of this tutorial. When I use .\gradlew build with the example mod, everything seems to work fine (although I cannot find the console output) But when I edit the mod to how the author describes, I get many errors.
The example 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());
}
}
How I changed it, following the tutorial:
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);
}
}
}
When I run .\gradlew build, I get:
#################################################
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.
I don't know a whole lot about Java (I just started learning it) but I would assume that copying the tutorial character-for-character should result in an error-free program. Apparently not.
Looking at the error output on the compiler, the first error is 'The import net cannot be resolved' (line 3) I don't know why though.
Any help is much appreciated, Ben
来源:https://stackoverflow.com/questions/58580656/execution-failed-for-task-compilejava-issue-3-in-this-series