Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.6.4] Properly registering mobs (LivingEntityBase-derived entities)
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Akjosch

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

By Akjosch, October 28, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Akjosch    4

Akjosch

Akjosch    4

  • Tree Puncher
  • Akjosch
  • Members
  • 4
  • 17 posts
Posted October 28, 2013

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?

  • Quote

ItemBlock is not a Block

ItemStack is not an Item

Damage value is not metadata

 

Stop confusing them.

Share this post


Link to post
Share on other sites

GotoLink    381

GotoLink

GotoLink    381

  • World Shaper
  • GotoLink
  • Members
  • 381
  • 2012 posts
Posted October 28, 2013

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

  • Quote

Share this post


Link to post
Share on other sites

Akjosch    4

Akjosch

Akjosch    4

  • Tree Puncher
  • Akjosch
  • Members
  • 4
  • 17 posts
Posted October 29, 2013

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)

  • Quote

ItemBlock is not a Block

ItemStack is not an Item

Damage value is not metadata

 

Stop confusing them.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • kmann383
      Forge 35.1.37 crashes when i hit escape key

      By kmann383 · Posted 3 minutes ago

      Hola. My forge crashes whenever i hit escape to go to the options menu please help.crash-2021-01-15_09.41.53-client.txt
    • avbavey
      Can’t download forge on Mac?

      By avbavey · Posted 32 minutes ago

      I tried downloading the launcher from the website, then I go to Finder and locate it and double click it. Then it shows a pop up that says “the java JAR file (name of the file) could bot be launched.” How do I open it?? Also, this sounds weird but the Mac keyboard stopped working so I have to use a Windows keyboard with the Mac computer. Please help ASAP!
    • Shrayzz
      Forge 1.4.7 : Problèmes d'installation

      By Shrayzz · Posted 41 minutes ago

      Bonjour, j'aimerais me faire une partie en 1.4.7 moddé car certains mods ne sont disponibles que sur cette version. Récemment, j'ai acheté un nouveau pc l'ancien ne marchait plus. Le problème, c'est qu'étant donné que le fichier "minecraft.jar" du dossier "bin" de ".minecraft" n'existe plus. Le type d'installation de forge n'est plus le même qu'avant, je suis donc allé voir sur des forums pour savoir comment je pourrais faire mais tous sont obsolètes. Pourriez-vous m'aider à installer cette version, je voulais savoir si on pouvait toujours en faire des serveurs avec cette version? Merci de votre réponse.
    • PedreHenrry
      my minecraft crashed by "rendering overlay"

      By PedreHenrry · Posted 45 minutes ago

      tomorrow i do this  
    • ChampionAsh5357
      How to register WallOrFloorItem / Torch

      By ChampionAsh5357 · Posted 1 hour ago

      Nope, you're just registering the item twice. Your block calls this method which creates an item to which you then create another item under the same name.
  • Topics

    • kmann383
      0
      Forge 35.1.37 crashes when i hit escape key

      By kmann383
      Started 3 minutes ago

    • avbavey
      0
      Can’t download forge on Mac?

      By avbavey
      Started 32 minutes ago

    • Shrayzz
      0
      Forge 1.4.7 : Problèmes d'installation

      By Shrayzz
      Started 41 minutes ago

    • PedreHenrry
      4
      my minecraft crashed by "rendering overlay"

      By PedreHenrry
      Started 4 hours ago

    • StealthyNoodle
      5
      How to register WallOrFloorItem / Torch

      By StealthyNoodle
      Started 14 hours ago

  • Who's Online (See full list)

    • Abdymazhit
    • Buecher_wurm
    • Sr_endi
    • Pl00py_R
    • kmann383
    • Shrayzz
    • StealthyNoodle
    • glimmermaxcool
    • GabrielIsDa1
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.6.4] Properly registering mobs (LivingEntityBase-derived entities)
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community