Jump to content

[SOLVED] [1.15.2] Registry Object not present for ProjectileItemEntity registration


Recommended Posts

Posted (edited)

Hi~
Here again with another stupid problem...

This time I'm trying to register a new projectile following how the Snowball is make. I'm registering the entity like any other entity in the project but this one throw this error. Whats wrong this time? XD

 

Log

[19giu2020 20:58:43.075] [modloading-worker-0/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: Registry Object not present: earthtojavamobs:melon_seed_projectile
	Index: 1
	Listeners:
		0: NORMAL
		1: ASM: class net.slexom.earthtojavamobs.client.ClientModEventSubscriber onFMLClientSetupEvent(Lnet/minecraftforge/fml/event/lifecycle/FMLClientSetupEvent;)V
java.lang.NullPointerException: Registry Object not present: earthtojavamobs:melon_seed_projectile
	at java.util.Objects.requireNonNull(Objects.java:290)
	at net.minecraftforge.fml.RegistryObject.get(RegistryObject.java:92)
	at net.slexom.earthtojavamobs.client.ClientModEventSubscriber.onFMLClientSetupEvent(ClientModEventSubscriber.java:74)
	at net.minecraftforge.eventbus.ASMEventHandler_4_ClientModEventSubscriber_onFMLClientSetupEvent_FMLClientSetupEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112)
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:135)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool.helpComplete(ForkJoinPool.java:1870)
	at java.util.concurrent.ForkJoinPool.awaitJoin(ForkJoinPool.java:2045)
	at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:404)
	at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734)
	at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583)
	at net.minecraftforge.fml.ModList.lambda$dispatchParallelEvent$11(ModList.java:135)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

[19giu2020 20:58:43.083] [modloading-worker-0/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/LOADING]: Caught exception during event FMLClientSetupEvent dispatch for modid earthtojavamobs
java.lang.NullPointerException: Registry Object not present: earthtojavamobs:melon_seed_projectile
	at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_231]
	at net.minecraftforge.fml.RegistryObject.get(RegistryObject.java:92) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200618-1.15.1-recomp.jar:?]
	at net.slexom.earthtojavamobs.client.ClientModEventSubscriber.onFMLClientSetupEvent(ClientModEventSubscriber.java:74) ~[main/:?]
	at net.minecraftforge.eventbus.ASMEventHandler_4_ClientModEventSubscriber_onFMLClientSetupEvent_FMLClientSetupEvent.invoke(.dynamic) ~[?:?]
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) ~[eventbus-2.2.0-service.jar:?]
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-2.2.0-service.jar:?]
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) ~[?:31.2]
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_231]
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_231]
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) ~[?:?]
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:135) ~[?:?]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[?:1.8.0_231]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) ~[?:1.8.0_231]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[?:1.8.0_231]
	at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291) ~[?:1.8.0_231]
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) ~[?:1.8.0_231]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool.helpComplete(ForkJoinPool.java:1870) ~[?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool.awaitJoin(ForkJoinPool.java:2045) ~[?:1.8.0_231]
	at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:404) ~[?:1.8.0_231]
	at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734) ~[?:1.8.0_231]
	at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160) ~[?:1.8.0_231]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174) ~[?:1.8.0_231]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) ~[?:1.8.0_231]
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[?:1.8.0_231]
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583) ~[?:1.8.0_231]
	at net.minecraftforge.fml.ModList.lambda$dispatchParallelEvent$11(ModList.java:135) ~[?:?]
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [?:1.8.0_231]
[19giu2020 20:58:43.100] [Server-Worker-1/FATAL] [net.minecraftforge.fml.ModLoader/LOADING]: Failed to complete lifecycle event SIDED_SETUP, 1 errors found
[19giu2020 20:58:43.101] [Server-Worker-1/FATAL] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: EventBus 0 shutting down - future events will not be posted.
java.lang.Exception: stacktrace
	at net.minecraftforge.eventbus.EventBus.shutdown(EventBus.java:278) ~[eventbus-2.2.0-service.jar:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:115) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.startModLoading(ClientModLoader.java:123) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$onreload$3(ClientModLoader.java:105) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:113) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626) [?:1.8.0_231]
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1618) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [?:1.8.0_231]
[19giu2020 20:58:43.893] [Forge Version Check/INFO] [net.minecraftforge.fml.VersionChecker/]: [forge] Found status: UP_TO_DATE Current: 31.2.0 Target: null
[19giu2020 20:58:43.894] [Forge Version Check/INFO] [net.minecraftforge.fml.VersionChecker/]: [earthtojavamobs] Starting version check at https://raw.githubusercontent.com/Slexom/earth2java/master/update.json
[19giu2020 20:58:45.573] [Forge Version Check/INFO] [net.minecraftforge.fml.VersionChecker/]: [earthtojavamobs] Found status: UP_TO_DATE Current: 1.3.0 Target: null
[19giu2020 20:59:11.644] [Server-Worker-1/ERROR] [net.minecraftforge.fml.ModLoader/LOADING]: Skipping lifecycle event ENQUEUE_IMC, 1 errors found.
[19giu2020 20:59:11.645] [Server-Worker-1/FATAL] [net.minecraftforge.fml.ModLoader/LOADING]: Failed to complete lifecycle event ENQUEUE_IMC, 1 errors found
[19giu2020 20:59:11.645] [Server-Worker-1/FATAL] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: EventBus 0 shutting down - future events will not be posted.
java.lang.Exception: stacktrace
	at net.minecraftforge.eventbus.EventBus.shutdown(EventBus.java:278) ~[eventbus-2.2.0-service.jar:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:115) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.finishModLoading(ClientModLoader.java:137) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$onreload$4(ClientModLoader.java:107) ~[?:?]
	at java.util.concurrent.CompletableFuture.uniRun(CompletableFuture.java:705) [?:1.8.0_231]
	at java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java:687) [?:1.8.0_231]
	at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [?:1.8.0_231]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [?:1.8.0_231]

 

