# PacketByteBufferHelper

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

**Since:** 1.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()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_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()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_constructor-}

```js
new PacketByteBufferHelper()
```

Creates a fresh buffer with no originating packet and the default `play` phase.  
Captures its initial contents for `reset()`.

### new PacketByteBufferHelper {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_constructor-FriendlyByteBuf-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_constructor-Packet-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_constructor-Packet-String-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_BUFFER_TO_PACKET}

```js
static BUFFER_TO_PACKET: Map<Class<? extends Packet<?>>, Function<FriendlyByteBuf, ? extends Packet<?>>>
```

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)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_toPacket-Class-) uses it for play-phase decoding; explicit phase decoding selects
the matching codec directly.

## Methods

### canSerialize {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_canSerialize-Packet-}

```js
static canSerialize(Packet<?> packet): boolean
```

Checks whether the packet has a standalone codec for the phase selected as in
[PacketByteBufferHelper(Packet)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_constructor-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

**Since:** 2.1.0

### clear {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_clear-}

```js
clear(): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### forEachInCollection {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_forEachInCollection-MethodWrapper-}

```js
forEachInCollection(MethodWrapper<FriendlyByteBuf, ?, Object, ?> reader): PacketByteBufferHelper
```

**Parameters:**
- `reader`: the function to read the collection's elements from the buffer

**Returns:** self for chaining.

**Since:** 1.8.4

### getBoolean {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getBoolean-int-}

```js
getBoolean(int index): boolean
```

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.

**Since:** 1.8.4

### getByte {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getByte-int-}

```js
getByte(int index): byte
```

**Parameters:**
- `index`: the index to read from

**Returns:** the byte at the given index.

**Since:** 1.8.4

### getBytes {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getBytes-int-int-}

```js
getBytes(int index, int length): byte[]
```

**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

**Since:** 1.8.4

### getChar {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getChar-int-}

```js
getChar(int index): char
```

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.

**Since:** 1.8.4

### getDouble {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getDouble-int-}

```js
getDouble(int index): double
```

**Parameters:**
- `index`: the index to read from

**Returns:** the double at the given index.

**Since:** 1.8.4

### getFloat {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getFloat-int-}

```js
getFloat(int index): float
```

**Parameters:**
- `index`: the index to read from

**Returns:** the float at the given index.

**Since:** 1.8.4

### getInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getInt-int-}

```js
getInt(int index): int
```

**Parameters:**
- `index`: the byte index to read from

**Returns:** the integer at that index.

**Since:** 1.8.4

### getLong {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getLong-int-}

```js
getLong(int index): long
```

**Parameters:**
- `index`: the index to read from

**Returns:** the long at the given index.

**Since:** 1.8.4

### getMedium {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getMedium-int-}

```js
getMedium(int index): int
```

**Parameters:**
- `index`: the byte index to read from

**Returns:** the signed medium at that index.

**Since:** 1.8.4

### getNetworkStateId {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getNetworkStateId-Class-}

```js
getNetworkStateId(Class<? extends Packet<?>> packetClass): int
```

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)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_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

**Since:** 1.8.4

### getNetworkStateId {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getNetworkStateId-Class-String-}

```js
getNetworkStateId(Class<? extends Packet<?>> packetClass, String protocol): int
```

Returns the ordinal of the requested protocol for a packet registered in it.  
 Throws [IllegalArgumentException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) 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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getPacketId-Class-}

```js
getPacketId(Class<? extends Packet<?>> packetClass): int
```

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)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getPacketId-Class-String-).

**Parameters:**
- `packetClass`: the class of the packet to get the id for

**Returns:** the ID registered for the packet class

**Since:** 1.8.4

### getPacketId {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getPacketId-Class-String-}

```js
getPacketId(Class<? extends Packet<?>> packetClass, String protocol): int
```

Returns the packet ID registered for the requested protocol (for example, "play" or "configuration").  
 Throws [IllegalArgumentException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) 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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getPacketName-Packet-}

```js
static getPacketName(Packet<?> packet): String
```

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

**Since:** 1.8.4

### getPacketNames {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getPacketNames-}

```js
getPacketNames(): List<String>
```

Returns the registered packet names: every packet's modern Mojang class alias, plus the
legacy name used as the packet-event `type` when one exists. Packet filterers accept
either form.  

Legacy names may encode direction in an `S2C` or `C2S` suffix; modern aliases do
not, so use [isClientbound(Class)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_isClientbound-Class-) or [isServerbound(Class)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_isServerbound-Class-) for direction.  
Names can change between game versions. Legacy names are planned for removal in 3.0.0.

**Returns:** a list of all packet names.

**Since:** 1.8.4

### getShort {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getShort-int-}

```js
getShort(int index): short
```

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.

**Since:** 1.8.4

### getUnsignedByte {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getUnsignedByte-int-}

```js
getUnsignedByte(int index): short
```

**Parameters:**
- `index`: the index to read from

**Returns:** the unsigned byte at the given index, represented as a short.

**Since:** 1.8.4

### getUnsignedInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getUnsignedInt-int-}

```js
getUnsignedInt(int index): long
```

**Parameters:**
- `index`: the byte index to read from

**Returns:** the unsigned integer at that index, represented as a long.

**Since:** 1.8.4

### getUnsignedMedium {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getUnsignedMedium-int-}

```js
getUnsignedMedium(int index): int
```

**Parameters:**
- `index`: the byte index to read from

**Returns:** the unsigned medium at that index.

**Since:** 1.8.4

### getUnsignedShort {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getUnsignedShort-int-}

```js
getUnsignedShort(int index): int
```

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.

**Since:** 1.8.4

### init {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_init-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_isClientbound-Class-}

```js
isClientbound(Class<? extends Packet<?>> packetClass): boolean
```

whether a packet class is one the server sends to the client.  

Reads the registered packet direction rather than inferring it from a name. Legacy names
used as event types often end in `S2C` or `C2S`, but modern Mojang aliases do
not encode direction; use this method or [isServerbound(Class)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_isServerbound-Class-).

**Parameters:**
- `packetClass`: the class to get the side for

**Returns:** `true` if the packet is clientbound, `false` if it is serverbound

**Since:** 1.8.4

### isServerbound {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_isServerbound-Class-}

```js
isServerbound(Class<? extends Packet<?>> packetClass): boolean
```

whether a packet class is one the client sends to the server.  

This is the exact opposite of [isClientbound(Class)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_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

**Since:** 1.8.4

### main {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_main-String[]-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_markReaderIndex-}

```js
markReaderIndex(): PacketByteBufferHelper
```

Marks the readers current index for later use.

**Returns:** self for chaining.

**Since:** 1.8.4

**See:**
- [resetReaderIndex()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_resetReaderIndex-)

### markWriterIndex {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_markWriterIndex-}

```js
markWriterIndex(): PacketByteBufferHelper
```

Marks the current writer index for later use by [resetWriterIndex()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_resetWriterIndex-).

**Returns:** self for chaining.

**Since:** 1.8.4

### preferredProtocol {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_preferredProtocol-Packet-ConnectionProtocol-}

```js
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](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/IllegalArgumentException.html) 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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readBitSet-}

