Пример #1
0
func (s *Slot) WriteTo(w io.Writer) (n int64, err error) {
	var rw must.ReadWriter

	rw.WriteInt16(w, s.BlockId)
	if s.BlockId == -1 {
		return rw.Result()
	}

	rw.WriteInt8(w, int8(s.Amount))
	rw.WriteInt16(w, s.Damage)

	if s.Enchantments == nil {
		rw.WriteInt16(w, -1)
		return rw.Result()
	}

	var bn, bw bytes.Buffer

	rw.Check(nbt.Write(&bn, s.Enchantments))
	gw := gzip.NewWriter(&bw)
	rw.Must(io.Copy(gw, &bn))
	rw.Check(gw.Close())

	rw.WriteInt16(w, int16(bw.Len()))
	rw.WriteByteArray(w, bw.Bytes())

	return rw.Result()
}