working block id mappings

This commit is contained in:
Thomas Rudin 2019-01-07 19:53:05 +01:00
parent d9db2c1d67
commit a311c7c2e3
3 changed files with 46 additions and 5 deletions

View File

@ -5,11 +5,13 @@ type MapBlock struct {
Underground bool Underground bool
Mapdata []byte Mapdata []byte
Metadata Metadata Metadata Metadata
BlockMapping map[int]string
} }
func NewMapblock() MapBlock { func NewMapblock() MapBlock {
mb := MapBlock{} mb := MapBlock{}
mb.Metadata = NewMetadata() mb.Metadata = NewMetadata()
mb.BlockMapping = make(map[int]string)
return mb return mb
} }

View File

@ -53,5 +53,39 @@ func Parse(data []byte) (*MapBlock, error) {
return nil, err return nil, err
} }
offset += count
//static objects
offset++ //static objects version
staticObjectsCount := readU16(data, offset)
offset += 2
for i := 0; i < staticObjectsCount; i++ {
offset += 13
dataSize := readU16(data, offset)
offset += dataSize + 2
}
//timestamp
offset += 4
//mapping version
offset++
numMappings := readU16(data, offset)
offset += 2
for i := 0; i < numMappings; i++ {
nodeId := readU16(data, offset)
offset += 2
nameLen := readU16(data, offset)
offset += 2
blockName := string(data[offset : offset+nameLen])
offset += nameLen
mapblock.BlockMapping[nodeId] = blockName
}
return &mapblock, nil return &mapblock, nil
} }

View File

@ -1,6 +1,7 @@
package mapblockparser package mapblockparser
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"strconv" "strconv"
"testing" "testing"
@ -72,11 +73,15 @@ func TestParse2(t *testing.T) {
t.Error(err) t.Error(err)
} }
_, err = Parse(data) mapblock, err := Parse(data)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
for k, v := range mapblock.BlockMapping {
fmt.Println("Key", k, "Value", v)
}
} }
func TestParse3(t *testing.T) { func TestParse3(t *testing.T) {