Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.15.1] How to register a EntityType with the DeferredRegister


DragonITA
 Share

Recommended Posts

Show what you’ve tried. EntityType registration should work perfectly with DeferredRegister (aside from spawn eggs as I’ve said)

  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

This means that I should rather not register with the DeferredRegister? (I asked so that I could know if it would be possible to register my Spawnegg with it. So now, if I want to use it for a Spawnegg, should I register it with my EntityType using the DeferredRegister or the other method?)

New in Modding? == Still learning!

Link to comment
Share on other sites

That’s not right. If you look at the DeferredRegister documentation you’ll see why it isn’t right. I would just not use vanilla’s spawn egg code - it wasn’t made to be used by mods Or at least I would extend it and make it use a supplier for your entity type.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

public final class ModItems
{
	// 1: This shouldn't be in a class called ModItems
  	// 2: You shouldn't be using this method, thats why its depreciated, you should be using the registry events
	@SuppressWarnings("deprecation")
	private static <T extends Entity> EntityType<T> register(String key, EntityType.Builder<T> builder) {
		return Registry.register(Registry.ENTITY_TYPE, key, builder.build(key));
	}
	public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, Main.MODID);
	// This shouldn't be in a class called ModItems
	//public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Main.MODID);
	
	// 1: This shouldn't be in a class called ModItems
	// 2: You shouldn't use static initialisers
  	// 3: You shouldn't register stuff statically
  	// You should create and register your objects inside the registry events
	public static final EntityType<UnicornEntity> UNICORN = register("unicorn_entity", EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).size(0.5F, 0.9F));
  	// This is correct - it's how you should be doing your registration, but it shouldn't be in a class called ModItems
	//public static final RegistryObject<EntityType<UnicornEntity>> UNICORN = ENTITY_TYPES.register("unicorn_entity", () -> EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).build(null));
	public static final RegistryObject<Item> RAINBOW_INGOT = ITEMS.register("rainbow_ingot",() -> new Item(new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP)));
	public static final RegistryObject<Item> UNICORN_ENTITY_EGG = ITEMS.register("unicorn_entity_egg", () -> new SpawnEggItem(UNICORN, 0xf0f0f0, 0xdf51f5, new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP)));
}

You should remove entity related stuff from your ModItems class and make a new class like so:

public final class ModEntityTypes {
	public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Main.MODID);

	public static final RegistryObject<EntityType<UnicornEntity>> UNICORN = ENTITY_TYPES.register("unicorn", () -> EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).size(0.5F, 0.9F).build(null));
}

and register your DeferredRegister in your mods constructor like this.

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

4 hours ago, Cadiboo said:

and register your DeferredRegister in your mods constructor like this.

Okay, thanks a lot. This should be the last question, do I have to register it before the items or after? To understand what I mean please look at Github. I mean into the Main class

Edited by DragonITA

New in Modding? == Still learning!

Link to comment
Share on other sites

9 minutes ago, DragonITA said:

Okay, thanks a lot. This should be the last question, do I have to register it before the items or after? To understand what I mean please look at Github.

If you're using DeferredRegister, it really doesn't matter; just make sure you register in your constructor, i.e. before any registry events are fired.  Forge will make sure everything's done in the right order.  If you've been paying attention, you'll have noticed that DeferredRegister does everything via Suppliers, so it's all lazy - nothing's actually initialized until the events are fired.

Edited by desht
  • Like 1
Link to comment
Share on other sites

Assuming https://github.com/DragonGamerDevelopers/NewFantasyMod-1.15.1/blob/master/src/main/java/mod/dragonita/fantasymod/init/ModItems.java is your up to date code producing that error, then it's wrong.  You're registering your entity type directly in the (vanilla) minecraft Registry in a class constructor which is called before any registration is happening.  That's always going to fail, and you should never be touching the vanilla registry directly.

 

Entity types work with DeferredRegister just like any other Forge registry entry.  As an example, see PneumaticCraft entity registration here, which works fine: https://github.com/TeamPneumatic/pnc-repressurized/blob/1.14/src/main/java/me/desht/pneumaticcraft/common/core/ModEntities.java

  • Like 1
Link to comment
Share on other sites

EntityTypes get created after Items. You’re trying to use an EntityEntry from your item when you make a spawn egg. This can’t work. As I said, the situation is problematic. That’s why I said you should make your own spawn egg that accepts a Supplier<EntityType> instead of an actual EntityType. 

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

13 hours ago, DragonITA said:

@Cadiboo But what if I need my EntityType somewhere else?

If you need it before it exists, you’re out of luck.

  • Sad 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

7 hours ago, DragonITA said:

So in other words I have to copy the whole Spawnegg code and change it so that it works with Suppliers?

Pretty much. You might be able to just extend it and use suppliers and you can probably clean up a bit of it’s code in your class.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

5 hours ago, DragonITA said:

@CadibooBut then it's impossible to close an entity, because the renderer needs the EntityType and I don't think I really have to rewrite the whole renderer register now. If so then it's much harder than what I think.

Renderers get registered after all registry events have finished. So after EntityTypes. I’ll put an example in my example mod

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

16 hours ago, DragonITA said:

I find the whole thing with the Deferred Registers too difficult.

The whole point of them is that they are dead simple. The only issue with them is the spawn egg thing which is easily fixed right now (pass null into the constructor + anonymous subclass that overrides getType) and is likely to be made even easier in the future.

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

3 hours ago, Cadiboo said:

pass null into the constructor

Does the first parameter, the entity parameter, have to be or all three parameters?

3 hours ago, Cadiboo said:

anonymous subclass that overrides getType

I still have not understood how to override the function.