```js
readBitSet(): BitSet
```

**Returns:** the read bit set.

**Since:** 1.8.4

### readBlockHitResultHelper {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readBlockHitResultHelper-}

```js
readBlockHitResultHelper(): HitResultHelper.Block
```

**Returns:** the read block hit result as a helper.

**Since:** 1.9.1

### readBlockPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readBlockPos-}

```js
readBlockPos(): BlockPosHelper
```

**Returns:** the read block position.

**Since:** 1.8.4

### readBoolean {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readBoolean-}

```js
readBoolean(): boolean
```

**Returns:** the read boolean value.

**Since:** 1.8.4

### readByte {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readByte-}

```js
readByte(): byte
```

**Returns:** the read byte value.

**Since:** 1.8.4

### readByteArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readByteArray-}

```js
readByteArray(): byte[]
```

**Returns:** the read byte array.

**Since:** 1.8.4

### readByteArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readByteArray-int-}

```js
readByteArray(int maxSize): byte[]
```

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.

**Since:** 1.8.4

### readBytes {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readBytes-int-}

```js
readBytes(int length): byte[]
```

Starts reading from this buffer's readerIndex.

**Parameters:**
- `length`: the length of the array to read

**Returns:** the read byte array.

**Since:** 1.8.4

### readChar {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readChar-}

