Skip to content

PacketByteBufferHelper ​

com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper

Since1.8.4

Reads and writes typed values in a packet buffer; callers must use the packet's field order and matching read/write operations.

Packet-event buffers contain encoded packet data; Client.createPacketByteBuffer() creates a fresh buffer. Changes to a packet-event buffer do not change the packet object.
reset() restores the captured bytes and reader position (normally the start for a packet-backed helper); use it when you need to reread or decode from that captured position.

Supported standalone packets can be decoded using their registered codecs. Packet-backed helpers remember their network phase; overloads taking a protocol select a phase explicitly.
Conversion reads from the current reader position, so reset after inspecting a packet before decoding its untouched bytes. receivePacket() handles the original packet object,
whereas its named and class overloads decode the buffer first.

ts
const payload = Client.createPacketByteBuffer();  
payload.writeString("hello").writeVarInt(42);  
Chat.log(`${payload.readString()} and ${payload.readVarInt()}`);

Constructors ​

new PacketByteBufferHelper ​

new PacketByteBufferHelper()#
Creates a fresh buffer with no originating packet and the default play phase. Captures its initial contents for reset().
new PacketByteBufferHelper(FriendlyByteBuf base)#
Uses the supplied buffer directly as its working buffer and captures a separate copy of its initial contents for reset(). This helper has no originating packet and uses the default play phase.

Parameters:

  • base: the non-null buffer to wrap
new PacketByteBufferHelper(Packet<?> packet)#
Encodes a packet using its selected phase's standalone codec and retains the packet as the helper's origin; this does not send or handle the packet. The encoded contents are captured for reset(). The current connection phase is preferred when registered for the packet; otherwise its sole registered phase is selected. Unknown packets or packets with ambiguous phases throw IllegalArgumentException; a missing standalone codec also throws IllegalArgumentException.

Parameters:

  • packet: the non-null packet to encode
new PacketByteBufferHelper(Packet<?> packet, String protocol)#
Encodes a packet using the standalone codec for the specified network phase.

Parameters:

  • packet: the packet to encode
  • protocol: the network phase, such as play or configuration

Fields ​

BUFFER_TO_PACKET ​

static BUFFER_TO_PACKET: Map<Class<? extends Packet<?>>, Function<FriendlyByteBuf, ? extends Packet<?>>>read-only#
the lookup table that turns a buffer back into a packet. Don't touch this here! Populated by init() for packet classes with supported standalone codecs. toPacket(Class) uses it for play-phase decoding; explicit phase decoding selects the matching codec directly.

Methods ​

canSerialize ​

static canSerialize(Packet<?> packet): booleanSince2.0.0#
Checks whether the packet has a standalone codec for the phase selected as in PacketByteBufferHelper(Packet). Returns false for null, unknown packets, ambiguous phase selection, or missing codecs; it does not test whether encoding the packet's contents will succeed.

Parameters:

  • packet: the packet to check, or null
Returns: whether the packet has a supported standalone codec

clear ​

clear(): PacketByteBufferHelperSince1.8.4#
Resets the writers and readers index to 0. This technically doesn't clear the buffer, but rather makes it so that new operations will overwrite the old data.
Returns: self for chaining.

forEachInCollection ​

forEachInCollection(MethodWrapper<FriendlyByteBuf, ?, Object, ?> reader): PacketByteBufferHelperSince1.8.4#

Parameters:

  • reader: the function to read the collection's elements from the buffer
Returns: self for chaining.

getBoolean ​

getBoolean(int index): booleanSince1.8.4#
Reads a byte at the given index without changing the reader index.

Parameters:

  • index: the index to read from
Returns: the boolean value at the given index.

getByte ​

getByte(int index): byteSince1.8.4#

Parameters:

  • index: the index to read from
Returns: the byte at the given index.

getBytes ​

getBytes(int index, int length): byte[]Since1.8.4#

Parameters:

  • index: the index to start reading from
  • length: the length of the array to read
Returns: the bytes at the specified index; the reader index is unchanged

getChar ​

