Sending packets
If something isn't possible in Bullet yet, Bullet allows you to manually send packets to the client(s). For a full understanding of packets and their structures for 1.16.5, read here.
Sending pre-existing packets with custom data
You can easily send packets with custom data by getting a reference to the player you're wanting to send the packet too, you can do this by either finding the player through an event, onEnable()
, whatever, or you have the option to make a for each loop through Bullet.players
, however you want to do it, the process is still the same.
Once you have a reference to your player, all you simply do is call player.sendPacket(...)
. It's that easy, below is an example on sending a client-bound time update packet.
player.sendPacket(ServerTimeUpdatePacket(0L, 0L));
Read the java-docs on the pre-existing packets to understand the parameters, this is just an example and you should probably never manually send the time update packet, as you can just call player.setTimeOfDay(...)
.
Creating custom client-bound packets
Does Bullet not fully implement a packet yet? Don't worry! You can easily make your own packets inside the bullet framework. Again in this example we'll go through the process of making a ServerTimeUpdatePacket even though this already exists. You're able to make any client-bound packet using this method.
This is the example code for the ServerTimeUpdatePacket:
class ServerTimeUpdatePacket(
worldAge: Long,
timeOfDay: Long
) : Packet(0x4E) {
init {
wrapper.writeLong(worldAge)
wrapper.writeLong(timeOfDay)
}
}
There's a few things to go through here, the first being the parameters of the packets. You can again find the structure of packets here and the parameters they accept.
The next thing to go over is the Packet ID, for the time update packet this is 0x4E
, you can again find the packet ID's next to the packet structure.
Next you'll use the init {} in order too actually write things to the client, to do this you use something called a wrapper. All the wrapper is, is a data output stream that sends the information straight to the client. Since the two parameters in the ServerTimeUpdatePacket are both longs, we can simply say wrapper.writeLong()
twice. For parameters that the data output stream does not support by default, like UUID's, VarInts, etc, bullet has special functions for that, you should be able to access them by just doing wrapper.writeVarInt(...)
.
And that's it, it's that easy to make a client-bound packet. Now wherever you want to send it, you can just call player.sendPacket()
.
Last updated