Пример #1
0
func cmdNbt(args []string) (err error) {
	if len(args) != 1 {
		os.Stderr.WriteString("usage: " + os.Args[0] + " nbt <NBT file path>\n")
		return
	}

	file, err := os.Open(args[0])
	if err != nil {
		return
	}
	defer file.Close()

	gzipReader, err := gzip.NewReader(file)
	if err != nil {
		return
	}
	defer gzipReader.Close()

	namedTag, err := nbt.Read(gzipReader)
	if err != nil {
		return
	}

	displayNbt(1, namedTag)

	return
}
Пример #2
0
// Load a chunk from its NBT representation
func newNbtChunkReader(reader io.Reader) (r *nbtChunkReader, err error) {
	chunkTag, err := nbt.Read(reader)
	if err != nil {
		return
	}

	r = &nbtChunkReader{
		chunkTag: chunkTag,
	}

	return
}
Пример #3
0
func loadLevelData(worldPath string) (levelData nbt.ITag, err error) {
	filename := path.Join(worldPath, "level.dat")
	file, err := os.Open(filename)
	if err != nil {
		return
	}
	defer file.Close()

	gzipReader, err := gzip.NewReader(file)
	if err != nil {
		return
	}
	defer gzipReader.Close()

	levelData, err = nbt.Read(gzipReader)

	return
}
Пример #4
0
func (world *WorldStore) PlayerData(user string) (playerData *nbt.Compound, err error) {
	file, err := os.Open(path.Join(world.WorldPath, "players", user+".dat"))
	if err != nil {
		//if errno, ok := util.Errno(err); ok && errno == os.ENOENT {
		// Player data simply doesn't exist. Not an error, playerData = nil is
		// the result.
		//	return nil, nil
		//}
		return nil, nil
	}
	defer file.Close()

	gzipReader, err := gzip.NewReader(file)
	if err != nil {
		return
	}
	defer gzipReader.Close()

	playerData, err = nbt.Read(gzipReader)

	return
}