예제 #1
0
// NOTE: ChunkStoreForDimension shouldn't really be used in the server just
// yet.
func (world *WorldStore) ChunkStoreForDimension(dimension DimensionId) (store chunkstore.IChunkStore, err error) {
	fgStore, err := chunkstore.ChunkStoreForLevel(world.WorldPath, world.LevelData, dimension)
	if err != nil {
		return
	}
	store = chunkstore.NewChunkService(fgStore)
	go store.Serve()
	return
}
예제 #2
0
func LoadWorldStore(worldPath string) (world *WorldStore, err error) {
	levelData, err := loadLevelData(worldPath)
	if err != nil {
		return
	}

	// In both single-player and SMP maps, the 'spawn position' is stored in
	// the level data.
	x, xok := levelData.Lookup("Data/SpawnX").(*nbt.Int)
	y, yok := levelData.Lookup("Data/SpawnY").(*nbt.Int)
	z, zok := levelData.Lookup("Data/SpawnZ").(*nbt.Int)
	if !xok || !yok || !zok {
		err = errors.New("Invalid map level data: does not contain Spawn{X,Y,Z}")
		log.Printf("%#v", levelData)
		return
	}
	spawnPosition := BlockXyz{
		BlockCoord(x.Value),
		BlockYCoord(y.Value),
		BlockCoord(z.Value),
	}

	var timeTicks Ticks
	if timeTag, ok := levelData.Lookup("Data/Time").(*nbt.Long); ok {
		timeTicks = Ticks(timeTag.Value)
	}

	var chunkStores []chunkstore.IChunkStore
	persistantChunkStore, err := chunkstore.ChunkStoreForLevel(worldPath, levelData, DimensionNormal)
	if err != nil {
		return nil, err
	}

	persistantChunkService := chunkstore.NewChunkService(persistantChunkStore)
	chunkStores = append(chunkStores, persistantChunkService)

	var seed int64
	if seedNbt, ok := levelData.Lookup("Data/RandomSeed").(*nbt.Long); ok {
		seed = seedNbt.Value
	} else {
		seed = time.Now().Unix()
	}

	chunkStores = append(chunkStores, chunkstore.NewChunkService(generation.NewTestGenerator(seed)))

	for _, store := range chunkStores {
		go store.Serve()
	}

	world = &WorldStore{
		WorldPath:     worldPath,
		Seed:          seed,
		Time:          timeTicks,
		LevelData:     levelData,
		ChunkStore:    chunkstore.NewChunkService(chunkstore.NewMultiStore(chunkStores, persistantChunkService)),
		SpawnPosition: spawnPosition,
	}

	go world.ChunkStore.Serve()

	return
}