getChar(int index): charSince1.8.4#
Reads an unsigned byte at the given index without changing the reader index.

Parameters:

  • index: the index to read from
Returns: the char at the given index.

getDouble ​

getDouble(int index): doubleSince1.8.4#

Parameters:

  • index: the index to read from
Returns: the double at the given index.

getFloat ​

getFloat(int index): floatSince1.8.4#

Parameters:

  • index: the index to read from
Returns: the float at the given index.

getInt ​

getInt(int index): intSince1.8.4#

Parameters:

  • index: the byte index to read from
Returns: the integer at that index.

getLong ​

getLong(int index): longSince1.8.4#

Parameters:

  • index: the index to read from
Returns: the long at the given index.

getMedium ​

getMedium(int index): intSince1.8.4#

Parameters:

  • index: the byte index to read from
Returns: the signed medium at that index.

getNetworkStateId ​

getNetworkStateId(Class<? extends Packet<?>> packetClass): intSince1.8.4#
which network state a packet class belongs to, in the game's own numbering. This overload requires the packet class to occur in exactly one protocol. Use getNetworkStateId(Class, String) for a class shared between phases. The state is which part of the connection a packet belongs to — logging in, playing, or configuring — and it is why a packet cannot simply be read on the wrong one.

Parameters:

  • packetClass: the class of the packet to get the id for
Returns: the ordinal of the registered connection protocol
getNetworkStateId(Class<? extends Packet<?>> packetClass, String protocol): int#
Returns the ordinal of the requested protocol for a packet registered in it. Throws IllegalArgumentException if the protocol is unknown or the packet is not registered in it.

Parameters:

  • packetClass: the packet class
  • protocol: the protocol identifier or name
Returns: the requested protocol's ordinal

getPacketId ​

getPacketId(Class<? extends Packet<?>> packetClass): intSince1.8.4#
Returns the packet ID registered for the packet class. The ID is specific to the protocol and direction, and may change across Minecraft versions; if the class is registered in multiple protocols, use getPacketId(Class, String).

Parameters:

  • packetClass: the class of the packet to get the id for
Returns: the ID registered for the packet class
getPacketId(Class<? extends Packet<?>> packetClass, String protocol): int#
Returns the packet ID registered for the requested protocol (for example, "play" or "configuration"). Throws IllegalArgumentException if the protocol is unknown or the packet is not registered in it.

Parameters:

  • packetClass: the packet class
  • protocol: the protocol identifier or name
Returns: the registered packet ID

getPacketName ​

static getPacketName(Packet<?> packet): StringSince1.8.4#
Returns the shortcut name for a packet, or its simple class name when no shortcut is registered. The returned name is also used as packet-event type and accepted by packet filterers.

Parameters:

  • packet: the packet to name
Returns: the packet's shortcut name, or its simple class name if none is registered

getPacketNames ​

getPacketNames(): List<String>Since1.8.4#
Returns the convenience names registered for packet classes. Names are also used as packet-event type values and by filterer setType. Most encode direction in an S2C or C2S suffix, but this is a naming convention, not authoritative direction metadata; use isClientbound(Class) or isServerbound(Class) when available. Names are convenience aliases and may change. getPacketName(Packet) can return a class's simple name when that class has no registered alias.
Returns: a list of all packet names.

getShort ​

getShort(int index): shortSince1.8.4#
Reads a short at the given index without changing the reader index.

Parameters:

  • index: the index to read from
Returns: the short at the given index.

getUnsignedByte ​

getUnsignedByte(int index): shortSince1.8.4#

Parameters:

  • index: the index to read from
Returns: the unsigned byte at the given index, represented as a short.

getUnsignedInt ​

getUnsignedInt(int index): longSince1.8.4#

Parameters:

  • index: the byte index to read from
Returns: the unsigned integer at that index, represented as a long.

getUnsignedMedium ​

getUnsignedMedium(int index): intSince1.8.4#

Parameters:

  • index: the byte index to read from
Returns: the unsigned medium at that index.

getUnsignedShort ​

