1
\$\begingroup\$

I'm trying to make a Minecraft Forge mod. I've done this before, but I've never worked with entities. So I was trying to add an entity to the EntityRegistry, but I can't seem to reference the mod file as an object using this. It tells me that it expect Object mod, not TestMobs. What am i doing wrong?

Here is my code:

package com.scriptcoded.testmobs;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;

@Mod(modid = Tutorial.MODID, version = Tutorial.VERSION)
public class TestMobs
{
    public static final String MODID = "testmobs";
    public static final String VERSION = "1.0";

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        EntityRegistry.registerModEntity(EntityTutorial.class, "Test mob", 1, this, 80, 3, true);
    }
}

The problem is in the line EntityRegistry.registerModEntity(EntityTutorial.class, "Test mob", 1, this, 80, 3, true);.

Any ideas? Thanks for any help!

\$\endgroup\$
  • \$\begingroup\$ The Forge Forums will likely get you better help. If I had done any modding with 1.8 myself, I might have known the problem. \$\endgroup\$ – Draco18s Dec 10 '15 at 15:07
  • \$\begingroup\$ @Draco18s ok, thanks. Didn't think about that ;) \$\endgroup\$ – Script_Coded Dec 10 '15 at 16:20
  • \$\begingroup\$ I guess you need that your TestMobs class extends some other class in order to work. \$\endgroup\$ – Xriuk Jan 7 '16 at 19:08
1
\$\begingroup\$

For 1.7.10 (and I'm assuming 1.8 too), you need to add an instance of the main class into itself. Just after initialising the VERSION, you should put:

@Instance(TestMobs.MODID)
public static TestMobs instance;

Then when you reference your mod reference it through:

TestMobs.instance

The only other suggestion I can give is to register it in the preInit or postInit (or the client/common proxy)

\$\endgroup\$
  • \$\begingroup\$ This exact question came up Forge Forums recentish. I can't find it now, but it has something to do with the way the mod loader code functions. \$\endgroup\$ – Draco18s Jan 7 '16 at 18:03
  • \$\begingroup\$ @Draco18s I've had similar issues in the past where adding an instance has pretty much fixed it. Ive added another thing that could possibly cause it to the end. \$\endgroup\$ – Ashigaru Jan 7 '16 at 18:09
0
\$\begingroup\$

I know this is an OLD TOPIC, but I just could not help noticing:

In the line reading: @Mod(modid = you have the following: @Mod(modid = Tutorial.MODID, version = Tutorial.VERSION)

Do you actually HAVE a class file named "Tutorial.java", that defines both the "MODID" and "VERSION" strings?

Because, you ALSO have defined a "MODID" string var. and a "VERSION" string var. right BELOW that line, in the TestMobs class definition ITSELF! So, you have basically told Forge to "look" in a class file named "Tutorial", for the strings "MODID" and "VERSION" (resulting in "Tutorial.MODID" and "Tutorial.VERSION"; you MUST therefore HAVE that classfile in your project!

It makes absolutely no difference to Forge if you define yet another string "MODID" and a string "VERSION" anywhere else; it won't know to use THOSE strings for anything!

I mean, that's just what I noticed at a quick glance through your code...

ZTagre.

\$\endgroup\$
  • \$\begingroup\$ Yes, it was indeed quite some time ago ;) But no, I don't believe I actually had a Tutorial.class file. I'm assuming it might have added to my problem, but I'd like to say that that project is put on the shelf for now. Thank's for looking back at it anyways. \$\endgroup\$ – Script_Coded Jul 24 '17 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.