Jump to content
  • Home
  • Files
  • Docs
  • Merch
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.12] Registering entities
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
Kokkie

[1.12] Registering entities

By Kokkie, October 6, 2017 in Modder Support

  • Reply to this topic
  • Start new topic
  • Prev
  • 1
  • 2
  • Next
  • Page 1 of 2  

Recommended Posts

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 6, 2017

Hello,

I was just wondering what the best way to register an entity would be.

Thanks.

  • Quote

Share this post


Link to post
Share on other sites

aw_wolfe    14

aw_wolfe

aw_wolfe    14

  • Stone Miner
  • aw_wolfe
  • Members
  • 14
  • 94 posts
Posted October 6, 2017

directly with.

ForgeRegistries.ENTITIES.register([EntityEntry]);

 

or better, trap the event (per docs)

@SubscribeEvent
public void registerBlocks(RegistryEvent.Register<EntityEntry> event) {
    event.getRegistry().register([EntityEntry]);
}

 

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 6, 2017

Ah, it was EntityEntry instead of raw Entity, thanks!

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017

Just tried it, it crashes.

The log:

[14:33:39] [main/WARN] [FML/]: Registry EntityEntry: Override did not have an associated owner object. Name: dgm:cheese_boss Value: net.minecraftforge.fml.common.registry.EntityEntry@79ed43f8

My code:

public class Entities {
	public static final EntityEntry CHEESE_BOSS = new EntityEntry(CheeseBossEntity.class, Reference.MOD_ID + ":cheese_boss");
	public static final EntityEntry[] ENTITIES = new EntityEntry[] { CHEESE_BOSS };
	static {
		CHEESE_BOSS.setRegistryName(Reference.MOD_ID, "cheese_boss");
		CHEESE_BOSS.setEgg(new EntityEggInfo(new ResourceLocation(Reference.MOD_ID, "cheese_boss"), 0xFFFFFF, 0xAAAAAA));
	}
}
@Mod.EventBusSubscriber
public class CommonHandler {
	@SubscribeEvent
	public static void registerBlocks(RegistryEvent.Register<Block> e) {
		DeGeweldigeMod.LOGGER.info("Registering Blocks.");
		e.getRegistry().registerAll(Blocks.BLOCKS);
	}

	@SubscribeEvent
	public static void registerItems(RegistryEvent.Register<Item> e) {
		DeGeweldigeMod.LOGGER.info("Registering Items.");
		e.getRegistry().registerAll(Items.ITEMS);
		for (Block block : Blocks.BLOCKS) {
			e.getRegistry().register(new ItemBlock(block).setRegistryName(block.getRegistryName()).setUnlocalizedName(block.getUnlocalizedName()));
		}
	}

	@SubscribeEvent
	public static void registerEntities(RegistryEvent.Register<EntityEntry> e) {
		DeGeweldigeMod.LOGGER.info("Registering Entities.");
		e.getRegistry().registerAll(Entities.ENTITIES);
	}
}

Tell me if you need more code/stuff.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted October 7, 2017

Use this: https://github.com/MinecraftForge/MinecraftForge/commit/f2b07e8db1e2a6cf3a5b47393783bb367f2afdb2

Don't create EntityEntry instances in a static initializer.

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017

How can I get the ModContainer?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted October 7, 2017

What?

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017

Correct me if I'm wrong but I'm creating an EntityRegistration and it takes a ModContainer as parameter, I need to know how I can get the ModContainer of my mod...

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted October 7, 2017

No, you use the builder.

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017

But I couldn't find that class.. Let me try updating...

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017 (edited)

All is fine now, only the methods return a EntityEntryBuilder<Entity> instead of one using my Entity, how can I fix this?

Code so far:

public static final EntityEntryBuilder<CheeseBossEntity> CHEESE_BOSS = EntityEntryBuilder.create().entity(CheeseBossEntity.class).id(new ResourceLocation(Reference.MOD_ID), ID++).name("cheese_boss").egg(0xFFFFFF, 0xAAAAAA).tracker(64, 20, false);