getUnsignedShort(int index): intSince1.8.4#
Reads an unsigned short at the given index without changing the reader index.

Parameters:

  • index: the index to read from
Returns: the unsigned short at the given index, represented as an int.

init ​

static init(): void#
Populates convenience packet-name mappings and registers packet IDs, directions, and supported standalone play-phase decoders using reflection. Reflective lookup failures may cause an IllegalStateException.

isClientbound ​

isClientbound(Class<? extends Packet<?>> packetClass): booleanSince1.8.4#
whether a packet class is one the server sends to the client. Reads the registered packet direction rather than inferring it from a convenience name. A name is the practical test for this: getPacketNames() ends almost every clientbound one with S2C and every serverbound one with C2S, and the event's type is that same name.

Parameters:

  • packetClass: the class to get the side for
Returns: true if the packet is clientbound, false if it is serverbound

isServerbound ​

isServerbound(Class<? extends Packet<?>> packetClass): booleanSince1.8.4#
whether a packet class is one the client sends to the server. This is the exact opposite of isClientbound(Class) for a registered packet class.

Parameters:

  • packetClass: the class to get the id for
Returns: true if the packet is serverbound, false if it is clientbound

main ​

static main(String[] args): void#
Runs the packet-mapping generator: initializes mappings, scans legacy packet classes on the class path (including declared nested classes), and prints missing PACKETS.put lines to standard output. Class-path scanning can fail with IOException; arguments are ignored.

Parameters:

  • args: ignored command-line arguments

markReaderIndex ​

markReaderIndex(): PacketByteBufferHelperSince1.8.4#
Marks the readers current index for later use.
Returns: self for chaining.

See:

markWriterIndex ​

markWriterIndex(): PacketByteBufferHelperSince1.8.4#
Marks the current writer index for later use by resetWriterIndex().
Returns: self for chaining.

preferredProtocol ​

static preferredProtocol(Packet<?> packet, ConnectionProtocol current): String#
Selects a registered phase for the packet, preferring current when registered. If no current phase applies, selects the sole registered phase; throws IllegalArgumentException for an unknown packet or when multiple phases remain.

Parameters:

  • packet: the packet whose registered phase to select
  • current: the current connection phase, or null
Returns: the selected phase identifier

readBitSet ​

readBitSet(): BitSetSince1.8.4#
Returns: the read bit set.

readBlockHitResultHelper ​

readBlockHitResultHelper(): HitResultHelper.BlockSince1.9.1#
Returns: the read block hit result as a helper.

readBlockPos ​

readBlockPos(): BlockPosHelperSince1.8.4#
Returns: the read block position.

readBoolean ​

readBoolean(): booleanSince1.8.4#
Returns: the read boolean value.

readByte ​

readByte(): byteSince1.8.4#
Returns: the read byte value.

readByteArray ​

readByteArray(): byte[]Since1.8.4#
Returns: the read byte array.
readByteArray(int maxSize): byte[]Since1.8.4#
Will throw an exception if the byte array is bigger than the given maximum size.

Parameters:

  • maxSize: the maximum size of the byte array to read
Returns: the read byte array.

readBytes ​

readBytes(int length): byte[]Since1.8.4#
Starts reading from this buffer's readerIndex.

Parameters:

  • length: the length of the array to read
Returns: the read byte array.

readChar ​

readChar(): charSince1.8.4#
Returns: the read char value.

readChunkHelper ​

readChunkHelper(): ChunkHelperSince1.8.4#
Reads a chunk position and looks up that chunk in the current client level.
Returns: its ChunkHelper, or null if the lookup returns no chunk.

readChunkPos ​

readChunkPos(): int[]Since1.8.4#
Returns: the chunk coordinates, with x at index 0 and z at index 1.

readChunkSectionPos ​

readChunkSectionPos(): BlockPosHelperSince1.8.4#
Returns: the read section coordinates, wrapped as a BlockPosHelper.

readDate ​

readDate(): DateSince1.8.4#
Returns: the read date.

readDouble ​

readDouble(): doubleSince1.8.4#
Returns: the read double value.

readEnumConstant ​

