我正在尝试制作一个Minecraft模组,该模组应该会让蝙蝠掉下生鸡肉。 Minecraft确实会启动并实际打开,但是进入compileJava阶段时,控制台中会显示错误。我对Java的了解很少,所以我不知道如何总结它。
我的问题是这些错误消息是什么意思,我该如何纠正它们?
我已经问过一些同事有关此问题的信息,但他们都不知道。
//NOTE TO SELF: Learn to indent.
package net.mcreator.trevcorp_meat_paste;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraft.world.World;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.passive.EntityBat;
public static class GUIRenderEventClass
{@SubscribeEvent
public void playerKilledBat(livingDropsEvent event)
{
if(event.entityLiving instanceof EntityBat)
{
event.drops.clear();
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
event.entity.posY, event.entity.posZ, itemStackToDrop));
}
}
}
Minecraft实际上确实会打开,但是进入compileJava阶段时,它将在控制台中显示以下错误消息:
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:16: error: class GUIRenderEventClass is public, should be declared in a file named GUIRenderEventClass.java
public static class GUIRenderEventClass
^
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:18: error: cannot find symbol
public void playerKilledBat(livingDropsEvent event)
^
symbol: class livingDropsEvent
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: class itemStack
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: class itemStack
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: variable items
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:25: error: cannot find symbol
event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
^
symbol: class EntityItem
location: class GUIRenderEventClass
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
答案 0 :(得分:0)
第一条错误消息
class GUIRenderEventClass is public, should be declared in a file named GUIRenderEventClass.java public static class GUIRenderEventClass
表示您的Java源代码位于名称与源代码中的Java类名称不匹配的文件中。文件中的类的Java源文件名和Java类名都必须匹配。它是Java编译器如何查找内容的方法。
您还会遇到许多相同类型的错误,例如:
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:18: error: cannot find symbol public void playerKilledBat(livingDropsEvent event)
这意味着Java编译器在处理源代码时会发现它不知道的符号或类型或名称。这是一个错误,表示在Java编译器搜索时找不到所指示的符号或类型或名称。
发生这种情况的原因有很多。
最常见的情况是缺少包含符号,类型或名称的文件的import
指令。这是涉及类型的“找不到符号”错误的最可能原因。看来您有几种“找不到符号”的情况,可能是由于缺少import
文件引起的,例如:
class livingDropsEvent
是找不到的符号class itemStack
是找不到的符号class EntityItem
是找不到的符号也找不到变量items
。我假设它也是import
文件中某个位置的全局变量。
有关这些符号的一些详细信息,请参见Jabelar的《 Minecraft Forge Modding教程》 Minecraft Forge 1.7.2/1.7.10 Changing Drops of Vanilla Entities和Minecraft Modding: Event Handling上的这篇文章。
还要查看此mincraftforge论坛https://www.minecraftforge.net/forum/topic/28747-how-to-add-a-drop-to-a-vanilla-mob-1710/中的示例代码,其中包含以下import
指令集:
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
最后您有一些警告:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
这些警告可能重要,也可能不重要。如果它们来自某个库中正在使用的某个源,则可能无法解决这些问题。无论这些警告如何,您的应用程序都可以运行。