```js
readChar(): char
```

**Returns:** the read char value.

**Since:** 1.8.4

### readChunkHelper {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readChunkHelper-}

```js
readChunkHelper(): ChunkHelper
```

Reads a chunk position and looks up that chunk in the current client level.

**Returns:** its [ChunkHelper](world/ChunkHelper.md), or `null` if the lookup returns no chunk.

**Since:** 1.8.4

### readChunkPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readChunkPos-}

```js
readChunkPos(): int[]
```

**Returns:** the chunk coordinates, with x at index 0 and z at index 1.

**Since:** 1.8.4

### readChunkSectionPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readChunkSectionPos-}

```js
readChunkSectionPos(): BlockPosHelper
```

**Returns:** the read section coordinates, wrapped as a [BlockPosHelper](world/BlockPosHelper.md).

**Since:** 1.8.4

### readDate {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readDate-}

```js
readDate(): Date
```

**Returns:** the read date.

**Since:** 1.8.4

### readDouble {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readDouble-}

```js
readDouble(): double
```

**Returns:** the read double value.

**Since:** 1.8.4

### readEnumConstant {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readEnumConstant-Class-}

```js
readEnumConstant(Class<T extends Enum<T>> enumClass): T extends Enum<T>
```

**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

**Since:** 1.8.4

### readerIndex {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readerIndex-}

```js
readerIndex(): int
```

**Returns:** the readers current position.

**Since:** 1.8.4

### readFloat {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readFloat-}

```js
readFloat(): float
```

**Returns:** the read float value.

**Since:** 1.8.4

### readIdentifier {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readIdentifier-}

```js
readIdentifier(): String
```

**Returns:** the read identifier.

**Since:** 1.8.4

### readInstant {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readInstant-}

```js
readInstant(): Instant
```

**Returns:** the read instant.

**Since:** 1.8.4

### readInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readInt-}

```js
readInt(): int
```

Reads an integer from the current reader index.

**Returns:** the value read.

**Since:** 1.8.4

### readIntArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readIntArray-}

```js
readIntArray(): int[]
```

**Returns:** the read int array.

**Since:** 1.8.4

### readIntArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readIntArray-int-}

```js
readIntArray(int maxSize): PacketByteBufferHelper
```

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

**Since:** 1.8.4

### readIntList {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readIntList-}

```js
readIntList(): IntList
```

Reads an integer list from the buffer.

**Returns:** the decoded list

**Since:** 1.8.4

### readList {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readList-MethodWrapper-}

```js
readList(MethodWrapper<FriendlyByteBuf, ?, T, ?> reader): List<T>
```

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

**Since:** 1.8.4

### readLong {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readLong-}

```js
readLong(): long
```

**Returns:** the read long value.

**Since:** 1.8.4

### readLongArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readLongArray-}

```js
readLongArray(): long[]
```

**Returns:** the read long array.

**Since:** 1.8.4

### readLongArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readLongArray-int-}

```js
readLongArray(int maxSize): long[]
```

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

**Since:** 1.8.4

### readMap {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readMap-MethodWrapper-MethodWrapper-}

```js
readMap(MethodWrapper<FriendlyByteBuf, ?, K, ?> keyReader, MethodWrapper<FriendlyByteBuf, ?, V, ?> valueReader): Map<K, V>
```

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.

**Since:** 1.8.4

### readMedium {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readMedium-}

```js
readMedium(): int
```

Reads a signed medium from the current reader index.

**Returns:** the value read.

**Since:** 1.8.4

### readNbt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readNbt-}

```js
readNbt(): NBTElementHelper<?>
```

**Returns:** the read nbt data.

**Since:** 1.8.4

### readNullable {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readNullable-MethodWrapper-}

```js
readNullable(MethodWrapper<FriendlyByteBuf, ?, T, ?> reader): T
```

**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.

**Since:** 1.8.4

**See:**
- [readOptional(MethodWrapper)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readOptional-MethodWrapper-)

### readOptional {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readOptional-MethodWrapper-}

