Meldexun Posted June 22, 2019 Posted June 22, 2019 (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 June 23, 2019 by Meldexun Quote
Meldexun Posted June 23, 2019 Author Posted June 23, 2019 On 6/23/2019 at 11:41 AM, diesieben07 said: Which is not working? How did you test it? Expand 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. Quote
Meldexun Posted June 23, 2019 Author Posted June 23, 2019 After testing my mod with only the mod class and the event test class i noticed that i forgot to register my capability. Still thank you for trying to help. Quote
Meldexun Posted June 23, 2019 Author Posted June 23, 2019 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"); } Quote
Meldexun Posted June 23, 2019 Author Posted June 23, 2019 (edited) On 6/23/2019 at 3:13 PM, diesieben07 said: Yeah, no. This is not a thing at all. Expand 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 June 23, 2019 by Meldexun Quote
Cadiboo Posted June 24, 2019 Posted June 24, 2019 Look at the code that creates event subscribers. There is nothing at all that deals with unsubscribing stuff with a resource location field. Quote About Me Reveal hidden contents 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)
Meldexun Posted June 24, 2019 Author Posted June 24, 2019 On 6/24/2019 at 2:54 AM, 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. Expand 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. Quote
Draco18s Posted June 24, 2019 Posted June 24, 2019 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. Quote 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.
Meldexun Posted June 24, 2019 Author Posted June 24, 2019 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. Quote
Draco18s Posted June 24, 2019 Posted June 24, 2019 (edited) On 6/24/2019 at 3:03 PM, 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. Expand 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 June 24, 2019 by Draco18s 2 Quote 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.
Recommended Posts
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.