Entity

public class MelonSeedProjectileEntity extends ProjectileItemEntity {
    public MelonSeedProjectileEntity(EntityType<? extends MelonSeedProjectileEntity> p_i50159_1_, World p_i50159_2_) {
        super(p_i50159_1_, p_i50159_2_);
    }

    public MelonSeedProjectileEntity(World worldIn, LivingEntity throwerIn) {
        super(EntityTypesInit.MelonSeedProjectile.registryObject.get(), throwerIn, worldIn);
    }

    public MelonSeedProjectileEntity(World worldIn, double x, double y, double z) {
        super(EntityTypesInit.MelonSeedProjectile.registryObject.get(), x, y, z, worldIn);
    }

    protected Item getDefaultItem() {
        return Items.MELON_SEEDS;
    }

    @OnlyIn(Dist.CLIENT)
    private IParticleData makeParticle() {
        ItemStack itemstack = this.func_213882_k();
        return (IParticleData) (itemstack.isEmpty() ? ParticleTypes.ITEM_SNOWBALL : new ItemParticleData(ParticleTypes.ITEM, itemstack));
    }

    @OnlyIn(Dist.CLIENT)
    public void handleStatusUpdate(byte id) {
        if (id == 3) {
            IParticleData iparticledata = this.makeParticle();
            for (int i = 0; i < 8; ++i) {
                this.world.addParticle(iparticledata, this.getPosX(), this.getPosY(), this.getPosZ(), 0.0D, 0.0D, 0.0D);
            }
        }
    }

    protected void onImpact(RayTraceResult result) {
        if (result.getType() == RayTraceResult.Type.ENTITY) {
            Entity entity = ((EntityRayTraceResult) result).getEntity();
            int i = entity instanceof MelonGolemEntity ? 4 : 0;
            entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float) i);
        }
        if (!this.world.isRemote) {
            this.world.setEntityState(this, (byte) 3);
            this.remove();
        }
    }
}

 

EntityInit

public class EntityTypesInit {

    ...

    public static final class MelonSeedProjectile {
        public static final String registryName = "melon_seed_projectile";
        public static final RegistryObject<EntityType<MelonSeedProjectileEntity>> registryObject = ENTITY_TYPES.register(
                registryName,
                () -> EntityType.Builder.<MelonSeedProjectileEntity>create(MelonSeedProjectileEntity::new, EntityClassification.MISC)
                        .size(0.25F, 0.25F)
                        .build(new ResourceLocation(EarthtojavamobsMod.MOD_ID, registryName).toString())
        );
    }
 
    ...

}

 

