Views
Actions
Difference between revisions of "Using FriendlyByteBuf"
(Created page with "<code>PacketBuffer</code>s are essentially a byte array of zero or more bytes to sync information across a network. It works similarly to a queue: the information is written i...") |
m (ChampionAsh5357 moved page Using FriendlyByteBuf to Using FriendlyByteBuf: Class rename) |
(No difference)
|
Revision as of 18:26, 2 August 2021
PacketBuffer
s are essentially a byte array of zero or more bytes to sync information across a network. It works similarly to a queue: the information is written in to a specific order and read in the order it was written.
Using PacketBuffer
s
In most cases, one will use a premade PacketBuffer
passed in from some network. Most of the time this is a heap buffer of some sort; however, understanding how it works is best left as an explanation of data structures.
When you are writing
to a PacketBuffer
, you are calling one of the many write functions to store information as bytes (e.g. writeBlockPos
or writeVarInt
). There are a couple of helpers for objects like CompoundNBT
, ItemStack
s, etc. if they are needed.
When you are reading
from a PacketBuffer
, you are calling the equivalent read function in the same order. For example, if you call writeBlockPos
and then writeVarInt
, you would call readBlockPos
and then readVarInt
in that order. Each of these method returns the value from the buffer.