我正在尝试在Eclipse中创建我的第一个块,但只要我尝试运行它,启动器就会崩溃。我不确定我做错了什么。我已经创建了一个新的块实例,注册了它,给了构造函数所有必要的字段,三重检查了运行方法,我仍然没有发现问题。我正在运行Minecraft 1.7.10。
以下是课程:
创建一个BasicBlock
对象并注册它:
package com.mrcrayfish.tutorial.blocks;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
public final class ModBlocks {
public static Block tutorialBlock;
public static final void init() {
tutorialBlock = new BasicBlock("tutorialBlock", Material.wood);
GameRegistry.registerBlock(tutorialBlock, "tutorialBlock");
}
}
BasicBlock类:
package com.mrcrayfish.tutorial.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import com.mrcrayfish.tutorial.Reference;
public class BasicBlock extends Block {
public BasicBlock(String unlocalizedName, Material material) {
super(material);
this.setBlockName(unlocalizedName);
this.setBlockTextureName(Reference.MOD_ID + ":" + unlocalizedName);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setHardness(2.0F);
this.setResistance(6.0F);
this.setLightLevel(20.0F);
this.setHarvestLevel("shovel", 3);
this.setStepSound(soundTypeMetal);
}
}
使用运行时方法的代理:
package com.mrcrayfish.tutorial.proxy;
import cpw.mods.fml.common.event.*;
import com.mrcrayfish.tutorial.blocks.ModBlocks;
import com.mrcrayfish.tutorial.init.ModItems;
public class CommonProxy {
public void preInit(FMLPreInitializationEvent e) {
ModItems.init();
ModItems.register();
ModBlocks.init();
}
public void init(FMLInitializationEvent e) {
}
public void postInit(FMLPostInitializationEvent e) {
}
}
主运行时类:
package com.mrcrayfish.tutorial;
import com.mrcrayfish.tutorial.init.ModItems;
import com.mrcrayfish.tutorial.proxy.CommonProxy;
import com.mrcrayfish.tutorial.blocks.ModBlocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.Mod.EventHandler;
@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Tutorial {
@Instance
public static Tutorial instance;
@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
ModItems.init();
ModItems.register();
ModBlocks.init();
proxy.preInit(event);
}
@EventHandler
public void init(FMLInitializationEvent event) {
System.out.println("init");
proxy.init(event);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
System.out.println("postinit");
proxy.postInit(event);
}
}
带有最终变量/枚举的引用类:
package com.mrcrayfish.tutorial;
import net.minecraft.block.material.Material;
public class Reference {
public static final String MOD_ID = "ctm";
public static final String NAME = "MrCrayfish's Tutorial Mod";
public static final String VERSION = "1.0";
public static final String CLIENT_PROXY_CLASS = "com.mrcrayfish.tutorial.proxy.ClientProxy";
public static final String SERVER_PROXY_CLASS = "com.mrcrayfish.tutorial.proxy.ServerProxy";
public enum TutorialItems {
CHEESE("cheese", "ItemCheese");
public String unlocalizedName;
public String registryName;
TutorialItems(String unlocalizedName, String registryName) {
this.unlocalizedName = unlocalizedName;
this.registryName = registryName;
}
public String getUnlocalizedName() {
return unlocalizedName;
}
public String getRegistryName() {
return registryName;
}
}
public enum EBlock {
TUTORIALBLOCK("tutorialBlock", Material.wood);
String BlockName;
Material material;
EBlock(String BlockName, Material material) {
this.BlockName = BlockName;
this.material = material;
}
}
}
ClientProxy类:
package com.mrcrayfish.tutorial.proxy;
import cpw.mods.fml.common.event.*;
public class ClientProxy extends CommonProxy
{
public void preInit(FMLPreInitializationEvent h)
{
super.preInit(h);
}
public void init(FMLInitializationEvent h)
{
super.init(h);
}
public void postInit(FMLPostInitializationEvent h)
{
super.postInit(h);
}
}
ServerProxy类:
package com.mrcrayfish.tutorial.proxy;
import cpw.mods.fml.common.event.*;
public class ServerProxy extends CommonProxy
{
public void preInit(FMLPreInitializationEvent h)
{
super.preInit(h);
}
public void init(FMLInitializationEvent h)
{
super.init(h);
}
public void postInit(FMLPostInitializationEvent h)
{
super.postInit(h);
}
}
我可以从调试报告中得到的最多信息是“Tutorial.java”中的“preInit”方法存在问题。这是崩溃报告:
at cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry.add(FMLControlledNamespacedRegistry.java:410)
at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:849)
at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:812)
at cpw.mods.fml.common.registry.GameRegistry.registerItem(GameRegistry.java:149)
at cpw.mods.fml.common.registry.GameRegistry.registerItem(GameRegistry.java:137)
at com.mrcrayfish.tutorial.init.ModItems.register(ModItems.java:23)
at com.mrcrayfish.tutorial.proxy.CommonProxy.preInit(CommonProxy.java:10)
at com.mrcrayfish.tutorial.proxy.ClientProxy.preInit(ClientProxy.java:8)
at com.mrcrayfish.tutorial.Tutorial.preInit(Tutorial.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:556)
at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:522)
at net.minecraft.client.Minecraft.run(Minecraft.java:942)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)
通过浏览eclipse的控制台输出后,我想我可以缩小这个问题的范围:
[09:12:27] [客户端主题/信息] [MinecraftForge]:尝试早期的MinecraftForge初始化
[09:12:27] [客户线程/信息] [FML]:MinecraftForge v10.13.4.1558初始化
[09:12:27] [客户线程/信息] [FML]:取代了183个矿石收件人
[09:12:27] [客户端主题/信息] [MinecraftForge]:早期完成MinecraftForge初始化
[09:12:28] [客户端线程/信息] [FML]:从命令行找到0个mod。注入mod发现者
[09:12:28] [客户端主题/信息] [FML]:搜索C:\ Users \ Chris \ Desktop \ Forge \ eclipse \ mods for mods
[09:12:44] [客户线程/信息] [FML]:Forge Mod Loader已识别出4个mod加载
[09:12:45] [客户线程/信息] [FML]:在CLIENT尝试连接缺少的mod [mcp,FML,Forge,ctm]
[09:12:45] [客户端主题/信息] [FML]:在SERVER上尝试连接缺少的mod [mcp,FML,Forge,ctm]
似乎是我创建的代理类的问题。
答案 0 :(得分:0)
当发生preInit事件时,您运行以下行
ModItems.init();
ModItems.register();
ModBlocks.init();
然后运行Proxies preInit Methode 因为客户端代理和ServerProxy只需调用super.preInit 两者都调用了CommonProxy的preInit Methode,它也是
ModItems.init();
ModItems.register();
ModBlocks.init();
这意味着您正在尝试注册可能导致错误的所有内容。