Tell me if something is wrong in this as well.

Forgot to add tracker, fixed now

Edited October 7, 2017 by Kokkie
  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017

Okay turns out it didn't matter, what is the correct way to register the renderers?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted October 7, 2017
51 minutes ago, Kokkie said:

Okay turns out it didn't matter, what is the correct way to register the renderers?

RenderingRegistry.registerEntityRenderingHandler

 

1 hour ago, Kokkie said:

Tell me if something is wrong in this as well.

You need to call build and register the resulting entry.

  • Quote

Share this post


Link to post
Share on other sites

jabelar    591

jabelar

jabelar    591

  • Reality Controller
  • jabelar
  • Members
  • 591
  • 3266 posts
Posted October 7, 2017

This is exactly the type of thread I envisioned when I was complaining on the pull request about the complexity of the new registration system... we went from needing a single, easy-to-understand line of code to register an entity to complex set of entries, builders and such. I'm still at a bit of a loss to understand the advantage of the new system. diesieben07 do you understand the advantage / reason that this sort of complexity is needed? I suppose it has something to do with the fact that entities need to be instantiated where other things that are registered (items, blocks, recipes) are singletons?

  • Like 2
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted October 7, 2017
2 minutes ago, jabelar said:

diesieben07 do you understand the advantage / reason that this sort of complexity is needed? I suppose it has something to do with the fact that entities need to be instantiated where other things that are registered (items, blocks, recipes) are singletons?

I don't think

EntityEntry entry = EntityEntryBuilder.create()
    .entity(MyEntity.class)
    .id(new ResourceLocation(...), ID++)
    .name("my_entity")
    .egg(0xFFFFFF, 0xAAAAAA)
    .tracker(64, 20, false)
    .build();
event.getRegistry().register(entry);

is any more complex than

EntityRegistry.registerModEntity(new ResourceLocation(...), MyEntity.class, "my_entity", ID, MyMod.INSTANCE, 64, 20, false, 0xFFFFFF, 0xAAAAAA);

 

In fact I would argue that the first one is

  • much easier to understand: you clearly see what each argument does, one of the advantages of a builder over a huge one-method factory with 20 parameters.
  • more consistent: you only register things to event.getRegistry inside RegistryEvent.Register, you don't call random other methods.
  • more future proof: If we need new parameters entity registration they can be added to the builder without breaking old mods.
  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

jabelar    591

jabelar

jabelar    591

  • Reality Controller
  • jabelar
  • Members
  • 591
  • 3266 posts
Posted October 7, 2017
1 hour ago, diesieben07 said:

I don't think


EntityEntry entry = EntityEntryBuilder.create()
    .entity(MyEntity.class)
    .id(new ResourceLocation(...), ID++)
    .name("my_entity")
    .egg(0xFFFFFF, 0xAAAAAA)
    .tracker(64, 20, false)
    .build();
event.getRegistry().register(entry);

is any more complex than


EntityRegistry.registerModEntity(new ResourceLocation(...), MyEntity.class, "my_entity", ID, MyMod.INSTANCE, 64, 20, false, 0xFFFFFF, 0xAAAAAA);

 

In fact I would argue that the first one is

  • much easier to understand: you clearly see what each argument does, one of the advantages of a builder over a huge one-method factory with 20 parameters.
  • more consistent: you only register things to event.getRegistry inside RegistryEvent.Register, you don't call random other methods.
  • more future proof: If we need new parameters entity registration they can be added to the builder without breaking old mods.

Well, I meant it is conceptually more difficult as well as inconsistent with the other registries. You want to register an entity, but you need to wrap that in an entity entry. That would be okay except you can't simply construct that but rather you need to build it through a builder class then chain the methods -- and don't forget to actually call the build() method which is different than create()!

 

Basically, you can see the OP in this thread ran into all the problems conceptually -- initially thought they could register entities directly, finally figured out that they needed a builder for entries but then forgot to do the build().

 

