Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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.

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());

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.