Cadiboo / Example-Mod

An example mod created to try and get new modders to use good code practices
GNU Lesser General Public License v3.0
196 stars 41 forks source link

Update ModItems.java #19

Closed Chubel10 closed 4 years ago

Chubel10 commented 4 years ago

Since ModEntityTypes.WILD_BOAR is of type RegistryObject<EntityType>. I thought that maybe it was incorrect because .get() need to get called in order to return the EntityType.

Cadiboo commented 4 years ago

Sorry for the long wait, I looked at this when you made it but didn’t accept it (because of the following reasoning). I didn’t close it either because I wanted to give some reasoning for closing it but haven’t had much free time.

Entities don’t exist when items are registered (the registry order is blocks -> items -> everything else in alphabetical order) so a reference to the entity type rather than the type itself (which would be null at the time) needs to be passed to the egg. Therefore I pass ModEntityTupes.WILD_BOAR (a RegistryObject<EntityType> is effectively a Supplier<EntityType> I.e. a reference to the EntityType) to the egg. Calling get on the EntityType when the egg is being registered would yield null and cause issues or crashes (NPEs or registry issues) later down the line.