I guess I'd like it better if it was consistent across all the registries.

 

I think the problem is that Forge is moving to more high-end programmer style -- lots of factories, functional interfaces, builders, and such. These are all really good programming style things and of course the "proper" way to do things. However, I believe it greatly reduces the accessibility to the general modder who is just dabbling.

 

Also, the point with an API is that it is supposed to be a "contract" that is only modified under extreme situations. The amount of work it takes now to port a mod is literally weeks per mod. Forge ideally would be an API that stands the test of time (with all the changes happening invisibly under the hood). This is why there are so many people stuck modding back on 1.7.10 -- they simply can't keep up either conceptually or effort-wise.

 

Basically, I think Forge is doing great stuff but is getting way ahead of the actual modding community both in terms of skill level required as well as simply keeping up porting mods. Heck this morning I upgraded my 1.12.1 mod to 1.12.2 and had to spend some serious time to clear out the errors. That is a problem when a modder like me who tries to keep up and has intermediate Java level has to scratch their head just to keep their previously working mod working.  It is really fracturing the modding community -- if you don't believe me go to Minecraft Forums modification development forum and you'll see that only about 1 in 10 questions is about anything after 1.8!

 

I guess I'm hoping that all these big changes get solid soon and then stay stable for a few years. Otherwise it is really disheartening to see all your learning and work get obsolete so quickly.

  • Like 2
  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017
1 hour ago, jabelar said:

and don't forget to actually call the build() method which is different than create()!

I didn't forget this, I only called this when registering instead of at creation, should've said that though.

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017
3 hours ago, diesieben07 said:

RenderingRegistry.registerEntityRenderingHandler

In what event do you suggest doing this?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted October 7, 2017
1 hour ago, jabelar said:

Well, I meant it is conceptually more difficult as well as inconsistent with the other registries. You want to register an entity, but you need to wrap that in an entity entry. That would be okay except you can't simply construct that but rather you need to build it through a builder class then chain the methods -- and don't forget to actually call the build() method which is different than create()!

No, you are not registering an Entity, you are registering an EntityEntry. This is unavoidable, since entities are not singletons, unlike the other registry types. Yes, an EntityEntry requires a builder, but that is just because registering an entity requires so many damn  parameters (which is also unavoidable). A giant constructor on EntityEntry would not help here at all. 

 

1 hour ago, jabelar said:

I guess I'd like it better if it was consistent across all the registries.

It can't be. Entities are fundamentally different from Blocks, Items, Biomes, etc.

 

1 hour ago, jabelar said:

Also, the point with an API is that it is supposed to be a "contract" that is only modified under extreme situations. The amount of work it takes now to port a mod is literally weeks per mod. Forge ideally would be an API that stands the test of time (with all the changes happening invisibly under the hood). This is why there are so many people stuck modding back on 1.7.10 -- they simply can't keep up either conceptually or effort-wise.

Which is exactly my point. A constructor with a parameter added is no longer backwards compatible (unless you keep both constructors, which is a hassle). A builder continues to work even if you add more parameters.

  • Quote

Share this post


Link to post
Share on other sites

Kokkie    55

Kokkie

Kokkie    55

  • Dragon Slayer
  • Kokkie
  • Forge Modder
  • 55
  • 796 posts
Posted October 7, 2017
15 minutes ago, Kokkie said:

In what event do you suggest doing this?

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted October 7, 2017
28 minutes ago, Kokkie said:

In what event do you suggest doing this?

preInit of your client proxy.

  • Quote

Share this post


Link to post
Share on other sites

jabelar    591

jabelar

jabelar    591

  • Reality Controller
  • jabelar
  • Members
  • 591
  • 3266 posts
Posted October 7, 2017
29 minutes ago, diesieben07 said:

Which is exactly my point. A constructor with a parameter added is no longer backwards compatible (unless you keep both constructors, which is a hassle). A builder continues to work even if you add more parameters.

 