readEnumConstant(Class<T extends Enum<T>> enumClass): T extends Enum<T>Since1.8.4#

Parameters:

  • enumClass: the enum class whose constant is selected by the encoded ordinal

Type Parameters:

  • T: the enum type to read
Returns: the enum constant at the encoded ordinal

readerIndex ​

readerIndex(): intSince1.8.4#
Returns: the readers current position.

readFloat ​

readFloat(): floatSince1.8.4#
Returns: the read float value.

readIdentifier ​

readIdentifier(): StringSince1.8.4#
Returns: the read identifier.

readInstant ​

readInstant(): InstantSince1.8.4#
Returns: the read instant.

readInt ​

readInt(): intSince1.8.4#
Reads an integer from the current reader index.
Returns: the value read.

readIntArray ​

readIntArray(): int[]Since1.8.4#
Returns: the read int array.
readIntArray(int maxSize): PacketByteBufferHelperSince1.8.4#
Reads and discards an int array, then returns this helper. The reader rejects an encoded array length greater than maxSize.

Parameters:

  • maxSize: the maximum size of the int array to read
Returns: this helper

readIntList ​

readIntList(): IntListSince1.8.4#
Reads an integer list from the buffer.
Returns: the decoded list

readList ​

readList(MethodWrapper<FriendlyByteBuf, ?, T, ?> reader): List<T>Since1.8.4#
Reads a list of elements from the buffer.

Parameters:

  • reader: reads each element

Type Parameters:

  • T: the type of elements read
Returns: the decoded elements

readLong ​

readLong(): longSince1.8.4#
Returns: the read long value.

readLongArray ​

readLongArray(): long[]Since1.8.4#
Returns: the read long array.
readLongArray(int maxSize): long[]Since1.8.4#
Reads and returns a long array. The maxSize argument is ignored; the underlying reader instead rejects a length greater than the number of complete longs remaining in the buffer.

Parameters:

  • maxSize: the maximum size of the long array to read
Returns: the read long array

readMap ​

readMap(MethodWrapper<FriendlyByteBuf, ?, K, ?> keyReader, MethodWrapper<FriendlyByteBuf, ?, V, ?> valueReader): Map<K, V>Since1.8.4#
Reads a map's keys and values from the buffer.

Parameters:

  • keyReader: reads each map key
  • valueReader: reads each map value

Type Parameters:

  • K: the type of map keys
  • V: the type of map values
Returns: the read map.

readMedium ​

readMedium(): intSince1.8.4#
Reads a signed medium from the current reader index.
Returns: the value read.

readNbt ​

readNbt(): NBTElementHelper<?>Since1.8.4#
Returns: the read nbt data.

readNullable ​

readNullable(MethodWrapper<FriendlyByteBuf, ?, T, ?> reader): TSince1.8.4#

Parameters:

  • reader: the function to read the value from the buffer if it's not null

Type Parameters:

  • T: the value type
Returns: the read value or null if it was null.

See:

readOptional ​

readOptional(MethodWrapper<FriendlyByteBuf, ?, T, ?> reader): Optional<T>Since1.8.4#

Parameters:

  • reader: the function to read the optional value from the buffer if present

Type Parameters:

  • T: the value type
Returns: the optional value.

See:

readPublicKey ​

readPublicKey(): PublicKeySince1.8.4#
Returns: the read public key.

readRegistryKey ​

readRegistryKey(ResourceKey<? extends Registry<T>> registry): ResourceKey<T>Since1.8.4#
Reads a registry key from the buffer.

Parameters:

  • registry: the registry the key belongs to

Type Parameters:

  • T: the type of values identified by the registry key
Returns: the decoded key

readShort ​

readShort(): shortSince1.8.4#
Reads a short from the current reader index.
Returns: the read short value.

readString ​

readString(): StringSince1.8.4#
Returns: the read string.
readString(int maxLength): StringSince1.8.4#
Throws an exception if the read string is longer than the given length.

Parameters:

  • maxLength: the maximum length of the string to read
Returns: the read string.

readUnsignedByte ​

