Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

In my project i use DeferredRegister to register entities, blocks, items and so on. But as i recently discovered, DeferredRegister has some problems with registring spawn eggs that summon custom entities. As i know there is some sort of registration order that registers items first, and only after that entities; and because of that system cannot register spawn egg that has reference to non-existent entity. So my question is there any way to change that order? If not, is there any other way to create spawn eggs using DeferredRegister?

My classes with current logs are below:

Entities class:

package com.mclich.engmod.util;

import java.util.ArrayList;
import java.util.List;
import com.mclich.engmod.ENGMod;
import com.mclich.engmod.entity.CustomEntity;
import com.mclich.engmod.entity.ValkyrieEntity;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EntityType.Builder;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public abstract class ENGModEntities
{
	public static final DeferredRegister<EntityType<?>> ENTITIES=DeferredRegister.create(ForgeRegistries.ENTITIES, ENGMod.MOD_ID);
	
	public static final RegistryObject<EntityType<ValkyrieEntity>> VALKYRIE_ENTITY=ENGModEntities.ENTITIES.register(ValkyrieEntity.ID, ()->						EntityType.Builder.<ValkyrieEntity>of(ValkyrieEntity::new,
    	EntityClassification.MONSTER).setShouldReceiveVelocityUpdates(true).setTrackingRange(32)
        .setUpdateInterval(3).sized(1.0f, 2.0f).build(new ResourceLocation(ENGMod.MOD_ID, ValkyrieEntity.ID).toString()));
}

Items class:

package com.mclich.engmod.util;

import java.util.ArrayList;
import java.util.List;
import com.mclich.engmod.ENGMod;
import com.mclich.engmod.block.CustomBlock;
import com.mclich.engmod.block.CustomBlock.CustomBlockBase;
import com.mclich.engmod.entity.ValkyrieEntity;
import com.mclich.engmod.item.CustomMaterial;
import com.mclich.engmod.item.CustomSpawnEggItem;
import com.mclich.engmod.item.CustomSword;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;

public abstract class ENGModItems
{
	public static final DeferredRegister<Item> ITEMS=DeferredRegister.create(ForgeRegistries.ITEMS, ENGMod.MOD_ID);
      
    public static final RegistryObject<Item> VALKYRIE_SPAWN_EGG_ITEM=ENGModItems.ITEMS.register(ValkyrieEntity.SPAWN_EGG_ID, ()->
		new SpawnEggItem(ENGModEntities.VALKYRIE_ENTITY.get(), -26317, -3394816, new Item.Properties().tab(ENGModTabs.MATERIALS_TAB)));
}

Entity class:

package com.mclich.engmod.entity;

import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.controller.FlyingMovementController;
import net.minecraft.entity.ai.goal.LookAtGoal;
import net.minecraft.entity.ai.goal.LookRandomlyGoal;
import net.minecraft.entity.ai.goal.PanicGoal;
import net.minecraft.entity.ai.goal.SwimGoal;
import net.minecraft.entity.ai.goal.TemptGoal;
import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.pathfinding.FlyingPathNavigator;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class ValkyrieEntity extends MonsterEntity
{
	public static final String ID="valkyrie_entity";
	public static final String SPAWN_EGG_ID="valkyrie_spawn_egg";
	public ValkyrieEntity(EntityType<? extends MonsterEntity> type, World worldIn)
	{
		super(type, worldIn);
		this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(Items.IRON_SWORD, 1));
		this.moveControl=new FlyingMovementController(this, 10, true);
		this.navigation=new FlyingPathNavigator(this, worldIn);
	}
	
	public static AttributeModifierMap.MutableAttribute createAttributes()
	{
		return MonsterEntity.createMonsterAttributes()
			.add(Attributes.MAX_HEALTH, 60.0D)
			.add(Attributes.MOVEMENT_SPEED, 0.35D)
			.add(Attributes.ATTACK_DAMAGE, 10.0D)
			.add(Attributes.ARMOR, 16.0D)
			.add(Attributes.FLYING_SPEED, 1.0D);
	}

	@Override
	public void registerGoals()
	{
		super.registerGoals();
		this.goalSelector.addGoal(0, new SwimGoal(this));
		this.goalSelector.addGoal(1, new PanicGoal(this, 1.25D));
		this.goalSelector.addGoal(2, new WaterAvoidingRandomWalkingGoal(this, 0.8));
		this.goalSelector.addGoal(3, new LookAtGoal(this, PlayerEntity.class, 6.0F));
		this.goalSelector.addGoal(4, new LookRandomlyGoal(this));
	}

	@Override
	public int getExperienceReward(PlayerEntity player)
	{
		return 15;
	}

	@Override
	public SoundEvent getAmbientSound()
	{
		return SoundEvents.ARMOR_EQUIP_ELYTRA;
	}

	@Override
	public SoundEvent getDeathSound()
	{
		return SoundEvents.BEACON_DEACTIVATE;
	}

	@Override
	public SoundEvent getHurtSound(DamageSource damageSource)
	{
		return super.getHurtSound(damageSource);
	}

	@Override
	protected void playStepSound(BlockPos pos, BlockState blockOn)
	{
		this.playSound(SoundEvents.NETHER_SPROUTS_STEP, 0.15F, 1.0F);
	}
}

