Enhance BitStorage

This commit is contained in:
Tnze
2021-12-14 14:12:26 +08:00
parent f2c0c9e4a8
commit fe6fc3dc7b
2 changed files with 85 additions and 27 deletions

View File

@ -1,6 +1,8 @@
package save
import (
pk "github.com/Tnze/go-mc/net/packet"
"math/bits"
"reflect"
"testing"
)
@ -26,3 +28,19 @@ func TestBitStorage_Set(t *testing.T) {
t.Errorf("Encode error, got %v but expected: %v", bs.data, data)
}
}
func ExampleNewBitStorage_heightmaps() {
// Create a BitStorage
bs := NewBitStorage(bits.Len(256), 16*16, nil)
// Fill your data
for i := 0; i < 16; i++ {
for j := 0; j < 16; j++ {
bs.Set(i*16+j, 0)
}
}
// Encode as NBT, and this is ready for packet.Marshal
type HeightMaps struct {
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
}
_ = pk.NBT(HeightMaps{bs.Longs()})
}