Пример #1
0
// Load a chunk from its NBT representation
func loadChunk(reader io.Reader) (chunk *Chunk, err os.Error) {
	level, err := nbt.Read(reader)
	if err != nil {
		return
	}

	chunk = &Chunk{
		X:          ChunkCoord(level.Lookup("/Level/xPos").(*nbt.Int).Value),
		Z:          ChunkCoord(level.Lookup("/Level/zPos").(*nbt.Int).Value),
		Blocks:     level.Lookup("/Level/Blocks").(*nbt.ByteArray).Value,
		BlockData:  level.Lookup("/Level/Data").(*nbt.ByteArray).Value,
		SkyLight:   level.Lookup("/Level/SkyLight").(*nbt.ByteArray).Value,
		BlockLight: level.Lookup("/Level/BlockLight").(*nbt.ByteArray).Value,
		HeightMap:  level.Lookup("/Level/HeightMap").(*nbt.ByteArray).Value,
		players:    make(map[EntityID]*Player),
	}
	return
}
Пример #2
0
func loadStartPosition(worldPath string) {
	file, err := os.Open(path.Join(worldPath, "level.dat"), os.O_RDONLY, 0)
	if err != nil {
		log.Exit("loadStartPosition: ", err.String())
	}

	level, err := nbt.Read(file)
	file.Close()
	if err != nil {
		log.Exit("loadStartPosition: ", err.String())
	}

	pos := level.Lookup("/Data/Player/Pos")
	StartPosition = XYZ{
		pos.(*nbt.List).Value[0].(*nbt.Double).Value,
		pos.(*nbt.List).Value[1].(*nbt.Double).Value,
		pos.(*nbt.List).Value[2].(*nbt.Double).Value,
	}
}