diff --git a/mapblock.go b/mapblock.go index f2e1251..18424f0 100644 --- a/mapblock.go +++ b/mapblock.go @@ -1,5 +1,7 @@ package types +import "fmt" + type MapBlock struct { Size int `json:"size"` Version byte `json:"version"` @@ -35,3 +37,18 @@ func (mb *MapBlock) GetNodeName(p *Pos) string { id := mb.GetNodeId(p) return mb.BlockMapping[id] } + +func (mb *MapBlock) GetNode(p *Pos) (*Node, error) { + i := p.Index() + + if i > len(mb.Mapdata.ContentId) { + return nil, fmt.Errorf("unexpected index, got %d, len: %d, pos: %s", i, len(mb.Mapdata.ContentId), p) + } + + return &Node{ + Pos: p, + Name: mb.BlockMapping[mb.Mapdata.ContentId[i]], + Param1: mb.Mapdata.Param1[i], + Param2: mb.Mapdata.Param2[i], + }, nil +}