```js
readOptional(MethodWrapper<FriendlyByteBuf, ?, T, ?> reader): Optional<T>
```

**Parameters:**
- `reader`: the function to read the optional value from the buffer if present

**Type Parameters:**
- `T`: the value type

**Returns:** the optional value.

**Since:** 1.8.4

**See:**
- [readNullable(MethodWrapper)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readNullable-MethodWrapper-)

### readPublicKey {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readPublicKey-}

```js
readPublicKey(): PublicKey
```

**Returns:** the read public key.

**Since:** 1.8.4

### readRegistryKey {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readRegistryKey-ResourceKey-}

```js
readRegistryKey(ResourceKey<? extends Registry<T>> registry): ResourceKey<T>
```

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

**Since:** 1.8.4

### readShort {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readShort-}

```js
readShort(): short
```

Reads a short from the current reader index.

**Returns:** the read short value.

**Since:** 1.8.4

### readString {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readString-}

```js
readString(): String
```

**Returns:** the read string.

**Since:** 1.8.4

### readString {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readString-int-}

```js
readString(int maxLength): String
```

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.

**Since:** 1.8.4

### readUnsignedByte {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readUnsignedByte-}

```js
readUnsignedByte(): short
```

**Returns:** the read unsigned byte value, represented as a short.

**Since:** 1.8.4

### readUnsignedInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readUnsignedInt-}

```js
readUnsignedInt(): long
```

Reads an unsigned integer from the current reader index.

**Returns:** the value read, represented as a long.

**Since:** 1.8.4

### readUnsignedMedium {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readUnsignedMedium-}

```js
readUnsignedMedium(): int
```

Reads an unsigned medium from the current reader index.

**Returns:** the value read.

**Since:** 1.8.4

### readUnsignedShort {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readUnsignedShort-}

```js
readUnsignedShort(): int
```

Reads an unsigned short from the current reader index.

**Returns:** the read unsigned short value, represented as an int.

**Since:** 1.8.4

### readUuid {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readUuid-}

```js
readUuid(): UUID
```

**Returns:** the read UUID.

**Since:** 1.8.4

### readVarInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readVarInt-}

```js
readVarInt(): int
```

**Returns:** the read int.

**Since:** 1.8.4

### readVarLong {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_readVarLong-}

```js
readVarLong(): long
```

**Returns:** the read long.

**Since:** 1.8.4

### receivePacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_receivePacket-}

```js
receivePacket(): PacketByteBufferHelper
```

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()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_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.

**Since:** 1.8.4

### receivePacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_receivePacket-String-}

```js
receivePacket(String packetName): PacketByteBufferHelper
```

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)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_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.

**Since:** 1.8.4

### receivePacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_receivePacket-Class-}

```js
receivePacket(Class<? extends Packet> clazz): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### reset {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_reset-}

```js
reset(): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### resetIndices {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_resetIndices-}

```js
resetIndices(): PacketByteBufferHelper
```

Resets the readers and writers index to their respective last marked indices.

**Returns:** self for chaining.

**Since:** 1.8.4

**See:**
- [markReaderIndex()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_markReaderIndex-)
- [markWriterIndex()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_markWriterIndex-)

### resetReaderIndex {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_resetReaderIndex-}

```js
resetReaderIndex(): PacketByteBufferHelper
```

Resets the readers index to the last marked index.

**Returns:** self for chaining.

**Since:** 1.8.4

**See:**
- [markReaderIndex()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_markReaderIndex-)

### resetWriterIndex {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_resetWriterIndex-}

```js
resetWriterIndex(): PacketByteBufferHelper
```

Resets the writers index to the last marked index.

**Returns:** self for chaining.

**Since:** 1.8.4

**See:**
- [markWriterIndex()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_markWriterIndex-)

### sendPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_sendPacket-}

```js
sendPacket(): PacketByteBufferHelper
```

Send a packet of the given type, created from this buffer, to the server.  

