github.com/df-mc/dragonfly@v0.9.13/server/world/chunk/heightmap.go (about)

     1  package chunk
     2  
     3  import (
     4  	"math"
     5  )
     6  
     7  // HeightMap represents the height map of a chunk. It holds the y value of all the highest blocks in the chunk
     8  // that diffuse or obstruct light.
     9  type HeightMap []int16
    10  
    11  // At returns the height map value at a specific column in the chunk.
    12  func (h HeightMap) At(x, z uint8) int16 {
    13  	return h[(uint16(x)<<4)|uint16(z)]
    14  }
    15  
    16  // Set changes the height map value at a specific column in the chunk.
    17  func (h HeightMap) Set(x, z uint8, val int16) {
    18  	h[(uint16(x)<<4)|uint16(z)] = val
    19  }
    20  
    21  // HighestNeighbour returns the height map value of the highest directly neighbouring column of the x and z values
    22  // passed.
    23  func (h HeightMap) HighestNeighbour(x, z uint8) int16 {
    24  	highest := int16(math.MinInt16)
    25  	if x != 15 {
    26  		if val := h.At(x+1, z); val > highest {
    27  			highest = val
    28  		}
    29  	}
    30  	if x != 0 {
    31  		if val := h.At(x-1, z); val > highest {
    32  			highest = val
    33  		}
    34  	}
    35  	if z != 15 {
    36  		if val := h.At(x, z+1); val > highest {
    37  			highest = val
    38  		}
    39  	}
    40  	if z != 0 {
    41  		if val := h.At(x, z-1); val > highest {
    42  			highest = val
    43  		}
    44  	}
    45  	return highest
    46  }