Exemplo n.º 1
0
func deserializeChunkData(raw []byte) (*mapgen.Chunk, error) {
	offset := 0

	version := raw[offset]
	offset++
	if version != 1 {
		return nil, errors.New("Persist: Unrecognized chunk version.")
	}

	chunk := &mapgen.Chunk{}
	for i := 0; i < coords.BlocksPerChunk; i++ {
		chunk.SetBlock(coords.IndexOffset(i), mapgen.Block(raw[offset]))
		offset++
	}

	return chunk, nil
}
Exemplo n.º 2
0
func (fw *FlatWorld) Block(bc coords.Block) mapgen.Block {
	blockSeed := int64(bc.X)
	blockSeed += int64(bc.Y) << 32
	blockSeed += int64(bc.Z) << 16
	blockSeed += int64(fw.seed)
	randGen := rand.New(rand.NewSource(blockSeed))

	if bc.X == 0 && bc.Y == 16 && bc.Z == 0 {
		return mapgen.BLOCK_SPAWN
	}
	if bc.Y < 15 {
		return mapgen.BLOCK_DIRT
	}
	if bc.Y == 15 {
		return mapgen.BLOCK_GRASS
	}
	if bc.X%4 == 0 && bc.Z%4 == 0 && bc.Y < 17 {
		randBlock := 5 + randGen.Int()%9
		return mapgen.Block(randBlock)
	}
	return mapgen.BLOCK_AIR
}