readUnsignedByte(): shortSince1.8.4#
Returns: the read unsigned byte value, represented as a short.

readUnsignedInt ​

readUnsignedInt(): longSince1.8.4#
Reads an unsigned integer from the current reader index.
Returns: the value read, represented as a long.

readUnsignedMedium ​

readUnsignedMedium(): intSince1.8.4#
Reads an unsigned medium from the current reader index.
Returns: the value read.

readUnsignedShort ​

readUnsignedShort(): intSince1.8.4#
Reads an unsigned short from the current reader index.
Returns: the read unsigned short value, represented as an int.

readUuid ​

readUuid(): UUIDSince1.8.4#
Returns: the read UUID.

readVarInt ​

readVarInt(): intSince1.8.4#
Returns: the read int.

readVarLong ​

readVarLong(): longSince1.8.4#
Returns: the read long.

receivePacket ​

receivePacket(): PacketByteBufferHelperSince1.8.4#
handles a packet as though the client had received it, for testing a listener. Nothing is converted here: this handles the original packet object, not modified buffer bytes. The named and class overloads decode instead. A helper without an original packet is a no-op in all three receive overloads. Nothing is sent anywhere either, so this is the opposite direction from sendPacket() and the send event's replacePacket has no bearing on it. The listener type is not checked before handling; the packet's handler receives the current client game connection, so use a packet compatible with that listener.
Returns: self for chaining.
receivePacket(String packetName): PacketByteBufferHelperSince1.8.4#
handles a packet of the named type as though the client had received it. If this helper has an original packet, decodes through toPacket(String) and handles the result with the client game connection. Otherwise this is a no-op. The bytes must be correctly positioned and describe a compatible client game packet.

Parameters:

  • packetName: the name of the packet's class that should be received
Returns: self for chaining.
receivePacket(Class<? extends Packet> clazz): PacketByteBufferHelperSince1.8.4#
Decodes the requested packet at the current reader position and handles it with the client game connection. A helper without an original packet is a no-op; the listener type is not checked before handling.

Parameters:

  • clazz: the class of the packet to receive
Returns: self for chaining.

reset ​

reset(): PacketByteBufferHelperSince1.8.4#
Restores the buffer contents and reader position captured when this helper was created. For a packet-backed helper, this is the encoded packet data, not an empty buffer. The helper's buffer is separate from the packet object; resetting it does not change that object. Registry access is retained when restoring a registry-backed buffer.
Returns: self for chaining.

resetIndices ​

resetIndices(): PacketByteBufferHelperSince1.8.4#
Resets the readers and writers index to their respective last marked indices.
Returns: self for chaining.

See:

resetReaderIndex ​

resetReaderIndex(): PacketByteBufferHelperSince1.8.4#
Resets the readers index to the last marked index.
Returns: self for chaining.

See:

resetWriterIndex ​

resetWriterIndex(): PacketByteBufferHelperSince1.8.4#
Resets the writers index to the last marked index.
Returns: self for chaining.

See:

sendPacket ​

sendPacket(): PacketByteBufferHelperSince1.8.4#
Send a packet of the given type, created from this buffer, to the server. Decodes through toPacket() at the current reader position. A helper without an original packet is a no-op. Sending requires a connection and a suitable serverbound packet.
Returns: self for chaining.
sendPacket(String packetName): PacketByteBufferHelperSince1.8.4#
builds a packet of the named type from this buffer and sends it to the server. Decodes through the class overload at the current reader position. Requires a connection, a supported codec and bytes matching a suitable serverbound packet.

Parameters:

  • packetName: the name of the packet's class that should be sent
Returns: self for chaining.
sendPacket(Class<? extends Packet<?>> clazz): PacketByteBufferHelperSince1.8.4#
Send a packet of the given type, created from this buffer, to the server.

Parameters:

  • clazz: the class of the packet to send
Returns: self for chaining.

setBoolean ​

