Jump to content

Recommended Posts

Posted

Hi,

I'm trying to register a custom MobEffect, but when the mod load it seams to not have the MobEffect to be registered. The forge version is the 40.2.1

"Main" class

@Mod(MODID)
public class BetterArmor
{
    //region Constructor
    public BetterArmor()
    {
        // Register the setup method for modloading
        IEventBus eventBus=FMLJavaModLoadingContext.get().getModEventBus();

        CustomEffectsRegistry.register(eventBus);
        BetterArmorRegistryItems.register(eventBus);

        eventBus.addListener(this::setup);
        
        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }
  ...
}

Class that hold references and register the effect

public class CustomEffectsRegistry
{
	public static void register(IEventBus eventBus)
	{
		MOB_EFFECTS.register(eventBus);
	}

	public static final DeferredRegister<MobEffect> MOB_EFFECTS= DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, BetterArmor.MODID);
	public static RegistryObject<MobEffect> FLY=MOB_EFFECTS.register("fly", ()->new FlyingEffect(MobEffectCategory.BENEFICIAL, 3124687));

}

Effetcs class

public class FlyingEffect extends MobEffect
{
	public FlyingEffect(MobEffectCategory mobEffectCategory, int color)
	{
		super(mobEffectCategory, color);
	}
	
	@Override
	public void applyEffectTick(LivingEntity livingEntity, int amplifier)
	{
		...
	}

	@Override
	public boolean isDurationEffectTick(int p_19455_, int p_19456_)
	{
		//return super.isDurationEffectTick(p_19455_, p_19456_);
		return true;
	}
}

There's a method where I use the effect and where it gives me an excpetion(seems that Items are registerd before MobEffects)


	private static ArrayList<MobEffectInstance> buildEffectsArray()
	{
		ArrayList<MobEffectInstance> effects=new ArrayList<>();
		effects.add(new MobEffectInstance(MobEffects.NIGHT_VISION, BaseMultipliers.BASETIMER, 50));
		effects.add(new MobEffectInstance(CustomEffectsRegistry.FLY.get(), 200, 5));
		return effects;
	}

There's the exception

Spoiler

[Render thread/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: null
    Index: 2
    Listeners:
        0: NORMAL
        1: ASM: net.minecraftforge.registries.DeferredRegister$EventDispatcher@4bb8dbe3 handleEvent(Lnet/minecraftforge/event/RegistryEvent$Register;)V
        2: ASM: net.minecraftforge.registries.DeferredRegister$EventDispatcher@316b043 handleEvent(Lnet/minecraftforge/event/RegistryEvent$Register;)V
java.lang.ExceptionInInitializerError
    at TRANSFORMER/[email protected]/com.redox.betterarmor.item.BetterArmorRegistryItems.lambda$static$12(BetterArmorRegistryItems.java:54)
    at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister.lambda$register$0(DeferredRegister.java:214)
    at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister.addEntries(DeferredRegister.java:446)
    at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.handleEvent(DeferredRegister.java:376)
    at net.minecraftforge.eventbus.ASMEventHandler_0_EventDispatcher_handleEvent_Register.invoke(.dynamic)
    at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
    at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
    at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:106)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:107)
    at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModWorkManager$SyncExecutor.driveOne(ModWorkManager.java:42)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModWorkManager$DrivenExecutor.drive(ModWorkManager.java:26)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:202)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$21(ModLoader.java:187)
    at java.base/java.util.Optional.ifPresent(Optional.java:178)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:187)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$11(ModLoader.java:164)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:164)
    at TRANSFORMER/[email protected]/net.minecraftforge.client.loading.ClientModLoader.lambda$begin$1(ClientModLoader.java:92)
    at TRANSFORMER/[email protected]/net.minecraftforge.client.loading.ClientModLoader.lambda$createRunnableWithCatch$4(ClientModLoader.java:112)
    at TRANSFORMER/[email protected]/net.minecraftforge.client.loading.ClientModLoader.begin(ClientModLoader.java:92)
    at TRANSFORMER/[email protected]/net.minecraft.client.Minecraft.<init>(Minecraft.java:459)
    at TRANSFORMER/[email protected]/net.minecraft.client.main.Main.main(Main.java:169)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:24)
    at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
    at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53)
    at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71)
    at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:106)
    at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:77)
    at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)
    at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)
    at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149)
