Jump to content

[1.13.2] Events not firing


Meldexun

Recommended Posts

Hello there,

i want to use some events in my mod but all of them don't seem to work.

So this is an example class:

@EventBusSubscriber(modid = BetterDiving.MOD_ID)
public class Test {
    
    @SubscribeEvent
    public static void test1(PlayerInteractEvent.RightClickEmpty e) {
        System.out.println("Test1");
    }
    
    @SubscribeEvent
    public static void test2(LivingUpdateEvent e) {
        System.out.println("Test2");
    }
    
}

ย 

Am i missing something?

Edited by Meldexun
Link to comment
Share on other sites

Okay, that wasn't the issue. Just another problem.

The problem was that i had a static ResourceLocation in one of my event classes. So when you have a class with the EventBusSubscriber annotation and inside it a static ResourceLocation it will prevent all events from firing.

That would be an example class:

@EventBusSubscriber(modid = TestMod.MOD_ID)
public class Test {
	
	public static ResourceLocation TEST = new ResourceLocation(TestMod.MOD_ID, "test");
	
}

ย 

Link to comment
Share on other sites

4 hours ago, diesieben07 said:

Yeah, no. This is not a thing at all.

I know it sounds like i'm just dumb. But these are my classes:

Mod class:

package meldexun.better_diving;

import net.minecraftforge.fml.common.Mod;

@Mod(BetterDiving.MOD_ID)
public class BetterDiving {
	
	public static final String MOD_ID = "better_diving";
	
}

ย 

Event class 1:

package meldexun.better_diving;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

@EventBusSubscriber(modid = BetterDiving.MOD_ID)
public class Event1 {
	
	public static final ResourceLocation DIVING_VALUES = new ResourceLocation(BetterDiving.MOD_ID, "divingValues");
	
}

ย 

Event class 2:

package meldexun.better_diving;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

@EventBusSubscriber(modid = BetterDiving.MOD_ID)
public class Event2 {
	
	@SubscribeEvent
	public static void test(LivingUpdateEvent e) {
		if (e.getEntity() instanceof EntityPlayer) {
			System.out.println("test");
		}
	}
	
}

ย 

When launching the game like this i never see the "test" from the LivingUpdateEvent.

But when removing the ResourceLocation from the Event class 1 i get the "test" in the console.

Edited by Meldexun
Link to comment
Share on other sites

Look at the code that creates event subscribers. There is nothing at all that deals with unsubscribing stuff with a resource location field.

About Me

Spoiler

My Discordย -ย Cadiboo#8887

My Website -ย Cadiboo.github.io

My Mods -ย Cadiboo.github.io/projects

My Tutorials -ย Cadiboo.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

6 hours ago, Cadiboo said:

Look at the code that creates event subscribers. There is nothing at all that deals with unsubscribing stuff with a resource location field.

Well I'm just saying what is happening. These are the only 3 classes in my mod and only when i remove the ResourceLocation i get the "test" printed in the console. I really would like to understand what is causing this.

Link to comment
Share on other sites

Almost certainly something else is happening. After removing the line, and it works, add the line back, touch nothing else. Does it break again? Try commenting the line instead of removing it. Try changing the strings being passed to the resource location. Make it private. Don't make it static.

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.

Link to comment
Share on other sites

59 minutes ago, Meldexun said:

Ok, i think i found it. I had a capital letter in my ResourceLocation which only gives an error but no crash and prevents the events from being subscribed.

Yes, because when it errors it stops loading your mod for being improperly formatted. This is not a "stop the presses and burn down the building" error, its a "throw the drunk out" error.

Edited by Draco18s
  • Haha 2

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.

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