setBoolean(int index, boolean value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setByte ​

setByte(int index, int value): PacketByteBufferHelperSince1.8.4#
Writes a short at the given index without changing the writer index.

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setBytes ​

setBytes(int index, byte[] bytes): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • bytes: the bytes to store
Returns: self for chaining.

setChar ​

setChar(int index, char value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setDouble ​

setDouble(int index, double value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setFloat ​

setFloat(int index, double value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setIndices ​

setIndices(int readerIndex, int writerIndex): PacketByteBufferHelperSince1.8.4#

Parameters:

  • readerIndex: the readers new index
  • writerIndex: the writers new index
Returns: self for chaining.

setInt ​

setInt(int index, int value): PacketByteBufferHelperSince1.8.4#
Writes an integer at the given byte index without changing the writer index.

Parameters:

  • index: the byte index to write to
  • value: the value to write
Returns: this buffer helper.

setLong ​

setLong(int index, long value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setMedium ​

setMedium(int index, int value): PacketByteBufferHelperSince1.8.4#
Writes a medium at the given index without changing the writer index.

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setReaderIndex ​

setReaderIndex(int index): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the readers new index
Returns: self for chaining.

setShort ​

setShort(int index, int value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • value: the value to store
Returns: self for chaining.

setWriterIndex ​

setWriterIndex(int index): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the writers new index
Returns: self for chaining.

setZero ​

setZero(int index, int length): PacketByteBufferHelperSince1.8.4#

Parameters:

  • index: the index to write to
  • length: the amount of zeros to write
Returns: self for chaining.

skipBytes ​

skipBytes(int length): PacketByteBufferHelperSince1.8.4#
Moves the readerIndex of this buffer by the specified amount.

Parameters:

  • length: the amount of bytes to skip
Returns: self for chaining.

toPacket ​

toPacket(): Packet<?>Since1.8.4#
the packet this buffer came from, rebuilt from the buffer. A fresh helper without an original packet returns null. A packet-backed helper decodes the original packet class using its saved network phase and the current reader position. This returns a decoded packet, not the original object carried by the event.
Returns: the packet for this buffer, or null if no packet was used to create this helper
toPacket(String packetName): Packet<?>Since1.8.4#
the packet named, built from this buffer. Looks up the convenience name and decodes at the current reader position. Packet-backed helpers use their saved phase; fresh helpers default to play. The names are the ones getPacketNames() lists.

Parameters:

  • packetName: the name of the packet's class that should be returned
Returns: the packet for this buffer.
toPacket(String packetName, String protocol): Packet<?>#
Decodes a named packet at the current reader position using an explicit network phase.

Parameters:

Returns: the decoded packet
toPacket(Class<? extends Packet> clazz): Packet<?>Since1.8.4#
the packet of the given class, built from this buffer. Decodes at the current reader position. Non-play helpers use their saved phase; play helpers use the registered decoder lookup. The bytes must match the requested codec.

Parameters:

  • clazz: the class of the packet to return
Returns: the packet for this buffer.
toPacket(Class<? extends Packet> clazz, String protocol): Packet<?>#
Decodes at the current reader position using a phase-specific codec, including configuration custom payloads. The bytes must match the requested codec.

Parameters:

  • clazz: the packet class
  • protocol: the network phase
Returns: the decoded packet

toString ​

toString(): String#
Returns a diagnostic string containing the underlying buffer's string representation.
Returns: a diagnostic string describing the underlying buffer

writeBitSet ​

writeBitSet(BitSet bitSet): PacketByteBufferHelperSince1.8.4#

Parameters:

  • bitSet: the bit set to store
Returns: self for chaining.

writeBlockHitResult ​

writeBlockHitResult(HitResultHelper.Block hitResult): PacketByteBufferHelperSince1.9.1#

Parameters:

  • hitResult: the hit result to store
Returns: self for chaining.
writeBlockHitResult(Pos3D pos, String direction, BlockPosHelper blockPos, boolean missed, boolean insideBlock): PacketByteBufferHelperSince1.8.4#

Parameters:

  • pos: the position of the BlockHitResult
  • direction: the direction of the BlockHitResult
  • blockPos: the block pos of the BlockHitResult
  • missed: whether the BlockHitResult missed
  • insideBlock: whether the BlockHitResult is inside a block
Returns: self for chaining.

writeBlockPos ​

writeBlockPos(BlockPosHelper pos): PacketByteBufferHelperSince1.8.4#

Parameters:

  • pos: the block position to store
Returns: self for chaining.
writeBlockPos(int x, int y, int z): PacketByteBufferHelperSince1.8.4#

Parameters:

  • x: the x coordinate of the block position to store
  • y: the y coordinate of the block position to store
  • z: the z coordinate of the block position to store
Returns: self for chaining.

writeBoolean ​

writeBoolean(boolean value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the value to store
Returns: self for chaining.

writeByte ​

writeByte(int value): PacketByteBufferHelperSince1.8.4#
Writes a short at the current writer index.

Parameters:

  • value: the value to store
Returns: self for chaining.

writeByteArray ​

writeByteArray(byte[] bytes): PacketByteBufferHelperSince1.8.4#

Parameters:

  • bytes: the bytes to store
Returns: self for chaining.

writeBytes ​

writeBytes(byte[] bytes): PacketByteBufferHelperSince1.8.4#

Parameters:

  • bytes: the bytes to store
Returns: self for chaining.

writeChar ​

writeChar(int value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the value to store
Returns: self for chaining.

writeChunkPos ​

writeChunkPos(int x, int z): PacketByteBufferHelperSince1.8.4#

Parameters:

  • x: the x coordinate of the chunk to store
  • z: the z coordinate of the chunk to store
Returns: self for chaining.
writeChunkPos(ChunkHelper chunk): PacketByteBufferHelperSince1.8.4#

Parameters:

  • chunk: the chunk to store
Returns: self for chaining.

writeChunkSectionPos ​

writeChunkSectionPos(int chunkX, int y, int chunkZ): PacketByteBufferHelperSince1.8.4#

Parameters:

  • chunkX: the section's x coordinate
  • y: the section's y coordinate
  • chunkZ: the section's z coordinate
Returns: self for chaining.
writeChunkSectionPos(ChunkHelper chunk, int y): PacketByteBufferHelperSince1.8.4#

Parameters:

  • chunk: the chunk whose x and z coordinates define the section position
  • y: the section's y coordinate
Returns: self for chaining.

writeCollection ​

writeCollection(Collection<T> collection, MethodWrapper<FriendlyByteBuf, T, ?, ?> writer): PacketByteBufferHelperSince1.8.4#
Writes a collection and its elements to the buffer.

Parameters:

  • collection: the collection to write
  • writer: writes each element

Type Parameters:

  • T: the type of elements in the collection
Returns: self for chaining.

writeDate ​

writeDate(Date date): PacketByteBufferHelperSince1.8.4#

Parameters:

  • date: the date to store
Returns: self for chaining.

writeDouble ​

writeDouble(double value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the value to store
Returns: self for chaining.

writeEnumConstant ​

writeEnumConstant(Enum<?> constant): PacketByteBufferHelperSince1.8.4#

Parameters:

  • constant: the enum constant to encode by ordinal
Returns: self for chaining.

writeFloat ​

writeFloat(double value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the value to store
Returns: self for chaining.

writeGlobalPos ​

writeGlobalPos(String dimension, BlockPosHelper pos): PacketByteBufferHelperSince1.8.4#

Parameters:

  • dimension: the dimension identifier; vanilla dimensions include overworld, the_nether, and the_end
  • pos: the position to store
Returns: self for chaining.
writeGlobalPos(String dimension, int x, int y, int z): PacketByteBufferHelperSince1.8.4#

Parameters:

  • dimension: the dimension identifier; vanilla dimensions include overworld, the_nether, and the_end
  • x: the x coordinate of the position to store
  • y: the y coordinate of the position to store
  • z: the z coordinate of the position to store
Returns: self for chaining.

writeIdentifier ​

writeIdentifier(String id): PacketByteBufferHelperSince1.8.4#

Parameters:

  • id: the identifier to store
Returns: self for chaining.

writeInstant ​

writeInstant(Instant instant): PacketByteBufferHelperSince1.8.4#

Parameters:

  • instant: the instant to store
Returns: self for chaining.

writeInt ​

writeInt(int value): PacketByteBufferHelperSince1.8.4#
Writes an integer at the current writer index.

Parameters:

  • value: the value to write
Returns: this buffer helper.

writeIntArray ​

writeIntArray(int[] ints): PacketByteBufferHelperSince1.8.4#

Parameters:

  • ints: the int array to store
Returns: self for chaining.

writeIntList ​

writeIntList(Collection<Integer> list): PacketByteBufferHelperSince1.8.4#
Writes an integer list to the buffer.

Parameters:

  • list: the list to write
Returns: self for chaining.

writeLong ​

writeLong(long value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the value to store
Returns: self for chaining.

writeLongArray ​

writeLongArray(long[] longs): PacketByteBufferHelperSince1.8.4#

Parameters:

  • longs: the long array to store
Returns: self for chaining.

writeMap ​

writeMap(Map<K, V> map, MethodWrapper<FriendlyByteBuf, K, ?, ?> keyWriter, MethodWrapper<FriendlyByteBuf, V, ?, ?> valueWriter): PacketByteBufferHelperSince1.8.4#
Writes a map and its keys and values to the buffer.

Parameters:

  • map: the map to write
  • keyWriter: writes each key
  • valueWriter: writes each value

Type Parameters:

  • K: the type of map keys
  • V: the type of map values
Returns: self for chaining.

writeMedium ​

writeMedium(int value): PacketByteBufferHelperSince1.8.4#
Writes a medium at the current writer index.

Parameters:

  • value: the value to store
Returns: self for chaining.

writeNbt ​

Parameters:

  • nbt: the nbt
Returns: self for chaining.

writeNullable ​

writeNullable(Object value, MethodWrapper<FriendlyByteBuf, Object, ?, ?> writer): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the optional value to store
  • writer: the function to write the optional value if it's not null to the buffer
Returns: self for chaining.

See:

writeOptional ​

writeOptional(T value, MethodWrapper<FriendlyByteBuf, T, ?, ?> writer): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the optional value to store
  • writer: the function to write the optional value if present to the buffer

Type Parameters:

  • T: the value type
Returns: self for chaining.

See:

writePublicKey ​

writePublicKey(PublicKey key): PacketByteBufferHelperSince1.8.4#

Parameters:

  • key: the public key to store
Returns: self for chaining.

writeRegistryKey ​

writeRegistryKey(ResourceKey<?> key): PacketByteBufferHelperSince1.8.4#
Writes a registry key to the buffer.

Parameters:

  • key: the key to write
Returns: self for chaining.

writerIndex ​

writerIndex(): intSince1.8.4#
Returns: the writers current position.

writeShort ​

writeShort(int value): PacketByteBufferHelperSince1.8.4#

Parameters:

  • value: the value to store
Returns: self for chaining.

writeString ​

writeString(String string): PacketByteBufferHelperSince1.8.4#

Parameters:

  • string: the string to store
Returns: self for chaining.
writeString(String string, int maxLength): PacketByteBufferHelperSince1.8.4#
Throws an exception if the string is longer than the given length.

Parameters:

  • string: the string to store
  • maxLength: the maximum length of the string
Returns: self for chaining.

writeUuid ​

writeUuid(String uuid): PacketByteBufferHelperSince1.8.4#

Parameters:

  • uuid: the UUID to store
Returns: self for chaining.

writeVarInt ​

writeVarInt(int i): PacketByteBufferHelperSince1.8.4#

Parameters:

  • i: the integer to encode as a variable-length integer
Returns: self for chaining.

writeVarLong ​

writeVarLong(long l): PacketByteBufferHelperSince1.8.4#

Parameters:

  • l: the long to store
Returns: self for chaining.

writeZero ​

writeZero(int length): PacketByteBufferHelperSince1.8.4#

Parameters:

  • length: the amount of zeros to write
Returns: self for chaining.