I agree it is good f we're moving towards something we can keep stable for the long term. Up until now there has been a major overhaul of some aspect of Forge literally every couple months which is well-intentioned but has fractured the modding code base and left a lot of people and mods behind. Hopefully we'll be finished upgrading everything soon and we let the modding community catch up!

  • Quote

Share this post


Link to post
Share on other sites

DragonFerocity    0

DragonFerocity

DragonFerocity    0

  • Creeper Killer
  • DragonFerocity
  • Members
  • 0
  • 113 posts
Posted October 9, 2017 (edited)
On 10/7/2017 at 11:04 AM, diesieben07 said:

RenderingRegistry.registerEntityRenderingHandler

 

Is there another way to register entities now? Whenever I type in this function, Eclipse says "Deprecated. use the factory version during Preinitialization. TODO Will be removed in 1.11."

 

What should I do instead?

 

EDIT: I already have 

EntityEntry entry = EntityEntryBuilder.create()
    .entity(MyEntity.class)
    .id(new ResourceLocation(...), ID++)
    .name("my_entity")
    .egg(0xFFFFFF, 0xAAAAAA)
    .tracker(64, 20, false)
    .build();
event.getRegistry().register(entry);

implemented. I'm assuming I still need to register the render though?

Edited October 9, 2017 by DragonFerocity
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2096

Draco18s

Draco18s    2096

  • Reality Controller
  • Draco18s
  • Members
  • 2096
  • 14029 posts
Posted October 9, 2017
4 minutes ago, DragonFerocity said:

 

Is there another way to register entities now? Whenever I type in this function, Eclipse says "Deprecated. use the factory version during Preinitialization. TODO Will be removed in 1.11."

There are two methods with the same name, use the not-deprecated one.

  • Quote

Share this post


Link to post
Share on other sites

DragonFerocity    0

DragonFerocity

DragonFerocity    0

  • Creeper Killer
  • DragonFerocity
  • Members
  • 0
  • 113 posts
Posted October 9, 2017
1 minute ago, Draco18s said:

There are two methods with the same name, use the not-deprecated one.

On my end, they both show as deprecated.

 

These are the two different ones that I see:

RenderingRegistry.registerEntityRenderingHandler(entityClass, renderFactory);
RenderingRegistry.registerEntityRenderingHandler(entityClass, renderer);

And both show

Deprecated.  use the factory version during Preinitialization. TODO Will be removed in 1.11.

 

  • Quote

Share this post


Link to post
Share on other sites
  • Prev
  • 1
  • 2
  • Next
  • Page 1 of 2  

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 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      Memory Heap Thingy!

      By diesieben07 · Posted 9 minutes ago

      That's not what this thread is about... Make your own thread and post logs.
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 26 minutes ago

      It gets stuck on that part and doesn’t change
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 27 minutes ago

      Wym  
    • RaphGamingz
      ScreenGui does nothing

      By RaphGamingz · Posted 1 hour ago

      any errors?
    • RaphGamingz
      Game crashing when the block is activated

      By RaphGamingz · Posted 1 hour ago

      then you    your not assigning a value to the tileEntity try in the constructor tileEntity = world.getTileEntity(pos);
  • Topics

    • Mizinov
      7
      Memory Heap Thingy!

      By Mizinov
      Started August 24

    • Jaffaaaaa
      2
      ScreenGui does nothing

      By Jaffaaaaa
      Started Wednesday at 07:03 PM

    • jun2040
      5
      Game crashing when the block is activated

      By jun2040
      Started 17 hours ago

    • Merthew
      5
      [1.12.2] Multiple Structure Generation

      By Merthew
      Started November 7, 2018

    • Professional Derp
      16
      Server frequently crashes

      By Professional Derp
      Started 10 hours ago

  • Who's Online (See full list)

    • Lea9ue
    • Choonster
    • Krevik
    • diesieben07
    • GttiqwT
    • ZigTheHedge
    • ewew
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12] Registering entities
  • Theme
  • Contact Us
  • Discord

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