Jump to content

Recommended Posts

Posted

Hi, just wondering if there are any events that are triggered once a packet is sent/recieved?

 

There are many things that I would like to do with this functionality, such as measuring a servers tickrate based on counting the frequency of server update packets.

 

If these events do not exist, is there another way to do it like each tick seeing each packet that is going to be sent during that tick?

 

Thanks

  • 2 weeks later...
Posted

For anyone else looking for this in the future, create mixins for net.minecraft.network.NetworkManager like so:

@Inject(method = "sendPacket(Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
private void onSendPacket(Packet<?> packet, CallbackInfo callbackInfo)
{
	//System.out.println("Packet Sent: " + packet.toString());
	PacketSent event = new PacketSent(packet);
	MinecraftForge.EVENT_BUS.post(event);
	if (event.isCanceled() && callbackInfo.isCancellable())
	{
		callbackInfo.cancel();
	}
	packet = event.packet;
}
	
@Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true)
private void onChannelRead(ChannelHandlerContext context, Packet<?> packet, CallbackInfo callbackInfo)
{
	//System.out.println("Packet Recieved: " + packet.toString());
	PacketRecieved event = new PacketRecieved(packet);
	MinecraftForge.EVENT_BUS.post(event);
	if (event.isCanceled() && callbackInfo.isCancellable())
	{
		callbackInfo.cancel();
	}
	packet = event.packet;
}

PacketSent and PacketRecieved are custom events that you can make yourself by making a class that extends Event.

  • Like 2
Posted

Best thing would be to not mess with it at all, may I ask why you need to interact with Vanilla packets?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted
  On 8/16/2019 at 11:39 PM, DaemonUmbra said:

Best thing would be to not mess with it at all, may I ask why you need to interact with Vanilla packets?

Expand  

Scroll up. Also I don’t understand why me literally offering helpful advice to other people coming across this is met with “that’s a shit method” and “don’t mess with it at all”. Like geez, if you know a better way then feel free to contribute, but simply getting complaining isn’t contributing anything.

  • Like 1
Posted

Because the best case for checking server tickrate would be to make your mod check the tickrate on the server side and send that info to your mod on the client side.

I don't understand this fascination with manipulating vanilla packets when having a server component of your mod is far safer and more reliable.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted
  On 8/16/2019 at 11:20 PM, cookiedragon234 said:

I’d welcome any examples of a better way to do this?

Expand  
  On 8/4/2019 at 5:08 PM, diesieben07 said:

There are ways to listen to packets. But it's usually a really bad idea because you can break things. If you dig into the code it's pretty easy to figure out what to do though. Hint: Netty. 

Expand  

Huh I wonder who gave you advice you just ignored.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 8/16/2019 at 11:49 PM, DaemonUmbra said:

Because the best case for checking server tickrate would be to make your mod check the tickrate on the server side and send that info to your mod on the client side.

 I don't understand this fascination with manipulating vanilla packets when having a server component of your mod is far safer and more reliable.

Expand  

The mod is designed to be client side only

Posted (edited)
  On 8/17/2019 at 2:49 AM, Animefan8888 said:

Huh I wonder who gave you advice you just ignored.

Expand  

Yes, and the mixin I just described is mixing into the netty networkmanager. I know its netty because when printing from the network manager it tells me that it is in the "netty" thread. I did dig into the code, and I found the class from which packets are sent and recieved, so I made a mixin to intercept the function calls.

Edited by cookiedragon234

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.