github.com/df-mc/dragonfly@v0.9.13/server/world/generator/flat.go (about) 1 package generator 2 3 import ( 4 "github.com/df-mc/dragonfly/server/world" 5 "github.com/df-mc/dragonfly/server/world/chunk" 6 ) 7 8 // Flat is the flat generator of World. It generates flat worlds (like those in vanilla) with no other 9 // decoration. It may be constructed by calling NewFlat. 10 type Flat struct { 11 // biome is the encoded biome that the generator should use. 12 biome uint32 13 // layers is a list of block runtime ID layers placed by the Flat generator. The layers are ordered in a way where 14 // the last element in the slice is placed as the bottom-most block of the chunk. 15 layers []uint32 16 // n is the amount of layers in the slice above. 17 n int16 18 } 19 20 // NewFlat creates a new Flat generator. Chunks generated are completely filled with the world.Biome passed. layers is a 21 // list of block layers placed by the Flat generator. The layers are ordered in a way where the last element in the 22 // slice is placed as the bottom-most block of the chunk. 23 func NewFlat(biome world.Biome, layers []world.Block) Flat { 24 f := Flat{ 25 biome: uint32(biome.EncodeBiome()), 26 layers: make([]uint32, len(layers)), 27 n: int16(len(layers)), 28 } 29 for i, b := range layers { 30 f.layers[i] = world.BlockRuntimeID(b) 31 } 32 return f 33 } 34 35 // GenerateChunk ... 36 func (f Flat) GenerateChunk(_ world.ChunkPos, chunk *chunk.Chunk) { 37 min, max := int16(chunk.Range().Min()), int16(chunk.Range().Max()) 38 39 for x := uint8(0); x < 16; x++ { 40 for z := uint8(0); z < 16; z++ { 41 for y := int16(0); y <= max; y++ { 42 if y < f.n { 43 chunk.SetBlock(x, min+y, z, 0, f.layers[f.n-y-1]) 44 } 45 chunk.SetBiome(x, min+y, z, f.biome) 46 } 47 } 48 } 49 }