Ejemplo n.º 1
0
func (sh *SimplexHills) Chunk(cc coords.Chunk) *mapgen.Chunk {
	// Build the height map
	hMap := make([][]int, coords.ChunkWidth)
	for x := range hMap {
		hMap[x] = make([]int, coords.ChunkDepth)
		for z := range hMap[x] {
			oc := coords.Offset{X: x, Y: 0, Z: z}
			bc := oc.Block(cc)
			hMap[x][z] = int(sh.heightAt(float64(bc.X), float64(bc.Z)))
		}
	}

	chunk := &mapgen.Chunk{}
	for ocX := 0; ocX < coords.ChunkWidth; ocX++ {
		for ocY := 0; ocY < coords.ChunkHeight; ocY++ {
			for ocZ := 0; ocZ < coords.ChunkDepth; ocZ++ {
				oc := coords.Offset{X: ocX, Y: ocY, Z: ocZ}
				bc := oc.Block(cc)
				block := sh.block(bc, hMap[oc.X][oc.Z])
				chunk.SetBlock(oc, block)
			}
		}
	}
	return chunk
}
Ejemplo n.º 2
0
func (c *Chunk) SetBlock(oc coords.Offset, newBlock Block) {
	c.blocks[oc.Index()] = newBlock
}
Ejemplo n.º 3
0
func (c *Chunk) Block(oc coords.Offset) Block {
	return c.blocks[oc.Index()]
}