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


Recommended Posts

23 hours ago, DragonITA said:

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

You should pass in null as the entity type as you’re going to override the getType method to return your one

23 hours ago, DragonITA said:

I still have not understood how to override the function.

Just override “getType” like any other method. You can use an anonymous subclass if you want.


The only issue that I’ve found with this is that the spawn egg textures don’t get generated for your egg. I’m looking into this.

Edited by Cadiboo
  • Thanks 1

About Me


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

  • 1 month later...

If you still have problems with your SparnEgg, try this:

public class SupplierSpawnEggItem extends SpawnEggItem
    private RegistryObject<?> supplier;
    public SupplierSpawnEggItem(EntityType<?> typeIn, RegistryObject<?> supplierIn, int primaryColorIn, int secondaryColorIn, Properties builder)
        super(typeIn, primaryColorIn, secondaryColorIn, builder);
        supplier = supplierIn;
    public EntityType<?> getType(CompoundNBT p_208076_1_)
        return (EntityType<?>) supplier.get();

This custom SpawnEgg-class works fine for me.

Textures and colors work too.

Edited by Drachenbauer
Link to comment
Share on other sites

@DrachenbauerOk, for placing a entity you need a spawnegg. Cadiboo has make a method to create, register and use Spawnegggs but that are registered with the deferredregister. But the Problem with the DeferredRegister is that when you are trying to place the entity then the game crash and it say you that the RegistryObject was not found (RegistryObject = Your entity). This was caused because the egg was registered before the entity, so when you use the egg you spawn null and it cause a crash. Now the other part of the code is to make that when you use the Spawnegg, that you are sure that the entity was before registered, so that when you spawn it it not cause a game crash.

Edited by DragonITA

New in Modding? == Still learning!

Link to comment
Share on other sites

My much slimmer code, that i posted above, can do that too.


Ad cadiboo´s version:

is there something about using spawneggs in a redstone-dispenser?


I just wonder, about this part:

        public static void initUnaddedEggs() {
		final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
		DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior() {
			public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
				Direction direction = source.getBlockState().get(DispenserBlock.FACING);
				EntityType<?> entitytype = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
				entitytype.spawn(source.getWorld(), stack, null, source.getBlockPos().offset(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
				return stack;
		for (final SpawnEggItem egg : UNADDED_EGGS) {
			EGGS.put(egg.getType(null), egg);
			DispenserBlock.registerDispenseBehavior(egg, defaultDispenseItemBehavior);
			// ItemColors for each spawn egg don't need to be registered because this method is called before ItemColors is created


I tested to put my egg into the dispenser, but only the egg came out.


But this happens with all my mod-ones, also the ones, that still are registered the old way, too...



Now i got the new one to work in a dispenser.

Now i know, this method makes it able to spawn the entity out of the disbenser.


And for the two constructors:

When do you get an Entity type in a NonNullSupplier?

With DeferredRegister, you put them always into a RegistryObject.


And instead of using this thing called "Lazy", you also can put them into separate fields and use a boolean to choose one in the getType method.

The boolean is set to true in one constructor and false in the other.


Another question:

Why do the creators of minecraft never change the order of register entity and item?



Now i modifyed the constructors a bit:

I removed the EntityType parameters from the constructor-headers and pass directly "null" to the superconstructor.

So i could remove the "null" from my registry lines for the eggs.

Edited by Drachenbauer
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.

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.


  • Create New...

Important Information

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