Skip to content

Commit

Permalink
fix: use RegistryFriendlyByteBuf#readableBytes for reading bytearray …
Browse files Browse the repository at this point in the history
…payload
  • Loading branch information
Apehum committed Apr 29, 2024
1 parent c6ab289 commit db8cc76
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload
import net.minecraft.resources.ResourceLocation

class ByteArrayCodec(
private val channelKey: ResourceLocation
channelKey: ResourceLocation
) : StreamCodec<RegistryFriendlyByteBuf, ByteArrayPayload> {

val type = CustomPacketPayload.Type<ByteArrayPayload>(channelKey)

override fun decode(buf: RegistryFriendlyByteBuf): ByteArrayPayload {
val length = buf.readVarInt()
val length = buf.readableBytes()

val data = ByteArray(length)
buf.readBytes(data)
Expand All @@ -21,7 +21,6 @@ class ByteArrayCodec(
}

override fun encode(buf: RegistryFriendlyByteBuf, payload: ByteArrayPayload) {
buf.writeVarInt(payload.data.size)
buf.writeBytes(payload.data)
}
}

0 comments on commit db8cc76

Please sign in to comment.