Caused by: java.lang.NullPointerException: Registry Object not present: betterarmor:fly
    at java.base/java.util.Objects.requireNonNull(Objects.java:334)
    at TRANSFORMER/[email protected]/net.minecraftforge.registries.RegistryObject.get(RegistryObject.java:320)
    at TRANSFORMER/[email protected]/com.redox.betterarmor.item.armor.effects.effectsapplicators.DragonArmorEffects.buildEffectsArray(DragonArmorEffects.java:43)
    at TRANSFORMER/[email protected]/com.redox.betterarmor.item.armor.effects.effectsapplicators.DragonArmorEffects.<clinit>(DragonArmorEffects.java:47)
    ... 38 more

 

 

Posted
Quote

seems that Items are registerd before MobEffects

Yes.

 

See the recent discussion here or one of the many others in this forum about using Suppliers (deferred access)

https://forums.minecraftforge.net/topic/123444-forge-error-on-run/?do=findComment&comment=536470

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted (edited)

I read the doc on why DeferredRegister gives me null. But now I don't understand how to fix that.

It says:

When using DeferredRegisters with non-vanilla registries, the registry key or the registry name should be supplied to the create method. These include the custom Forge registries for entity data serializers, global loot modifier serializers, world presets, and biome modifier serializers. Calling Supplier#get on a Supplier<IForgeRegistry<?>> when making a DeferredRegister will return null because the registry does not exist yet.

So I have to change the create with registry key or registry name, but I have not understand how, cause I've not completely understand what these two objects are for, and how I have to pass to the create method.

Edited by rEDOx_
More explicitly
Posted (edited)

Read the link I posted.

 

Repeating that and many other posts:

Instead of storing the MobEffect directly in the item, store the RegistryObject<MobEffect> or Supplier<MobEffect> and only use get() on that when you actually need it.

A RegistryObject is just a utility object that does all the Registry/ResourceKey/ResourceLocation handling for you and probably more efficiently than you can write it by hand.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

It works like this:

public class CustomEffectsRegistry
{
	public static void register(IEventBus eventBus)
	{
		MOB_EFFECTS.register(eventBus);
	}

	public static final DeferredRegister<MobEffect> MOB_EFFECTS=DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, BetterArmor.MODID);
	public static final FlyingEffect flyingEffect=new FlyingEffect(MobEffectCategory.BENEFICIAL, 3124687);
	public static RegistryObject<MobEffect> FLY_REGISTERED_OBJECT=MOB_EFFECTS.register("fly", ()->flyingEffect);
}

I reference to the object "flyingEffect", is that the "correct way"?

I'm still searching in forum for other posts and in the link you provided. You said that I have not to store MobEffect directly into the item, and I thought I wasn't doing that. I stored the output of .register method in RegistryObject and call it.

Edit:

I tried to call .get() on the "FLY_REGISTERED_OBJECT" in an event fired at runtime and it works. So basically the problem is that a static allocation that imply the call of .get() perform on a not yet created entry. Is this correct? The code up here(and it's consequent use) seemed i bit verbose. 

Posted
Quote

public static final FlyingEffect flyingEffect=new FlyingEffect(MobEffectCategory.BENEFICIAL, 3124687);

public static RegistryObject<MobEffect> FLY_REGISTERED_OBJECT=MOB_EFFECTS.register("fly", ()->flyingEffect);

That is not how you defer object construction. That creates the object during class initialisation, could be called anytime.

 

This creates the object when forge calls the supplier.get() at the correct time for registration

public static RegistryObject<MobEffect> FLY_REGISTERED_OBJECT=MOB_EFFECTS.register("fly", () -> new FlyingEffect(MobEffectCategory.BENEFICIAL, 3124687));

 

You need to make sure you understand how suppliers (deferred code) work. They are used everywhere by forge and vanilla.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted (edited)

I already read the page on registries in doc.

Think I understand where the problem is. Basically The initial code was correct for registries initialization. The problem was that I called the .get() method in a method of a class that extend ArmorItem, the Items are registered before the MobEffect.

Edited by rEDOx_

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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