fix bugs in PaletteContainer
This commit is contained in:
@ -2,13 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"github.com/Tnze/go-mc/chat"
|
||||||
|
"github.com/Tnze/go-mc/server"
|
||||||
"image"
|
"image"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/chat"
|
|
||||||
"github.com/Tnze/go-mc/server"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const MaxPlayer = 20
|
const MaxPlayer = 20
|
||||||
@ -23,7 +22,13 @@ func main() {
|
|||||||
log.Fatalf("Set server info error: %v", err)
|
log.Fatalf("Set server info error: %v", err)
|
||||||
}
|
}
|
||||||
defaultDimension := server.NewSimpleDim(16)
|
defaultDimension := server.NewSimpleDim(16)
|
||||||
defaultDimension.LoadChunk(server.ChunkPos{X: 0, Z: 0}, server.EmptyChunk(16))
|
chunk00 := server.EmptyChunk(16)
|
||||||
|
for s := 0; s < 16; s++ {
|
||||||
|
for i := 0; i < 16*16; i++ {
|
||||||
|
chunk00.Sections[s].SetBlock(i, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defaultDimension.LoadChunk(server.ChunkPos{X: 0, Z: 0}, chunk00)
|
||||||
s := server.Server{
|
s := server.Server{
|
||||||
ListPingHandler: serverInfo,
|
ListPingHandler: serverInfo,
|
||||||
LoginHandler: &server.MojangLoginHandler{
|
LoginHandler: &server.MojangLoginHandler{
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Tnze/go-mc/level"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
@ -189,7 +190,7 @@ func drawSection(s *save.Chunk, img *image.RGBA) {
|
|||||||
|
|
||||||
// decode status
|
// decode status
|
||||||
data := *(*[]uint64)(unsafe.Pointer(&s.BlockStates)) // convert []int64 into []uint64
|
data := *(*[]uint64)(unsafe.Pointer(&s.BlockStates)) // convert []int64 into []uint64
|
||||||
bs := save.NewBitStorage(bpb, 4096, data)
|
bs := level.NewBitStorage(bpb, 4096, data)
|
||||||
for y := 0; y < 16; y++ {
|
for y := 0; y < 16; y++ {
|
||||||
layerImg := image.NewRGBA(image.Rect(0, 0, 16, 16))
|
layerImg := image.NewRGBA(image.Rect(0, 0, 16, 16))
|
||||||
for i := 16*16 - 1; i >= 0; i-- {
|
for i := 16*16 - 1; i >= 0; i-- {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package save
|
package level
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -29,7 +29,13 @@ type BitStorage struct {
|
|||||||
// The "data" is optional for initializing. Panic if data != nil && len(data) != calcBitStorageSize(bits, length).
|
// The "data" is optional for initializing. Panic if data != nil && len(data) != calcBitStorageSize(bits, length).
|
||||||
func NewBitStorage(bits, length int, data []uint64) (b *BitStorage) {
|
func NewBitStorage(bits, length int, data []uint64) (b *BitStorage) {
|
||||||
if bits == 0 {
|
if bits == 0 {
|
||||||
return nil
|
return &BitStorage{
|
||||||
|
data: nil,
|
||||||
|
mask: 0,
|
||||||
|
bits: 0,
|
||||||
|
length: length,
|
||||||
|
valuesPerLong: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b = &BitStorage{
|
b = &BitStorage{
|
||||||
@ -76,13 +82,15 @@ func (b *BitStorage) calcIndex(n int) (c, o int) {
|
|||||||
|
|
||||||
// Swap sets v into [i], and return the previous [i] value.
|
// Swap sets v into [i], and return the previous [i] value.
|
||||||
func (b *BitStorage) Swap(i, v int) (old int) {
|
func (b *BitStorage) Swap(i, v int) (old int) {
|
||||||
if b == nil || i < 0 || i > b.length-1 {
|
if b.valuesPerLong == 0 {
|
||||||
panic(indexOutOfBounds)
|
return 0
|
||||||
}
|
}
|
||||||
if v < 0 || uint64(v) > b.mask {
|
if v < 0 || uint64(v) > b.mask {
|
||||||
panic(valueOutOfBounds)
|
panic(valueOutOfBounds)
|
||||||
}
|
}
|
||||||
|
if i < 0 || i > b.length-1 {
|
||||||
|
panic(indexOutOfBounds)
|
||||||
|
}
|
||||||
c, offset := b.calcIndex(i)
|
c, offset := b.calcIndex(i)
|
||||||
l := b.data[c]
|
l := b.data[c]
|
||||||
old = int(l >> offset & b.mask)
|
old = int(l >> offset & b.mask)
|
||||||
@ -92,12 +100,15 @@ func (b *BitStorage) Swap(i, v int) (old int) {
|
|||||||
|
|
||||||
// Set sets v into [i].
|
// Set sets v into [i].
|
||||||
func (b *BitStorage) Set(i, v int) {
|
func (b *BitStorage) Set(i, v int) {
|
||||||
if b == nil || i < 0 || i > b.length-1 {
|
if b.valuesPerLong == 0 {
|
||||||
panic(indexOutOfBounds)
|
return
|
||||||
}
|
}
|
||||||
if v < 0 || uint64(v) > b.mask {
|
if v < 0 || uint64(v) > b.mask {
|
||||||
panic(valueOutOfBounds)
|
panic(valueOutOfBounds)
|
||||||
}
|
}
|
||||||
|
if i < 0 || i > b.length-1 {
|
||||||
|
panic(indexOutOfBounds)
|
||||||
|
}
|
||||||
|
|
||||||
c, offset := b.calcIndex(i)
|
c, offset := b.calcIndex(i)
|
||||||
l := b.data[c]
|
l := b.data[c]
|
||||||
@ -106,7 +117,10 @@ func (b *BitStorage) Set(i, v int) {
|
|||||||
|
|
||||||
// Get gets [i] value.
|
// Get gets [i] value.
|
||||||
func (b *BitStorage) Get(i int) int {
|
func (b *BitStorage) Get(i int) int {
|
||||||
if b == nil || i < 0 || i > b.length-1 {
|
if b.valuesPerLong == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if i < 0 || i > b.length-1 {
|
||||||
panic(indexOutOfBounds)
|
panic(indexOutOfBounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,9 +131,6 @@ func (b *BitStorage) Get(i int) int {
|
|||||||
|
|
||||||
// Len is the number of stored values.
|
// Len is the number of stored values.
|
||||||
func (b *BitStorage) Len() int {
|
func (b *BitStorage) Len() int {
|
||||||
if b == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return b.length
|
return b.length
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +166,9 @@ func (b *BitStorage) ReadFrom(r io.Reader) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BitStorage) WriteTo(w io.Writer) (int64, error) {
|
func (b *BitStorage) WriteTo(w io.Writer) (int64, error) {
|
||||||
|
if b == nil {
|
||||||
|
return pk.VarInt(0).WriteTo(w)
|
||||||
|
}
|
||||||
n, err := pk.VarInt(len(b.data)).WriteTo(w)
|
n, err := pk.VarInt(len(b.data)).WriteTo(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return n, err
|
@ -1,4 +1,4 @@
|
|||||||
package save
|
package level
|
||||||
|
|
||||||
import (
|
import (
|
||||||
pk "github.com/Tnze/go-mc/net/packet"
|
pk "github.com/Tnze/go-mc/net/packet"
|
@ -1,4 +1,4 @@
|
|||||||
package save
|
package level
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@ -7,42 +7,38 @@ import (
|
|||||||
pk "github.com/Tnze/go-mc/net/packet"
|
pk "github.com/Tnze/go-mc/net/packet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlockState interface {
|
type state = int
|
||||||
}
|
|
||||||
|
|
||||||
type PaletteContainer struct {
|
type PaletteContainer struct {
|
||||||
bits int
|
bits int
|
||||||
maps IdMaps
|
config func(bits int) palette
|
||||||
config func(maps IdMaps, bits int) palette
|
|
||||||
palette palette
|
palette palette
|
||||||
data *BitStorage
|
data *BitStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStatesPaletteContainer(maps IdMaps, length int) *PaletteContainer {
|
func NewStatesPaletteContainer(length int, defaultValue state) *PaletteContainer {
|
||||||
return &PaletteContainer{
|
return &PaletteContainer{
|
||||||
bits: 0,
|
bits: 0,
|
||||||
maps: maps,
|
|
||||||
config: createStatesPalette,
|
config: createStatesPalette,
|
||||||
palette: createStatesPalette(maps, 0),
|
palette: &singleValuePalette{v: defaultValue},
|
||||||
data: NewBitStorage(0, length, nil),
|
data: NewBitStorage(0, length, nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBiomesPaletteContainer(maps IdMaps, length int) *PaletteContainer {
|
func NewBiomesPaletteContainer(length int, defaultValue state) *PaletteContainer {
|
||||||
return &PaletteContainer{
|
return &PaletteContainer{
|
||||||
bits: 0,
|
bits: 0,
|
||||||
maps: maps,
|
|
||||||
config: createBiomesPalette,
|
config: createBiomesPalette,
|
||||||
palette: createBiomesPalette(maps, 0),
|
palette: &singleValuePalette{v: defaultValue},
|
||||||
data: NewBitStorage(0, length, nil),
|
data: NewBitStorage(0, length, nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PaletteContainer) Get(i int) BlockState {
|
func (p *PaletteContainer) Get(i int) state {
|
||||||
return p.palette.value(p.data.Get(i))
|
return p.palette.value(p.data.Get(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PaletteContainer) Set(i int, v BlockState) {
|
func (p *PaletteContainer) Set(i int, v state) {
|
||||||
if vv, ok := p.palette.id(v); ok {
|
if vv, ok := p.palette.id(v); ok {
|
||||||
p.data.Set(i, vv)
|
p.data.Set(i, vv)
|
||||||
} else {
|
} else {
|
||||||
@ -50,14 +46,13 @@ func (p *PaletteContainer) Set(i int, v BlockState) {
|
|||||||
oldLen := p.data.Len()
|
oldLen := p.data.Len()
|
||||||
newPalette := PaletteContainer{
|
newPalette := PaletteContainer{
|
||||||
bits: vv,
|
bits: vv,
|
||||||
maps: p.maps,
|
|
||||||
config: p.config,
|
config: p.config,
|
||||||
palette: p.config(p.maps, vv),
|
palette: p.config(vv),
|
||||||
data: NewBitStorage(vv, oldLen+1, nil),
|
data: NewBitStorage(vv, oldLen+1, nil),
|
||||||
}
|
}
|
||||||
// copy
|
// copy
|
||||||
for i := 0; i < oldLen; i++ {
|
for i := 0; i < oldLen; i++ {
|
||||||
raw := p.palette.value(i)
|
raw := p.data.Get(i)
|
||||||
if vv, ok := newPalette.palette.id(raw); !ok {
|
if vv, ok := newPalette.palette.id(raw); !ok {
|
||||||
panic("not reachable")
|
panic("not reachable")
|
||||||
} else {
|
} else {
|
||||||
@ -80,7 +75,7 @@ func (p *PaletteContainer) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.palette = p.config(p.maps, int(bits))
|
p.palette = p.config(int(bits))
|
||||||
|
|
||||||
nn, err := p.palette.ReadFrom(r)
|
nn, err := p.palette.ReadFrom(r)
|
||||||
n += nn
|
n += nn
|
||||||
@ -96,47 +91,28 @@ func (p *PaletteContainer) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createStatesPalette(maps IdMaps, bits int) palette {
|
func createStatesPalette(bits int) palette {
|
||||||
switch bits {
|
switch bits {
|
||||||
case 0:
|
case 0:
|
||||||
return &singleValuePalette{
|
return &singleValuePalette{v: -1}
|
||||||
maps: maps,
|
|
||||||
v: nil,
|
|
||||||
}
|
|
||||||
case 1, 2, 3, 4:
|
case 1, 2, 3, 4:
|
||||||
return &linearPalette{
|
return &linearPalette{bits: 4, values: make([]state, 0, 1<<4)}
|
||||||
maps: maps,
|
|
||||||
bits: 4,
|
|
||||||
}
|
|
||||||
case 5, 6, 7, 8:
|
case 5, 6, 7, 8:
|
||||||
// TODO: HashMapPalette
|
// TODO: HashMapPalette
|
||||||
return &linearPalette{
|
return &linearPalette{bits: bits, values: make([]state, 0, 1<<bits)}
|
||||||
maps: maps,
|
|
||||||
bits: bits,
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return &globalPalette{
|
return &globalPalette{}
|
||||||
maps: maps,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createBiomesPalette(maps IdMaps, bits int) palette {
|
func createBiomesPalette(bits int) palette {
|
||||||
switch bits {
|
switch bits {
|
||||||
case 0:
|
case 0:
|
||||||
return &singleValuePalette{
|
return &singleValuePalette{v: -1}
|
||||||
maps: maps,
|
|
||||||
v: nil,
|
|
||||||
}
|
|
||||||
case 1, 2, 3:
|
case 1, 2, 3:
|
||||||
return &linearPalette{
|
return &linearPalette{bits: bits, values: make([]state, 0, 1<<bits)}
|
||||||
maps: maps,
|
|
||||||
bits: bits,
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return &globalPalette{
|
return &globalPalette{}
|
||||||
maps: maps,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,25 +127,15 @@ func (p *PaletteContainer) WriteTo(w io.Writer) (n int64, err error) {
|
|||||||
type palette interface {
|
type palette interface {
|
||||||
pk.FieldEncoder
|
pk.FieldEncoder
|
||||||
pk.FieldDecoder
|
pk.FieldDecoder
|
||||||
id(v BlockState) (int, bool)
|
id(v state) (int, bool)
|
||||||
value(i int) BlockState
|
value(i int) state
|
||||||
}
|
|
||||||
|
|
||||||
type IdMaps interface {
|
|
||||||
getID(state BlockState) (id int)
|
|
||||||
getValue(id int) (state BlockState)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type singleValuePalette struct {
|
type singleValuePalette struct {
|
||||||
maps IdMaps
|
v state
|
||||||
v BlockState
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleValuePalette) id(v BlockState) (int, bool) {
|
func (s *singleValuePalette) id(v state) (int, bool) {
|
||||||
if s.v == nil {
|
|
||||||
s.v = v
|
|
||||||
return 0, true
|
|
||||||
}
|
|
||||||
if s.v == v {
|
if s.v == v {
|
||||||
return 0, true
|
return 0, true
|
||||||
}
|
}
|
||||||
@ -177,8 +143,8 @@ func (s *singleValuePalette) id(v BlockState) (int, bool) {
|
|||||||
return 1, false
|
return 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleValuePalette) value(i int) BlockState {
|
func (s *singleValuePalette) value(i int) state {
|
||||||
if s.v != nil && i == 0 {
|
if i == 0 {
|
||||||
return s.v
|
return s.v
|
||||||
}
|
}
|
||||||
panic("singleValuePalette: " + strconv.Itoa(i) + " out of bounds")
|
panic("singleValuePalette: " + strconv.Itoa(i) + " out of bounds")
|
||||||
@ -190,21 +156,20 @@ func (s *singleValuePalette) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.v = s.maps.getValue(int(i))
|
s.v = state(i)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleValuePalette) WriteTo(w io.Writer) (n int64, err error) {
|
func (s *singleValuePalette) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
return pk.VarInt(s.maps.getID(s.v)).WriteTo(w)
|
return pk.VarInt(s.v).WriteTo(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
type linearPalette struct {
|
type linearPalette struct {
|
||||||
maps IdMaps
|
values []state
|
||||||
values []BlockState
|
|
||||||
bits int
|
bits int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *linearPalette) id(v BlockState) (int, bool) {
|
func (l *linearPalette) id(v state) (int, bool) {
|
||||||
for i, t := range l.values {
|
for i, t := range l.values {
|
||||||
if t == v {
|
if t == v {
|
||||||
return i, true
|
return i, true
|
||||||
@ -217,11 +182,11 @@ func (l *linearPalette) id(v BlockState) (int, bool) {
|
|||||||
return l.bits + 1, false
|
return l.bits + 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *linearPalette) value(i int) BlockState {
|
func (l *linearPalette) value(i int) state {
|
||||||
if i >= 0 && i < len(l.values) {
|
if i >= 0 && i < len(l.values) {
|
||||||
return l.values[i]
|
return l.values[i]
|
||||||
}
|
}
|
||||||
return nil
|
panic("linearPalette: " + strconv.Itoa(i) + " out of bounds")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *linearPalette) ReadFrom(r io.Reader) (n int64, err error) {
|
func (l *linearPalette) ReadFrom(r io.Reader) (n int64, err error) {
|
||||||
@ -235,7 +200,7 @@ func (l *linearPalette) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
} else {
|
} else {
|
||||||
n += nn
|
n += nn
|
||||||
}
|
}
|
||||||
l.values[i] = l.maps.getValue(int(value))
|
l.values[i] = state(value)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -245,7 +210,7 @@ func (l *linearPalette) WriteTo(w io.Writer) (n int64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, v := range l.values {
|
for _, v := range l.values {
|
||||||
if nn, err := pk.VarInt(l.maps.getID(v)).WriteTo(w); err != nil {
|
if nn, err := pk.VarInt(v).WriteTo(w); err != nil {
|
||||||
return n + nn, err
|
return n + nn, err
|
||||||
} else {
|
} else {
|
||||||
n += nn
|
n += nn
|
||||||
@ -254,15 +219,13 @@ func (l *linearPalette) WriteTo(w io.Writer) (n int64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type globalPalette struct {
|
type globalPalette struct{}
|
||||||
maps IdMaps
|
|
||||||
|
func (g *globalPalette) id(v state) (int, bool) {
|
||||||
|
return v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *globalPalette) id(v BlockState) (int, bool) {
|
func (g *globalPalette) value(i int) state {
|
||||||
return g.maps.getID(v), true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *globalPalette) value(i int) BlockState {
|
|
||||||
return g.value(i)
|
return g.value(i)
|
||||||
}
|
}
|
||||||
|
|
@ -2,12 +2,13 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/Tnze/go-mc/data/packetid"
|
|
||||||
pk "github.com/Tnze/go-mc/net/packet"
|
|
||||||
"github.com/Tnze/go-mc/save"
|
|
||||||
"io"
|
"io"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/Tnze/go-mc/data/packetid"
|
||||||
|
"github.com/Tnze/go-mc/level"
|
||||||
|
pk "github.com/Tnze/go-mc/net/packet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dimension interface {
|
type Dimension interface {
|
||||||
@ -24,14 +25,28 @@ type DimInfo struct {
|
|||||||
type ChunkPos struct{ X, Z int }
|
type ChunkPos struct{ X, Z int }
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
sections []Section
|
Sections []Section
|
||||||
HeightMaps *save.BitStorage
|
HeightMaps *level.BitStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
type Section struct {
|
type Section struct {
|
||||||
blockCount int16
|
blockCount int16
|
||||||
States *save.PaletteContainer
|
States *level.PaletteContainer
|
||||||
Biomes *save.PaletteContainer
|
Biomes *level.PaletteContainer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Section) GetBlock(i int) int {
|
||||||
|
return s.States.Get(i)
|
||||||
|
}
|
||||||
|
func (s *Section) SetBlock(i int, v int) {
|
||||||
|
// TODO: Handle cave air and void air
|
||||||
|
if s.States.Get(i) != 0 {
|
||||||
|
s.blockCount--
|
||||||
|
}
|
||||||
|
if v != 0 {
|
||||||
|
s.blockCount++
|
||||||
|
}
|
||||||
|
s.States.Set(i, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Section) WriteTo(w io.Writer) (int64, error) {
|
func (s *Section) WriteTo(w io.Writer) (int64, error) {
|
||||||
@ -55,13 +70,13 @@ func EmptyChunk(secs int) *Chunk {
|
|||||||
for i := range sections {
|
for i := range sections {
|
||||||
sections[i] = Section{
|
sections[i] = Section{
|
||||||
blockCount: 0,
|
blockCount: 0,
|
||||||
States: save.NewStatesPaletteContainer(nil, 16*16*16),
|
States: level.NewStatesPaletteContainer(16*16*16, 0),
|
||||||
Biomes: save.NewBiomesPaletteContainer(nil, 4*4*4),
|
Biomes: level.NewBiomesPaletteContainer(4*4*4, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &Chunk{
|
return &Chunk{
|
||||||
sections: sections,
|
Sections: sections,
|
||||||
HeightMaps: save.NewBitStorage(bits.Len(uint(secs)*16), 16*16, nil),
|
HeightMaps: level.NewBitStorage(bits.Len(uint(secs)*16), 16*16, nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +97,7 @@ func (c *Chunk) WriteTo(w io.Writer) (int64, error) {
|
|||||||
|
|
||||||
func (c *Chunk) Data() ([]byte, error) {
|
func (c *Chunk) Data() ([]byte, error) {
|
||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
for _, section := range c.sections {
|
for _, section := range c.Sections {
|
||||||
_, err := section.WriteTo(&buff)
|
_, err := section.WriteTo(&buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user