New in Modding? == Still learning!

Link to comment
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.   Restore formatting

  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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • We have created a pickaxe.json below MInecraft-MOD-1.17/src/main/resources/data/minecraft.tags.blocks/mineable/pickaxe.json github link  https://github.com/ocome85/MInecraft-MOD-1.17    I can't add Tag and you can't dig. Please help me.
    • Thank you I completely forgot about that. I will attempt to put a delay in  
    • While chugging along making the JSONs by hand (to get an idea of how they need to be generated for each type of block), I cam up with a possibly brilliant idea. Could I somehow make template JSONs and when a new block of a certain type is being generated it will just pull the template and replace certain keywords like "NAME" and "COLOR" instead of all of this getVariantBuilder stuff
    • Hello everyone!     I'm quite new to forge, I used to do development for spigot. I needed to create a GUI Overlays and I found an article https://emxtutorials.wordpress.com/simple-in-game-gui-overlay/ on how to create a gui overlay, but as I understood the classes were renamed. Can you           share a sample code that would perform this function? Thank you in advance
    • I am at my wit's end trying to figure out what keeps going wrong. Reading the error log tells me absolutely nothing I can understand, and after making a blank new server and finally having it work after so long, just to have it break again, is extremely irritating. I would love for someone to decipher what this error log says and point me in a direction, at least, so I'm not swinging blindly. Minecraft 1.16.5 and Forge 36.2.2   [14:47:37] [Server thread/INFO] [minecraft/PlayerList]: Hyratos[/192.168.1.195:64650] logged in with entity id 45 at (481.30365299459726, 78.0, 426.6331819365098) [14:47:37] [Server thread/INFO] [minecraft/DedicatedServer]: Hyratos joined the game [14:47:37] [Netty Server IO #2/ERROR] [tconstruct/]: MaterialRecipeSerializer: Error reading recipe from packet java.lang.NullPointerException: null     at slimeknights.tconstruct.library.recipe.material.MaterialRecipeSerializer.writeSafe(MaterialRecipeSerializer.java:70) ~[tconstruct:1.16.5-3.1.1.252]     at slimeknights.tconstruct.library.recipe.material.MaterialRecipeSerializer.writeSafe(MaterialRecipeSerializer.java:20) ~[tconstruct:1.16.5-3.1.1.252]     at slimeknights.tconstruct.common.recipe.LoggingRecipeSerializer.func_199427_a_(LoggingRecipeSerializer.java:49) ~[tconstruct:1.16.5-3.1.1.252]     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_218771_a(SourceFile:64) ~[?:?]     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148840_b(SourceFile:43) ~[?:?]     at net.minecraftforge.network.VanillaPacketSplitter.appendPackets(VanillaPacketSplitter.java:100) ~[forge:?]     at net.minecraftforge.network.ForgeConnectionNetworkFilter.splitPacket(ForgeConnectionNetworkFilter.java:85) ~[forge:?]     at net.minecraftforge.network.VanillaPacketFilter.encode(VanillaPacketFilter.java:75) ~[forge:?]     at net.minecraftforge.network.VanillaPacketFilter.encode(VanillaPacketFilter.java:38) ~[forge:?]     at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:88) ~[server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801) ~[server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814) ~[server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794) ~[server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831) ~[server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1071) ~[server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:300) ~[server-1.16.5-20210115.111550-extra.jar:?]     at net.minecraft.network.NetworkManager.lambda$sendPacket$5(NetworkManager.java:196) ~[?:?]     at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) [server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) [server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:465) [server-1.16.5-20210115.111550-extra.jar:?]     at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) [server-1.16.5-20210115.111550-extra.jar:?]     at java.lang.Thread.run(Unknown Source) [?:1.8.0_301] [14:47:38] [Server thread/WARN] [Mekanism/]: Failed to retrieve username for UUID 594cf1d3-7a0c-4e6f-bd16-5df4bb7ce72b, you might want to add it to the JSON cache [14:47:38] [Server thread/WARN] [minecraft/EntityDataManager]: defineId called for: class dev.itsmeow.whisperwoods.entity.EntityMoth from class dev.itsmeow.whisperwoods.imdlib.entity.EntityTypeContainer [14:47:38] [Server thread/WARN] [minecraft/EntityDataManager]: defineId called for: class dev.itsmeow.whisperwoods.entity.EntityMoth from class dev.itsmeow.whisperwoods.imdlib.entity.util.EntityTypeContainerContainable [14:47:38] [Server thread/WARN] [minecraft/EntityDataManager]: defineId called for: class its_meow.betteranimalsplus.common.entity.EntityButterfly from class dev.itsmeow.betteranimalsplus.imdlib.entity.EntityTypeContainer [14:47:38] [Server thread/WARN] [minecraft/EntityDataManager]: defineId called for: class its_meow.betteranimalsplus.common.entity.EntityButterfly from class dev.itsmeow.betteranimalsplus.imdlib.entity.util.EntityTypeContainerContainable [14:47:38] [Server thread/WARN] [minecraft/EntityDataManager]: defineId called for: class dev.itsmeow.whisperwoods.entity.EntityZotzpyre from class dev.itsmeow.whisperwoods.imdlib.entity.EntityTypeContainer [14:47:38] [Server thread/INFO] [survive/]: Syncing Armor Data To Client (Hyratos) [14:47:38] [Server thread/INFO] [minecraft/ServerPlayNetHandler]: Hyratos lost connection: Internal Exception: io.netty.handler.codec.EncoderException: java.lang.NullPointerException [14:47:38] [Server thread/INFO] [minecraft/DedicatedServer]: Hyratos left the game  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.