Logs:

-- Head --
Thread: Render thread
Stacktrace:
	at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_291] {}
-- MOD engmod --
Details:
	Mod File: main
	Failure message: Elder Norse Gods (engmod) encountered an error during the load_registries event phase
		java.lang.NullPointerException: Registry Object not present: engmod:valkyrie_entity
	Mod Version: 1.0
	Mod Issue URL: https://change.me.to.your.issue.tracker.example.invalid
	Exception message: java.lang.NullPointerException: Registry Object not present: engmod:valkyrie_entity
Stacktrace:
	at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_291] {}
	at net.minecraftforge.fml.RegistryObject.get(RegistryObject.java:120) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at com.mclich.engmod.util.ENGModItems.lambda$3(ENGModItems.java:24) ~[main/:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister.lambda$register$0(DeferredRegister.java:124) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister.addEntries(DeferredRegister.java:200) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister.access$000(DeferredRegister.java:61) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.registries.DeferredRegister$EventDispatcher.handleEvent(DeferredRegister.java:172) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.eventbus.ASMEventHandler_0_EventDispatcher_handleEvent_Register.invoke(.dynamic) ~[?:?] {}
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:120) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:36.2] {re:classloading}
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:121) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1640) ~[?:1.8.0_291] {}
	at net.minecraftforge.fml.ModWorkManager$SyncExecutor.driveOne(ModWorkManager.java:56) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModWorkManager$DrivenExecutor.drive(ModWorkManager.java:40) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:249) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:236) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:202) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$1(ClientModLoader.java:103) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$4(ClientModLoader.java:123) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:103) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.<init>(Minecraft.java:437) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:149) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_291] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_291] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_291] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_291] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}

 

Edited by mclich

  • mclich changed the title to Creating custom spawn eggs with DeferredRegister 1.16.5

You can't really use DeferredRegsiter as far as I'm aware.
To register a spawn egg you'll need to subscribe to RegistryEvent.Register<Item> and then do event.getRegistry().register(SpawnEgg).
I recommend making the spawn egg a variable outside of the method you're using to register them just so you can use that variable for example when adding your SpawnEgg to a manually-ordered creative tab.

  • Author

When i register it using events my custom entity just spawns as pig (if use an egg), i don't know why

  • Author
On 8/15/2021 at 7:37 PM, diesieben07 said:

Show your code.

I've already deleted it from my project (because it didn't work), but i had something like this in my items class:

package com.mclich.engmod.util;

import java.util.ArrayList;
import java.util.List;
import com.mclich.engmod.ENGMod;
import com.mclich.engmod.block.CustomBlock;
import com.mclich.engmod.block.CustomBlock.CustomBlockBase;
import com.mclich.engmod.entity.ValkyrieEntity;
import com.mclich.engmod.item.CustomMaterial;
import com.mclich.engmod.item.CustomSpawnEggItem;
import com.mclich.engmod.item.CustomSword;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;

public abstract class ENGModItems
{
	public static final DeferredRegister<Item> ITEMS=DeferredRegister.create(ForgeRegistries.ITEMS, ENGMod.MOD_ID);
	
    // custom items
	public static final RegistryObject<Item> CUSTOM_SWORD_ITEM=ENGModItems.ITEMS.register(CustomSword.ID, CustomSword::new);
	public static final RegistryObject<Item> CUSTOM_MATERIAL_ITEM=ENGModItems.ITEMS.register(CustomMaterial.ID, CustomMaterial::new);
	public static final RegistryObject<Item> CUSTOM_BLOCK_ITEM=ENGModItems.ITEMS.register(CustomBlock.ID, CustomBlockBase::new);
	
    // custom eggs
	@SubscribeEvent
	public static void registerItems(Register<Item> event)
    {
		event.getRegistry().register(new SpawnEggItem(ENGModEntities.VALKYRIE_ENTITY, 0X340000, 0XA52929, new
            Item.Properties().tab(ENGModTabs.MISC_TAB)).setRegistryName("engmod:"+ValkyrieEntity.SPAWN_EGG_ID));
    }
}

 

 

Edited by mclich

  • Author
3 hours ago, diesieben07 said:

What is ENGModEntities.VALKYRIE_ENTITY?

 

public static final EntityType<ValkyrieEntity> VALKYRIE_ENTITY=Builder.of(ValkyrieEntity::new, EntityClassification.MONSTER).sized(1.0f, 2.0f).build(new ResourceLocation(ENGMod.MOD_ID, ValkyrieEntity.ID).toString());

 

Edited by mclich

  • Author
9 minutes ago, Luis_ST said:

how did you register the EntityType (ENGModEntities.VALKYRIE_ENTITY)

using DeferredRegsiter

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.