Jump to content

Recommended Posts

Posted (edited)

Hey guys,

 

So, I'm creating a mod that uses code from another mod (using build.gradle to put it into my build path). One of my event handlers listens for an event made by the other mod. For the longest time, I wasn't able to get it to work, until I realised that the other mod had it's own EVENT_BUS made and posted their events on that bus instead of the one created by MinecraftForge. So, I registered my event handler using the other mod's bus and finally managed to get it working... in single player, that is.

 

The main problem comes when I test it on a server. When I entered a server (a pre-existing one, not a test server), the event handler doesn't get called at all. My initial suspicions were that, although I did register the handler on the mod bus, it didn't actually register on the server, so I made my handler hook to a general Event class and printed out the argument passed to it to see if it caught any event posted by the mod at all and it did catch some Effects and other events. So now my main suspicion is that the event I'm trying to hook is being posted on the server instead of the client. Should I use packets or just create my own test server? Or is there something else I'm missing.

 

I created my Event Handlers on a separate class and registered them at Pre-Init in my @Mod class. To reiterate, the event handler works, but only in SP. It's a really simple setup but if you still want to see my code then I'll gladly post it.

Edited by Lennos
Posted
1 hour ago, Lennos said:

see my code

That would be great

Have you tried looking at the other mod and seeing if they post it on the client & server?

What’s the other mod?

1 hour ago, Lennos said:

Event Handlers

I assume you mean EventSubscribers?

 

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

The mod I'm using is Pixlemon.

 

Ok so here's the code for Pre-Init:

@EventHandler
public void PreInit(FMLPreInitializationEvent event) {
	if (Loader.isModLoaded("pixelmon") {
		Pixelmon.EVENT_BUS.register(new PxEventHandler());
	}
}

I've made Pixelmon a soft dependency, so you don't need to have it installed in order for this mod to work.

 

And here's PxEventHandler:

public class PxEventHandler {
	
	@SubscribeEvent
	public void checkIfFlying(RidePokemonEvent event) {
		System.out.println("Event hooked: " + event);
	}
}

 

RidePokemonEvent is posted when you right click on a rideable pixelmon. The post statement is located in a class that indirectly extends the EntityTameable class in net.minecraft.entity.passive. Other than that, I can't really tell if the code is server or client code. A good portion of it is still obfuscated and I don't wanna say anymore than I already have since Pixelmon isn't open source (I'm using the latest version of Pixelmon Reforged, btw).

 

Another note, when the event handler is called on SP, on the console, the println statement is prefixed by something like this:

Quote

[21:44:07] [Server thread/INFO] [STDOUT]:

So I'm guessing this means that RidePokemonEvent is posted on the server?

Edited by Lennos
Posted

Can you see where the event gets called from?

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

The entire println outputs this:

Quote

[time] [Server thread/INFO] [STDOUT]: [mymod.util.handlers.PxEventHandler:checkIfFlying:29]: Event thrown: com.pixelmonmod.pixelmon.api.events.RidePokemonEvent@[hashcode]

 

I don't really know what you mean by where the event gets called from, but this statement should show you which package the event belongs to.

Posted
On 12/27/2018 at 2:32 AM, diesieben07 said:

Yes, the event is fired on the server, as you can see from the line in the log ("Server thread"). So yes, you need your mod to be installed on the server.

Thank you, that's all I need to know.

 

On 12/27/2018 at 2:32 AM, diesieben07 said:

Moreover, your code to check for the other mod is not sufficient, you cannot have hard-references to your mod-specific classes from your main mod class, you need to use reflection to access them, otherwise you might still get exceptions due to missing classes.

That's good to know, thanks. Will get right into it.

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.