fix bitsPerBlock calculation bug in NewXXXXPaletteContainerWithData
This commit is contained in:
@ -67,6 +67,16 @@ func calcBitStorageSize(bits, length int) (size int) {
|
||||
return (length + valuesPerLong - 1) / valuesPerLong
|
||||
}
|
||||
|
||||
// calcBitsPerValue calculate when "longs" number of uint64 stores
|
||||
// "length" number of value, how many bits are used for each value.
|
||||
func calcBitsPerValue(length, longs int) (bits int) {
|
||||
if longs == 0 || length == 0 {
|
||||
return 0
|
||||
}
|
||||
valuePerLong := (length + longs - 1) / longs
|
||||
return 64 / valuePerLong
|
||||
}
|
||||
|
||||
type newBitStorageErr struct {
|
||||
ArrlLen int
|
||||
WantLen int
|
||||
|
@ -2,7 +2,6 @@ package level
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math/bits"
|
||||
"strconv"
|
||||
|
||||
"github.com/Tnze/go-mc/level/biome"
|
||||
@ -36,7 +35,7 @@ func NewStatesPaletteContainer(length int, defaultValue BlocksState) *PaletteCon
|
||||
|
||||
func NewStatesPaletteContainerWithData(length int, data []uint64, pat []BlocksState) *PaletteContainer[BlocksState] {
|
||||
var p palette[BlocksState]
|
||||
n := bits.Len(uint(len(pat) - 1))
|
||||
n := calcBitsPerValue(length, len(data))
|
||||
switch n {
|
||||
case 0:
|
||||
p = &singleValuePalette[BlocksState]{pat[0]}
|
||||
@ -78,7 +77,7 @@ func NewBiomesPaletteContainer(length int, defaultValue BiomesState) *PaletteCon
|
||||
|
||||
func NewBiomesPaletteContainerWithData(length int, data []uint64, pat []BiomesState) *PaletteContainer[BiomesState] {
|
||||
var p palette[BiomesState]
|
||||
n := bits.Len(uint(len(pat) - 1))
|
||||
n := calcBitsPerValue(length, len(data))
|
||||
switch n {
|
||||
case 0:
|
||||
p = &singleValuePalette[BiomesState]{pat[0]}
|
||||
|
Reference in New Issue
Block a user