Jump to content

Recommended Posts

Posted (edited)

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
Posted
6 minutes ago, diesieben07 said:

Which is not working? How did you test it?

All of the events never seem to work. I have added this class to my mod and i never see "Test1" or "Test2" when playing ingame.

Posted

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");
	
}

 

Posted (edited)
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
Posted

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 WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

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

Posted

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.

Posted (edited)
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.

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.