Renderer Register

 @SubscribeEvent
    public static void onFMLClientSetupEvent(final FMLClientSetupEvent event) {

         ...

         RenderingRegistry.registerEntityRenderingHandler(EntityTypesInit.MelonSeedProjectile.registryObject.get(), renderManagerIn -> new SpriteRenderer<MelonSeedProjectileEntity>(renderManagerIn, Minecraft.getInstance().getItemRenderer()));
 
    }

 

Edited by Slexom

My mod:

Earth2Java - Mobs [1.15.2]

 

Posted (edited)

  

18 minutes ago, diesieben07 said:

Where is this coming from and where is it registered?

 

ENTITY_TYPES is the register where I have all the entities.

public class EntityTypesInit {

    public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, EarthtojavamobsMod.MOD_ID);

...

    public static final class MelonSeedProjectile {
        public static final String registryName = "melon_seed_projectile";
        public static final RegistryObject<EntityType<MelonSeedProjectileEntity>> registryObject = ENTITY_TYPES.register(
                registryName,
                () -> EntityType.Builder.<MelonSeedProjectileEntity>create(MelonSeedProjectileEntity::new, EntityClassification.MISC)
                        .size(0.25F, 0.25F)
                        .build(new ResourceLocation(EarthtojavamobsMod.MOD_ID, registryName).toString())
        );
    }
                  
...
                  
}

 

Is called from the mod constructor


@Mod(EarthtojavamobsMod.MOD_ID)
public class EarthtojavamobsMod {

    public static final String MOD_ID = "earthtojavamobs";

    public EarthtojavamobsMod() {
        final ModLoadingContext modLoadingContext = ModLoadingContext.get();
        final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        FluidInit.FLUIDS.register(modEventBus);
        BlockInit.BLOCKS.register(modEventBus);
        EntityTypesInit.ENTITY_TYPES.register(modEventBus); // <--- CALLED HERE
        ItemInit.ITEMS.register(modEventBus);
        RecipesInit.RECIPES.register(modEventBus);
        modEventBus.register(this);
        modEventBus.addListener(this::setup);

        modLoadingContext.registerConfig(ModConfig.Type.CLIENT, ConfigHolder.CLIENT_SPEC);
        modLoadingContext.registerConfig(ModConfig.Type.SERVER, ConfigHolder.SERVER_SPEC);
        modLoadingContext.registerConfig(ModConfig.Type.COMMON, ConfigHolder.COMMON_SPEC);

    }
...
}

 

Edited by Slexom

My mod:

Earth2Java - Mobs [1.15.2]

 

Posted (edited)

  

11 minutes ago, diesieben07 said:

This class is never used before the registry events fire, therefor the entries in it are never registered.

You should use DeferredRegister in one class only, like it is shown in the documentation.

 

 

Ok , I understand why... I'm using classes like the following to organize my entites, they are all inner classes of the EntityTypesInit

 public static final class AlbinoCow {
        public static final String registryName = "albino_cow";
        public static final RegistryObject<EntityType<AlbinoCowEntity>> registryObject = EntityTypesInit.ENTITY_TYPES.register(
                registryName,
                () -> EntityType.Builder.create(AlbinoCowEntity::new, EntityClassification.CREATURE)
                        .size(EntityType.COW.getWidth(), EntityType.COW.getHeight())
                        .build(new ResourceLocation(EarthtojavamobsMod.MOD_ID, registryName).toString())
        );
        public static final int eggPrimaryColor = 0xdecac3;
        public static final int eggSecondaryColor = 0xf0a590;
        public static final String[] spawnBiomes = BiomeSpawnHelper.getBiomesListFromBiomes(BiomeSpawnHelper.PLAINS, BiomeSpawnHelper.MOUNTAINS, BiomeSpawnHelper.GRAVELLY_MOUNTAINS);
    }

They are called when register the spawn in biomes for each entity, but a projectile have no spawn and never been called, so it could be the problem.
I think I've to find another way to organize them.
Thank you so much.

Edited by Slexom

My mod:

Earth2Java - Mobs [1.15.2]

 

Posted
2 hours ago, diesieben07 said:

Static-init dependencies across classes like this are already a bad idea.

If it then relies on happening before a certain point that's even worse.

...which is why deferred registers exist, because people couldn't be bothered to not statically create everything.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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