Decodes through [toPacket()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_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.

**Since:** 1.8.4

### sendPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_sendPacket-String-}

```js
sendPacket(String packetName): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### sendPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_sendPacket-Class-}

```js
sendPacket(Class<? extends Packet<?>> clazz): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### setBoolean {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setBoolean-int-boolean-}

```js
setBoolean(int index, boolean value): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### setByte {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setByte-int-int-}

```js
setByte(int index, int value): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### setBytes {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setBytes-int-byte[]-}

```js
setBytes(int index, byte[] bytes): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `bytes`: the bytes to store

**Returns:** self for chaining.

**Since:** 1.8.4

### setChar {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setChar-int-char-}

```js
setChar(int index, char value): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### setDouble {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setDouble-int-double-}

```js
setDouble(int index, double value): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### setFloat {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setFloat-int-double-}

```js
setFloat(int index, double value): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### setIndices {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setIndices-int-int-}

```js
setIndices(int readerIndex, int writerIndex): PacketByteBufferHelper
```

**Parameters:**
- `readerIndex`: the readers new index
- `writerIndex`: the writers new index

**Returns:** self for chaining.

**Since:** 1.8.4

### setInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setInt-int-int-}

```js
setInt(int index, int value): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### setLong {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setLong-int-long-}

```js
setLong(int index, long value): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### setMedium {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setMedium-int-int-}

```js
setMedium(int index, int value): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### setReaderIndex {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setReaderIndex-int-}

```js
setReaderIndex(int index): PacketByteBufferHelper
```

**Parameters:**
- `index`: the readers new index

**Returns:** self for chaining.

**Since:** 1.8.4

### setShort {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setShort-int-int-}

```js
setShort(int index, int value): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### setWriterIndex {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setWriterIndex-int-}

```js
setWriterIndex(int index): PacketByteBufferHelper
```

**Parameters:**
- `index`: the writers new index

**Returns:** self for chaining.

**Since:** 1.8.4

### setZero {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_setZero-int-int-}

```js
setZero(int index, int length): PacketByteBufferHelper
```

**Parameters:**
- `index`: the index to write to
- `length`: the amount of zeros to write

**Returns:** self for chaining.

**Since:** 1.8.4

### skipBytes {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_skipBytes-int-}

```js
skipBytes(int length): PacketByteBufferHelper
```

Moves the readerIndex of this buffer by the specified amount.

**Parameters:**
- `length`: the amount of bytes to skip

**Returns:** self for chaining.

**Since:** 1.8.4

### toPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_toPacket-}

```js
toPacket(): Packet<?>
```

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

**Since:** 1.8.4

### toPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_toPacket-String-}

```js
toPacket(String packetName): Packet<?>
```

the packet named, built from this buffer.  

Looks up a registered legacy or modern packet 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()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getPacketNames-) lists.

**Parameters:**
- `packetName`: the name of the packet's class that should be returned

**Returns:** the packet for this buffer.

**Since:** 1.8.4

### toPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_toPacket-String-String-}

```js
toPacket(String packetName, String protocol): Packet<?>
```

Decodes a named packet at the current reader position using an explicit network phase.

**Parameters:**
- `packetName`: a convenience name from [getPacketNames()](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_getPacketNames-)
- `protocol`: the network phase

**Returns:** the decoded packet

### toPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_toPacket-Class-}

```js
toPacket(Class<? extends Packet> clazz): Packet<?>
```

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.

**Since:** 1.8.4

### toPacket {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_toPacket-Class-String-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the underlying buffer's string representation.

**Returns:** a diagnostic string describing the underlying buffer

### writeBitSet {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeBitSet-BitSet-}

```js
writeBitSet(BitSet bitSet): PacketByteBufferHelper
```

**Parameters:**
- `bitSet`: the bit set to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeBlockHitResult {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeBlockHitResult-HitResultHelper.Block-}

```js
writeBlockHitResult(HitResultHelper.Block hitResult): PacketByteBufferHelper
```

**Parameters:**
- `hitResult`: the hit result to store

**Returns:** self for chaining.

**Since:** 1.9.1

### writeBlockHitResult {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeBlockHitResult-Pos3D-String-BlockPosHelper-boolean-boolean-}

```js
writeBlockHitResult(Pos3D pos, String direction, BlockPosHelper blockPos, boolean missed, boolean insideBlock): PacketByteBufferHelper
```

**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.

**Since:** 1.8.4

### writeBlockPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeBlockPos-BlockPosHelper-}

```js
writeBlockPos(BlockPosHelper pos): PacketByteBufferHelper
```

**Parameters:**
- `pos`: the block position to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeBlockPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeBlockPos-int-int-int-}

```js
writeBlockPos(int x, int y, int z): PacketByteBufferHelper
```

**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.

**Since:** 1.8.4

### writeBoolean {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeBoolean-boolean-}

```js
writeBoolean(boolean value): PacketByteBufferHelper
```

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeByte {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeByte-int-}

```js
writeByte(int value): PacketByteBufferHelper
```

Writes a short at the current writer index.

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeByteArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeByteArray-byte[]-}

```js
writeByteArray(byte[] bytes): PacketByteBufferHelper
```

**Parameters:**
- `bytes`: the bytes to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeBytes {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeBytes-byte[]-}

```js
writeBytes(byte[] bytes): PacketByteBufferHelper
```

**Parameters:**
- `bytes`: the bytes to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeChar {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeChar-int-}

```js
writeChar(int value): PacketByteBufferHelper
```

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeChunkPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeChunkPos-int-int-}

```js
writeChunkPos(int x, int z): PacketByteBufferHelper
```

**Parameters:**
- `x`: the x coordinate of the chunk to store
- `z`: the z coordinate of the chunk to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeChunkPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeChunkPos-ChunkHelper-}

```js
writeChunkPos(ChunkHelper chunk): PacketByteBufferHelper
```

**Parameters:**
- `chunk`: the chunk to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeChunkSectionPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeChunkSectionPos-int-int-int-}

```js
writeChunkSectionPos(int chunkX, int y, int chunkZ): PacketByteBufferHelper
```

**Parameters:**
- `chunkX`: the section's x coordinate
- `y`: the section's y coordinate
- `chunkZ`: the section's z coordinate

**Returns:** self for chaining.

**Since:** 1.8.4

### writeChunkSectionPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeChunkSectionPos-ChunkHelper-int-}

```js
writeChunkSectionPos(ChunkHelper chunk, int y): PacketByteBufferHelper
```

**Parameters:**
- `chunk`: the chunk whose x and z coordinates define the section position
- `y`: the section's y coordinate

**Returns:** self for chaining.

**Since:** 1.8.4

### writeCollection {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeCollection-Collection-MethodWrapper-}

```js
writeCollection(Collection<T> collection, MethodWrapper<FriendlyByteBuf, T, ?, ?> writer): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### writeDate {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeDate-Date-}

```js
writeDate(Date date): PacketByteBufferHelper
```

**Parameters:**
- `date`: the date to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeDouble {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeDouble-double-}

```js
writeDouble(double value): PacketByteBufferHelper
```

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeEnumConstant {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeEnumConstant-Enum-}

```js
writeEnumConstant(Enum<?> constant): PacketByteBufferHelper
```

**Parameters:**
- `constant`: the enum constant to encode by ordinal

**Returns:** self for chaining.

**Since:** 1.8.4

### writeFloat {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeFloat-double-}

```js
writeFloat(double value): PacketByteBufferHelper
```

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeGlobalPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeGlobalPos-String-BlockPosHelper-}

```js
writeGlobalPos(String dimension, BlockPosHelper pos): PacketByteBufferHelper
```

**Parameters:**
- `dimension`: the dimension identifier; vanilla dimensions include `overworld`,  
                 `the_nether`, and `the_end`
- `pos`: the position to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeGlobalPos {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeGlobalPos-String-int-int-int-}

```js
writeGlobalPos(String dimension, int x, int y, int z): PacketByteBufferHelper
```

**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.

**Since:** 1.8.4

### writeIdentifier {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeIdentifier-String-}

```js
writeIdentifier(String id): PacketByteBufferHelper
```

**Parameters:**
- `id`: the identifier to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeInstant {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeInstant-Instant-}

```js
writeInstant(Instant instant): PacketByteBufferHelper
```

**Parameters:**
- `instant`: the instant to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeInt-int-}

```js
writeInt(int value): PacketByteBufferHelper
```

Writes an integer at the current writer index.

**Parameters:**
- `value`: the value to write

**Returns:** this buffer helper.

**Since:** 1.8.4

### writeIntArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeIntArray-int[]-}

```js
writeIntArray(int[] ints): PacketByteBufferHelper
```

**Parameters:**
- `ints`: the int array to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeIntList {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeIntList-Collection-}

```js
writeIntList(Collection<Integer> list): PacketByteBufferHelper
```

Writes an integer list to the buffer.

**Parameters:**
- `list`: the list to write

**Returns:** self for chaining.

**Since:** 1.8.4

### writeLong {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeLong-long-}

```js
writeLong(long value): PacketByteBufferHelper
```

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeLongArray {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeLongArray-long[]-}

```js
writeLongArray(long[] longs): PacketByteBufferHelper
```

**Parameters:**
- `longs`: the long array to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeMap {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeMap-Map-MethodWrapper-MethodWrapper-}

```js
writeMap(Map<K, V> map, MethodWrapper<FriendlyByteBuf, K, ?, ?> keyWriter, MethodWrapper<FriendlyByteBuf, V, ?, ?> valueWriter): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### writeMedium {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeMedium-int-}

