start work on mca to packet conversion

This commit is contained in:
adman
2026-05-03 18:20:36 +02:00
parent 94d15258d8
commit 5d3860b91e
8 changed files with 47711 additions and 341 deletions
+40 -1
View File
@@ -1,13 +1,17 @@
package anvil_test
import (
"bytes"
"encoding/json"
"fmt"
"os"
"testing"
"github.com/admin-else/strom/level"
"github.com/admin-else/strom/level/anvil"
"github.com/admin-else/strom/nbt"
"github.com/admin-else/strom/util"
"github.com/google/go-cmp/cmp"
)
func TestLevel(t *testing.T) {
@@ -45,10 +49,45 @@ func TestRegionFile(t *testing.T) {
}
func TestConverToPacket(t *testing.T) {
f, err := os.Open("./level/anvil/testdata/r.0.0.mca")
f, err := os.Open("./testdata/r.0.0.mca")
if err != nil {
t.Errorf("Failed to open file: %v", err)
return
}
defer f.Close()
mca, err := anvil.ReadChunkHeader(f)
if err != nil {
t.Errorf("Failed to read chunk header: %v", err)
return
}
var n *nbt.Tag
n, err = mca.ChunkAt(f, 0, 0)
if err != nil {
t.Errorf("Failed to read chunk: %v", err)
return
}
var chunk anvil.Chunk
err = nbt.Format.Decode(n.Value, &chunk)
if err != nil {
t.Errorf("Failed to decode chunk: %v", err)
return
}
var packetChunk *level.Chunk
packetChunk, err = chunk.ToStorage("1.21.11")
if err != nil {
t.Errorf("Failed to convert chunk: %v", err)
return
}
buffer := bytes.NewBuffer(nil)
err = packetChunk.WriteChunkData(buffer)
if err != nil {
t.Errorf("Failed to write chunk data: %v", err)
return
}
a := chunk00.ChunkData.Val
b := buffer.Bytes()
if !bytes.Equal(a, b) {
t.Errorf("Chunk data is different: %v", cmp.Diff(a, b))
}
}