Jump to content

[1.6.4] Properly registering mobs (LivingEntityBase-derived entities)


Recommended Posts

Posted

Right now, I'm registering mobs with the game as follows. In the mod's initialisation routine:

 

    // We'll need that later.
    Map<Class, Integer> classToIDMapping = ObfuscationReflectionHelper.getPrivateValue(EntityList.class, new EntityList(), "classToIDMapping");

    // For every mob, repeat the following
    // Registering the mob with FML (this also fills EntityList's stringToClassMapping and classToStringMapping)
    EntityRegistry.registerModEntity(EntityMyMob.class, mobUntranslatedName, mobInternalID, this, trackingRange, updateFrequency, true);

    // Add a readable name for the default language (en_US) - this can also be done via a "lang" resource, I guess
    LanguageRegistry.instance().addStringLocalization("entity." + modID + "." + mobUntranslatedName + ".name", "en_US", mobName);

    // Find some unique and not used GLOBAL id (via checks for EntityList.getStringFromID(...) being null)
    Integer id = Integer.valueOf(getUniqueEntityId());

    // Register the egg
    EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor));

    // This is so that the egg can spawn the mob
    EntityList.IDtoClassMapping.put(id, EntityMyMob.class);

    // And this is so that middle click on the mob gets us the egg in creative mode (and why we needed the reflection above)
    classToIDMapping.put(EntityMyMob.class, id);

 

And, of course, in the client-side proxy:

 

    RenderingRegistry.registerEntityRenderingHandler(EntityMyMob.class, new RenderMyMob());

Is this the "right way"? If no, how are we supposed to do that (the internet is full of tutorials, all of them different ...)? If yes, why so complicated?

ItemBlock is not a Block

ItemStack is not an Item

Damage value is not metadata

 

Stop confusing them.

Posted

No, all this is not needed.

 

This is the only line you need to register an entity.

    EntityRegistry.registerModEntity(EntityMyMob.class, mobUntranslatedName, mobInternalID, this, trackingRange, updateFrequency, true);

Note:

If you absolutely want the "vanilla" spawn egg (meaning you can cope with its flaws), do instead

EntityRegistry.registerGlobalEntityID(EntityMyMob.class, mobUntranslatedName, id, backgroundEggColour, foregroundEggColour);

 

This is the only line you need to register a renderer.

RenderingRegistry.registerEntityRenderingHandler(EntityMyMob.class, new RenderMyMob());

Posted

The "problem" with EntityRegistry.registerGlobalEntityID() is that it doesn't fill up a couple of FML maps, which means (from what I understood of the code) you can't use FML's custom mod spawning and tracking.

 

As a workaround, would the following fill them up properly? Looking at the code for 1.6.4, it seems it might just work, but I'm not sure were the FML or the Forge team want to take those ...

 

    EntityRegistry.registerGlobalEntityID(EntityMyMob.class, modID + "." + mobUntranslatedName, id, backgroundEggColour, foregroundEggColour);
    EntityRegistry.registerModEntity(EntityMyMob.class, mobUntranslatedName, mobInternalID, this, trackingRange, updateFrequency, true);

 

(+ the renderer code obviously)

ItemBlock is not a Block

ItemStack is not an Item

Damage value is not metadata

 

Stop confusing them.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.