Merge branch 'patyhank-master'
This commit is contained in:
@ -1,12 +1,11 @@
|
|||||||
package level
|
package level
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"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 +108,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, nil),
|
||||||
}
|
}
|
||||||
// copy
|
// copy
|
||||||
for i := 0; i < oldLen; i++ {
|
for i := 0; i < oldLen; i++ {
|
||||||
@ -124,7 +123,7 @@ func (p *PaletteContainer[T]) Set(i int, v T) {
|
|||||||
if vv, ok := newPalette.palette.id(v); !ok {
|
if vv, ok := newPalette.palette.id(v); !ok {
|
||||||
panic("not reachable")
|
panic("not reachable")
|
||||||
} else {
|
} else {
|
||||||
newPalette.data.Set(oldLen, vv)
|
newPalette.data.Set(i, vv)
|
||||||
}
|
}
|
||||||
*p = newPalette
|
*p = newPalette
|
||||||
}
|
}
|
||||||
@ -177,7 +176,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
18
level/palette_test.go
Normal 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user