Jump to content

How to Register Entities using the Deferred Register?


Recommended Posts

I have an Item (DynamiteStickItem) that when used spawns an entity (DynamiteEntity) that extends ProjectileTileEntity.

if (!worldIn.isRemote) {
  DynamiteEntity dynamiteEntity = new DynamiteEntity(worldIn, player);
  dynamiteEntity.func_234612_a_(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);


However, the Java compiler seems to have a problem with the constructors. At first, in the DynamiteEntity, I had the following constructor:

public DynamiteEntity(World world, PlayerEntity player) {
	super(EntityTypes.SNOWBALL, player, world);


Then when I used the Item, the summoned entity had the snowball texture. I figured I had to register my own EntityType, and I'm trying to do so with the Deferred Registries.

public static final RegistryObject<EntityType<DynamiteEntity>> DYNAMITE_ENTITY = RegistryHandler.ENTITIES.register("dynamite_entity", () ->
	EntityType.Builder.create(DynamiteEntity::new, EntityClassification.MISC)
		.size(0.25f, 0.25f)


(I don't know if I'm missing something when passing the Supplier using EntityType.Builder.create method, I haven't found much resources about registering entities)

However, The EntityType.Builder.create complained about the constructor, so I looked at the code for the Snowball constructors and added the following to the DynamiteEntity class:

public DynamiteEntity(EntityType<? extends DynamiteEntity> entity, World world) { 
	super(entity, world);


Then the EntityType.Builder.create is not being able to resolve the constructor for 'DynamiteEntity'. I Tried removing the initial constructor (and updating the code in DynamiteStickItem to use only the construcor that uses EntityType<? extends DynamiteEntity>), the EntityType.Builder.create then worked, but the Item wouldn't spawn the Entity, and It wasn't textures when I tried spawning it using commands...

What am I doing wrong?


Additionnaly, is there a Data Generator to generate Entity models?

Link to comment
Share on other sites



>Additionnaly, is there a Data Generator to generate Entity models?

Try BlockBench, it is quite awesome 



I don't know about DeferredRegister for Entities; but this method should work for what you're trying to do:

  // register our entity types
  public static void onEntityTypeRegistration(RegistryEvent.Register<EntityType<?>> entityTypeRegisterEvent) {
    emojiEntityType = EntityType.Builder.<EmojiEntity>create(EmojiEntity::new, EntityClassification.MISC)
            .size(0.25F, 0.25F)
 * Created by TGG on 24/06/2020.
 * Heavily based on the vanilla SnowballEntity
public class EmojiEntity extends ProjectileItemEntity {
  public EmojiEntity(EntityType<? extends EmojiEntity> entityType, World world) {
    super(entityType, world);

  public EmojiEntity(World world, LivingEntity livingEntity) {
    super(StartupCommon.emojiEntityType, livingEntity, world);

  public EmojiEntity(World world, double x, double y, double z) {
    super(StartupCommon.emojiEntityType, x, y, z, world);

  // If you forget to override this method, the default vanilla method will be called.
  // This sends a vanilla spawn packet, which is then silently discarded when it reaches the client.
  //  Your entity will be present on the server and can cause effects, but the client will not have a copy of the entity
  //    and hence it will not render.
  public IPacket<?> createSpawnPacket() {
    return NetworkHooks.getEntitySpawningPacket(this);

  // ProjectileItemEntity::setItem uses this to save storage space.  It only stores the itemStack if the itemStack is not
  //   the default item.
  protected Item getDefaultItem() {
    return StartupCommon.emojiItemHappy;

  // We hit something (entity or block).
  protected void onImpact(RayTraceResult rayTraceResult) {
    // if we hit an entity, apply an effect to it depending on the emoji mood
    if (rayTraceResult.getType() == RayTraceResult.Type.ENTITY) {
      EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult)rayTraceResult;
      Entity entity = entityRayTraceResult.getEntity();
      if (entity instanceof LivingEntity) {
        LivingEntity livingEntity = (LivingEntity)entity;
        Optional<EmojiItem.EmojiMood> mood = getMoodFromMyItem();
        if (mood.isPresent()) {
          EffectInstance effect = (mood.get() == EmojiItem.EmojiMood.HAPPY) ?
                  new EffectInstance(Effects.REGENERATION, 100, 1) :
                  new EffectInstance(Effects.POISON, 10, 0);

    if (!this.world.isRemote) {
      this.world.setEntityState(this, VANILLA_IMPACT_STATUS_ID);  // calls handleStatusUpdate which tells the client to render particles

  // not needed here, but can be useful as a breakpoint location to check whether the entity was spawned properly, and to debug the behaviour / lifetime
  public void tick() {

  private static final byte VANILLA_IMPACT_STATUS_ID = 3;

  /*   see https://wiki.vg/Entity_statuses
       make a cloud of particles at the impact point
  public void handleStatusUpdate(byte statusID) {
    if (statusID == VANILLA_IMPACT_STATUS_ID) {
      IParticleData particleData = this.makeParticle();

      for(int i = 0; i < 8; ++i) {
        this.world.addParticle(particleData, this.getPosX(), this.getPosY(), this.getPosZ(), 0.0D, 0.0D, 0.0D);

  private IParticleData makeParticle() {
    Optional<EmojiItem.EmojiMood> mood = getMoodFromMyItem();
    if (!mood.isPresent()) return ParticleTypes.SNEEZE;
    return (mood.get() == EmojiItem.EmojiMood.HAPPY) ? ParticleTypes.HEART : ParticleTypes.ANGRY_VILLAGER;

  /** Look at the ItemStack stored by this entity and determine its mood
   * @return  The mood, or empty if no mood defined (for some unknown reason...)
  private Optional<EmojiItem.EmojiMood> getMoodFromMyItem() {
    ItemStack itemStackForThisEntity = this.func_213882_k();  // returns air if the entity is storing the default item (HAPPY in this case)
    Item item = itemStackForThisEntity.isEmpty() ? getDefaultItem() : itemStackForThisEntity.getItem();
    if (item instanceof EmojiItem) {
      EmojiItem.EmojiMood mood = ((EmojiItem) item).getEmojiMood();
      return Optional.of(mood);
    return Optional.empty();



Link to comment
Share on other sites

32 minutes ago, TheGreyGhost said:

>Additionnaly, is there a Data Generator to generate Entity models?

Try BlockBench, it is quite awesome 



This is going to be REALy useful, thanks!!


But then... I know there are Deferred Registries for Entities, I'm just not getting EntityType.Builder.create to work I think... Still thanks tho

I'm going to stick sctrictly to deferred registries, they seem far easier to write

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • What is that in my files?
    • Hi! I tried the above method, but it did not work. There's my function. The message appears in the chat, but the item is not added to the inventory. I can’t figure out what the problem is, so please help. @SubscribeEvent public void onJoin(EntityJoinLevelEvent event) { if (event.getEntity() instanceof Player && event.getEntity().getCommandSenderWorld().isClientSide) { Minecraft.getInstance().player.getInventory().add(new ItemStack(Items.CARROT)); Entity playerEntity = event.getEntity(); playerEntity.sendSystemMessage(Component.nullToEmpty("Hello!")); } }  
    • Hi guys ! New around here.So my problem is,I'm trying to play modded minecraft with my gf.We played on lan perfectly.But when we try to make a server for hamachi,It displays an error message.   [08Haz2023 18:30:33.491] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 43.2.8, --fml.mcVersion, 1.19.2, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20220805.130853] [08Haz2023 18:30:33.497] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.8+10.0.8+main.0ef7e830 starting: java version 19.0.1 by Oracle Corporation; OS Windows 10 arch amd64 version 10.0 [08Haz2023 18:30:33.798] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.onLoad [08Haz2023 18:30:33.799] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file URL: union:/C:/Users/user/Desktop/Yeni%20klasör/mods/OptiFine-OptiFine-1.19.2_HD_U_I1.jar%23118!/ [08Haz2023 18:30:33.848] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file: C:\Users\user\Desktop\Yeni klasör\mods\OptiFine-OptiFine-1.19.2_HD_U_I1.jar [08Haz2023 18:30:33.850] [main/INFO] [optifine.OptiFineTransformer/]: Target.PRE_CLASS is available [08Haz2023 18:30:33.916] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/user/Desktop/Yeni%20klasör/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2363!/ Service=ModLauncher Env=SERVER [08Haz2023 18:30:33.927] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.initialize [08Haz2023 18:30:34.282] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\user\Desktop\Yeni klasör\libraries\net\minecraftforge\fmlcore\1.19.2-43.2.8\fmlcore-1.19.2-43.2.8.jar is missing mods.toml file [08Haz2023 18:30:34.287] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\user\Desktop\Yeni klasör\libraries\net\minecraftforge\javafmllanguage\1.19.2-43.2.8\javafmllanguage-1.19.2-43.2.8.jar is missing mods.toml file [08Haz2023 18:30:34.291] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\user\Desktop\Yeni klasör\libraries\net\minecraftforge\lowcodelanguage\1.19.2-43.2.8\lowcodelanguage-1.19.2-43.2.8.jar is missing mods.toml file [08Haz2023 18:30:34.296] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\user\Desktop\Yeni klasör\libraries\net\minecraftforge\mclanguage\1.19.2-43.2.8\mclanguage-1.19.2-43.2.8.jar is missing mods.toml file [08Haz2023 18:30:34.386] [main/INFO] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: No dependencies to load found. Skipping! [08Haz2023 18:30:35.056] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.transformers [08Haz2023 18:30:35.063] [main/INFO] [optifine.OptiFineTransformer/]: Targets: 386 [08Haz2023 18:30:35.557] [main/INFO] [optifine.OptiFineTransformationService/]: additionalClassesLocator: [optifine., net.optifine.] [08Haz2023 18:30:35.906] [main/INFO] [mixin/]: Compatibility level set to JAVA_17 [08Haz2023 18:30:35.953] [main/ERROR] [mixin/]: Mixin config rottencreatures-common.mixins.json does not specify "minVersion" property [08Haz2023 18:30:35.957] [main/ERROR] [mixin/]: Mixin config rottencreatures.mixins.json does not specify "minVersion" property [08Haz2023 18:30:36.099] [main/INFO] [mixin/]: Successfully loaded Mixin Connector [org.tlauncher.MixinConnector] [08Haz2023 18:30:36.101] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeserver' with arguments [] [08Haz2023 18:30:36.122] [main/WARN] [mixin/]: Reference map '${refmap_target}refmap.json' for corgilib.forge.mixins.json could not be read. If this is a development environment you can ignore this message [08Haz2023 18:30:36.139] [main/WARN] [mixin/]: Reference map 'rottencreatures-forge-refmap.json' for rottencreatures.mixins.json could not be read. If this is a development environment you can ignore this message [08Haz2023 18:30:36.565] [main/ERROR] [net.minecraftforge.fml.loading.RuntimeDistCleaner/DISTXFORM]: Attempted to load class net/minecraft/client/gui/screens/Screen for invalid dist DEDICATED_SERVER [08Haz2023 18:30:36.566] [main/WARN] [mixin/]: Error loading class: net/minecraft/client/gui/screens/TitleScreen (java.lang.RuntimeException: Attempted to load class net/minecraft/client/gui/screens/Screen for invalid dist DEDICATED_SERVER) [08Haz2023 18:30:36.566] [main/WARN] [mixin/]: @Mixin target net.minecraft.client.gui.screens.TitleScreen was not found tlskincape-mixins.json:MixinMainMenu [08Haz2023 18:30:36.581] [main/WARN] [mixin/]: Error loading class: net/minecraft/client/model/PlayerModel (java.lang.ClassNotFoundException: net.minecraft.client.model.PlayerModel) [08Haz2023 18:30:36.582] [main/WARN] [mixin/]: @Mixin target net.minecraft.client.model.PlayerModel was not found tlskincape-mixins.json:MixinPlayerModel   that's from logs folder.
    • LivingAttackEvent is called inside the hurt function of LivingEntity. this means that whenever a living entity is attacked, forge will create an instance of new LivingAttackEvent and hand it to all subscribed functions 
    • ok after quitting and restarting I now get this crash report  
  • Topics

  • Create New...

Important Information

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