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

    • Klarks
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks · Posted 13 minutes ago

      To get my itemhandler.i need to get default living entity slots and my custom slots
    • diesieben07
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By diesieben07 · Posted 17 minutes ago

      That's an infinite loop. Why are you overriding getCapability at all?
    • Klarks
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks · Posted 24 minutes ago

      Like this public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return getCapability(cap,side).cast(); } return super.getCapability(cap, side); }
    • diesieben07
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By diesieben07 · Posted 28 minutes ago

      Call getCapability.
    • Klarks
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks · Posted 44 minutes ago

      I dont understand how i can get them from my class
  • Topics

    • Klarks
      12
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks
      Started 5 hours ago

    • Fars3O_
      1
      Minecraft forge not fully loading

      By Fars3O_
      Started 5 hours ago

    • BastouP
      3
      [1.16.4] Get Overworld save directory

      By BastouP
      Started 14 hours ago

    • Woodside
      15
      [1.15.2] Render as 2D icon in GUI, 3D model in hand

      By Woodside
      Started Sunday at 08:26 PM

    • CatSack
      1
      Forge unable to find model

      By CatSack
      Started 13 hours ago

  • Who's Online (See full list)

    • diesieben07
    • Klarks
    • FreshMod
    • WildHeart
  • 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