Packet handling
The event of receiving or sending a packet.
This event allows you to receive a packet sent by the player or sent by the server to the player.
on packet:
on packet <packet name>:
<packet name>
- allows you to specify the name of the tracking packet.
The event can be canceled. In this case, the packet will not be received by the server, or sent to the player
This event has built-in expressions.
event-packet
- to receive the packetevent-player
- to get a player
event-packet
it can be replaced with set event-packet to %packet%
, provided that no execution delay was used
Getting a buffer from a packet
After receiving the buffer from the packet, we can read the fields indicated on wiki.vg
buffer (of|from) %packet%
%packet%'s buffer
Reading the buffer
To get values from the buffer, the following expressions exist, similar to writing to the buffer
read bool[ean] from %bytebuf%
read uuid from %bytebuf%
read string from %bytebuf%
read position from %bytebuf%
read [unsigned] byte from %bytebuf%
read [unsigned] short from %bytebuf%
read float from %bytebuf%
read double from %bytebuf%
read int[eger] from %bytebuf%
read long from %bytebuf%
read angle from %bytebuf%
read var[iable][ ]int[eger] from %bytebuf%
read var[iable][ ]long from %bytebuf%
read utf[(-| )]8 [with [len[gth]]] %number% from %bytebuf%
To read utf-8 you must also specify the length of the text in bytes
Consider the packet PacketPlayOutOpenSignEditor
Packet ID | State | Bound To | Field Name | Field Type | Notes |
---|---|---|---|---|---|
0x32 | Play | Client | Location | Position | |
Is Front Text | Boolean | Whether the opened editor is for the front or on the back of the sign |
on packet PacketPlayOutOpenSignEditor:
set {_buffer} to buffer from event-packet
set {_position} to read position from {_buffer}
set {_isFrontText} to read boolean from {_buffer}
broadcast "%{_position}%"
cancel event
The code above will display a Vector with the coordinates of the open plate in the chat.
Reader index
Each reading of the buffer shifts its Reader index
, this is the number of bytes read inside the buffer.Reader index
you can find out or change it using the following expression:
reader index of %bytebuf%
%bytebuf%'s reader index
Disabling or enabling packet handling
For any player, you can enable or disable tracking of incoming or outgoing packets.
[(handl(e|ing))|(listen[ing] [of])] (in|out)coming packets of %player%
%player%'s [(handl(e|ing))|(listen[ing] [of])] (in|out)coming packets