```js
writeMedium(int value): PacketByteBufferHelper
```

Writes a medium at the current writer index.

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeNbt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeNbt-NBTElementHelper.NBTCompoundHelper-}

```js
writeNbt(NBTElementHelper.NBTCompoundHelper nbt): PacketByteBufferHelper
```

**Parameters:**
- `nbt`: the nbt

**Returns:** self for chaining.

**Since:** 1.8.4

### writeNullable {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeNullable-Object-MethodWrapper-}

```js
writeNullable(Object value, MethodWrapper<FriendlyByteBuf, Object, ?, ?> writer): PacketByteBufferHelper
```

**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.

**Since:** 1.8.4

**See:**
- [writeOptional(Object, MethodWrapper)](#)

### writeOptional {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeOptional-T-MethodWrapper-}

```js
writeOptional(T value, MethodWrapper<FriendlyByteBuf, T, ?, ?> writer): PacketByteBufferHelper
```

**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.

**Since:** 1.8.4

**See:**
- [writeNullable(Object, MethodWrapper)](#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeNullable-Object-MethodWrapper-)

### writePublicKey {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writePublicKey-PublicKey-}

```js
writePublicKey(PublicKey key): PacketByteBufferHelper
```

**Parameters:**
- `key`: the public key to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeRegistryKey {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeRegistryKey-ResourceKey-}

```js
writeRegistryKey(ResourceKey<?> key): PacketByteBufferHelper
```

Writes a registry key to the buffer.

**Parameters:**
- `key`: the key to write

**Returns:** self for chaining.

**Since:** 1.8.4

### writerIndex {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writerIndex-}

```js
writerIndex(): int
```

**Returns:** the writers current position.

**Since:** 1.8.4

### writeShort {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeShort-int-}

```js
writeShort(int value): PacketByteBufferHelper
```

**Parameters:**
- `value`: the value to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeString {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeString-String-}

```js
writeString(String string): PacketByteBufferHelper
```

**Parameters:**
- `string`: the string to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeString {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeString-String-int-}

```js
writeString(String string, int maxLength): PacketByteBufferHelper
```

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.

**Since:** 1.8.4

### writeUuid {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeUuid-String-}

```js
writeUuid(String uuid): PacketByteBufferHelper
```

**Parameters:**
- `uuid`: the UUID to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeVarInt {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeVarInt-int-}

```js
writeVarInt(int i): PacketByteBufferHelper
```

**Parameters:**
- `i`: the integer to encode as a variable-length integer

**Returns:** self for chaining.

**Since:** 1.8.4

### writeVarLong {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeVarLong-long-}

```js
writeVarLong(long l): PacketByteBufferHelper
```

**Parameters:**
- `l`: the long to store

**Returns:** self for chaining.

**Since:** 1.8.4

### writeZero {#com.jsmacrosce.jsmacros.client.api.helper.PacketByteBufferHelper_writeZero-int-}

```js
writeZero(int length): PacketByteBufferHelper
```

**Parameters:**
- `length`: the amount of zeros to write

**Returns:** self for chaining.

**Since:** 1.8.4
