Ejemplo n.º 1
0
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()
}
Ejemplo n.º 2
0
func Debug(f io.Reader) {
	var r io.Reader
	if !Flags.Quiet {
		r = iotest.NewReadLogger("r:", f)
	} else {
		r = f
	}

	c, err := nbt.Read(r)
	if err != nil {
		log.Fatalln("nbt.Read:", err)
	}

	log.Printf("Top level compound name: %q\n", c.Name)
	fmt.Println(nbt.Pretty(c.String()))
}