Example #1
0
func newChunkFromReader(reader chunkstore.IChunkReader, shard *ChunkShard) (chunk *Chunk) {
	chunk = &Chunk{
		shard:       shard,
		loc:         reader.ChunkLoc(),
		blocks:      reader.Blocks(),
		blockData:   reader.BlockData(),
		skyLight:    reader.SkyLight(),
		blockLight:  reader.BlockLight(),
		heightMap:   reader.HeightMap(),
		entities:    make(map[EntityId]gamerules.INonPlayerEntity),
		blockExtra:  make(map[BlockIndex]interface{}),
		rand:        rand.New(rand.NewSource(time.UTC().Seconds())),
		subscribers: make(map[EntityId]gamerules.IPlayerClient),
		playersData: make(map[EntityId]*playerData),
		onUnsub:     make(map[EntityId][]gamerules.IUnsubscribed),

		activeBlocks:    make(map[BlockIndex]bool),
		newActiveBlocks: make(map[BlockIndex]bool),
	}

	chunk.addEntities(reader.Entities())

	return
}
Example #2
0
func newChunkFromReader(reader chunkstore.IChunkReader, shard *ChunkShard) (chunk *Chunk) {
	chunk = &Chunk{
		shard:        shard,
		loc:          reader.ChunkLoc(),
		blocks:       reader.Blocks(),
		blockData:    reader.BlockData(),
		skyLight:     reader.SkyLight(),
		blockLight:   reader.BlockLight(),
		heightMap:    reader.HeightMap(),
		entities:     make(map[EntityId]gamerules.INonPlayerEntity),
		tileEntities: make(map[BlockIndex]gamerules.ITileEntity),
		rand:         rand.New(rand.NewSource(time.UTC().Seconds())),
		subscribers:  make(map[EntityId]gamerules.IPlayerClient),
		playersData:  make(map[EntityId]*playerData),
		onUnsub:      make(map[EntityId][]gamerules.IUnsubscribed),
		storeDirty:   false,

		activeBlocks:    make(map[BlockIndex]bool),
		newActiveBlocks: make(map[BlockIndex]bool),
		tickAll:         true,
	}

	entities := reader.Entities()
	for _, entity := range entities {
		entityId := chunk.shard.entityMgr.NewEntity()
		entity.SetEntityId(entityId)
		chunk.entities[entityId] = entity
	}

	// Load tile entities.
	tileEntities := reader.TileEntities()
	for _, tileEntity := range tileEntities {
		blockLoc := tileEntity.Block()
		chunkLoc, subChunk := blockLoc.ToChunkLocal()
		if !chunk.loc.Equals(*chunkLoc) {
			log.Printf("%v: loaded tile entity not in this chunk, but at location %#v", chunk, blockLoc)
		} else if index, ok := subChunk.BlockIndex(); !ok {
			log.Printf("%v: loaded tile entity at bad location %#v", chunk, blockLoc)
		} else {
			tileEntity.SetChunk(chunk)
			chunk.tileEntities[index] = tileEntity
		}
	}

	return
}