Try to fix palette resizing

This commit is contained in:
2022-11-20 21:16:53 +08:00
parent 3e83d1dbca
commit 6e597fe4f8
2 changed files with 23 additions and 5 deletions

View File

@ -1,12 +1,12 @@
package level package level
import ( import (
//"fmt"
"github.com/Tnze/go-mc/level/block"
pk "github.com/Tnze/go-mc/net/packet"
"io" "io"
"math/bits" "math/bits"
"strconv" "strconv"
"github.com/Tnze/go-mc/level/block"
pk "github.com/Tnze/go-mc/net/packet"
) )
type State interface { type State interface {
@ -109,7 +109,7 @@ func (p *PaletteContainer[T]) Set(i int, v T) {
bits: vv, bits: vv,
config: p.config, config: p.config,
palette: p.config.create(vv), palette: p.config.create(vv),
data: NewBitStorage(vv, oldLen+1, nil), data: NewBitStorage(p.config.bits(vv), oldLen+1, nil),
} }
// copy // copy
for i := 0; i < oldLen; i++ { for i := 0; i < oldLen; i++ {
@ -177,7 +177,7 @@ func (s statesCfg) bits(bits int) int {
case 5, 6, 7, 8: case 5, 6, 7, 8:
return bits return bits
default: default:
return bits return block.BitsPerBlock
} }
} }

18
level/palette_test.go Normal file
View File

@ -0,0 +1,18 @@
package level
import (
"testing"
)
func TestPaletteResize(t *testing.T) {
container := NewStatesPaletteContainer(16*16*16, 0)
for i := 0; i < 4096; i++ {
container.Set(i, BlocksState(i))
}
for i := 0; i < 4096; i++ {
if container.Get(i) != BlocksState(i) {
t.Errorf("Get Error, got: %v,but expect: %v", container.Get(i), BlocksState(i))
}
}
}