예제 #1
0
func (o *ObjectData) ReadFrom(r io.Reader) (n int64, err error) {
	var rw must.ReadWriter

	o.Data = rw.ReadInt32(r)
	if o.Data != 0 {
		o.SpeedX = rw.ReadInt16(r)
		o.SpeedY = rw.ReadInt16(r)
		o.SpeedZ = rw.ReadInt16(r)
	}

	return rw.Result()
}
예제 #2
0
파일: slot.go 프로젝트: KellyLSB/minero-go
func (s *Slot) ReadFrom(r io.Reader) (n int64, err error) {
	var rw must.ReadWriter

	s.BlockId = rw.ReadInt16(r)
	if s.BlockId == -1 {
		return rw.Result()
	}

	s.Amount = byte(rw.ReadInt8(r))
	s.Damage = rw.ReadInt16(r)
	Length := rw.ReadInt16(r)

	if Length == -1 {
		return rw.Result()
	}

	var br bytes.Buffer

	// Copy gzip'd NBT Compound
	gs := rw.ReadByteArray(r, int(Length))
	bn := bytes.NewBuffer(gs)

	// Ungzip byte array
	gr, err := gzip.NewReader(bn)
	rw.Check(err)
	rw.Must(io.Copy(&br, gr))
	rw.Check(gr.Close())

	// Read NBT Compound
	s.Enchantments, err = nbt.Read(&br)
	rw.Check(err)

	return rw.Result()
}