示例#1
0
文件: level.go 项目: trichner/mctools
// Save saves level data to the given file.
func (l *Level) Save(file string) error {
	fd, err := os.Create(file)
	if err != nil {
		return err
	}

	defer fd.Close()

	var v struct {
		Data *Level
	}

	v.Data = l

	gz := gzip.NewWriter(fd)
	err = nbt.Marshal(gz, v)
	gz.Close()
	return err
}
示例#2
0
// Write compresses the given chunk and writes the data into the current
// chunk descriptor.
func (cd *ChunkDescriptor) Write(c *Chunk) bool {
	cd.LastModified = time.Now()

	c.UpdateHeightmap()
	c.LastUpdate = cd.LastModified.Unix()

	var buf bytes.Buffer
	w := zlib.NewWriter(&buf)

	var v struct {
		Level *Chunk
	}
	v.Level = c

	err := nbt.Marshal(w, v)
	w.Close()

	cd.data = buf.Bytes()
	return err == nil
}