Jump to content

Event Handler working in SP but not on a Server


Lennos

Recommended Posts

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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, I'm trying to render a single quad in the world. I'm mixing into the ChestRenderer class. If I understand correctly, BufferSource#getBuffer opens a buffer according to the supplied RenderType (Quads with POSITION_COLOR in my case). Then, I can supply my vertices (a simple 1-block plane along the Z Axis) and close the buffer using BufferSource#endBatch for rendering. This is the code I'm using: @Inject(at = @At("TAIL"), method = "render(...)V") public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, CallbackInfo ci) { BlockPos pos = blockEntity.getBlockPos(); AABB box = new AABB(pos, pos.offset(1, 1, 1)); BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource(); VertexConsumer consumer = buffer.getBuffer(RenderType.guiOverlay()); poseStack.pushPose(); poseStack.translate(-pos.getX(), -pos.getY(), -pos.getZ()); consumer.vertex(box.minX, box.maxY, box.minZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.maxY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.minZ).color(1, 1, 1, 1).endVertex(); buffer.endBatch(RenderType.guiOverlay()); poseStack.popPose(); } However, the plane does not get rendered. However, if I replace those 4 vertices with a call to LevelRenderer#renderLineBox and set the RenderType to LINES, it works. Do I need something else to render planes other than the 4 edges of the quad? I used QUADS back in 1.8 where it was still the raw OpenGL type and it worked then. Or am I missing something else entirely? Thanks!
    • The Essential Role of Brunoe Quick Hack in Bitcoin Recovery Efforts The Brunoe Quick Hack has emerged as a vital tool in the ongoing efforts to recover lost or stolen Bitcoin. As the cryptocurrency landscape has evolved, the need for reliable and effective methods to regain access to misplaced or compromised digital assets has become increasingly pressing. The Brunoe Quick Hack, a specialized software solution, has stepped in to fill this critical void, offering Bitcoin users a lifeline when faced with the devastating prospect of permanently losing their hard-earned cryptocurrency holdings. At the core of this innovative technique lies a deep understanding of the underlying blockchain technology that powers Bitcoin, combined with a meticulous, methodical approach to identifying and exploiting vulnerabilities in the system. Through a series of carefully orchestrated steps, the Brunoe Quick Hack is able to bypass security measures, recover private keys, and restore access to Bitcoin wallets that were previously thought to be irretrievable. This process, while highly technical and requiring a skilled hand, has proven to be a game-changer for countless individuals and businesses who have fallen victim to the inherent risks of the cryptocurrency ecosystem. As the adoption of Bitcoin continues to grow, the Brunoe Quick Hack has emerged as an essential safeguard, providing a crucial safety net for those navigating the complex and ever-evolving world of digital finance. Contact this experts through: WhtasApp: + 170-"578-42"-635 Website: brunoequickhack.COM Email: brunoequickhack (AT) GMAIL (DOT) COM Thanks.
    • it doesnt let me import the zip that i use with curseforge
    • it doesnt let me import the zip that i use with curseforge
    • Halo semua, Kembali lagi bersama kami di situs Duta89 situs Aman, Terpercaya dan Situs yang memberikan hadiah terbesar kepada semua membernya. Pada kesempatan kali ini kami akan memberi tahu kalian semua mengenai situs permainan online yang bisa menghasilkan uang dengan cepat hanya dengan modal receh. Permainan apa kah itu? Saran bukan? >>>akungameaman<<< >>>akunminecrafsuper<<< >>>daftarsitus<<<
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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