Closed jobpaardekooper closed 9 months ago
You should implement net.FieldEncoder
in your array type. And when you do so, write elements in a loop internally.
Thanks for the quick response. Why is this not part of the primitive types provided by this library? Basically all fields in the protocol are here in the library and can be used except for these non-length-prefixed arrays.
Didn't found any of this, which packet are you building?
Currently I am working on the chunk packet. That includes an array of chunk sections that is not length-prefixed. This is because the client calculates the array length based on the world height it has received before. This is not the only packet though.
There is an implement in this file:
https://github.com/Tnze/go-mc/blob/master/level/chunk.go
that type Chunk
has a method named WriteTo()
.
I'm not sure it's up to date. Hope the piece of code can answer your question.
Is there a way to write an array to a packet without prefixing the length? Currently if you use
pk.Array
orpk.Ary
it will prefix the length when you write the packet. But for some packets the client will already know the length from the context so it does not expect a prefixed length. Any way to write such an array in a nice way?