From 57a4f7629c58e2322e0e6a462268710a3745b155 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 2 Sep 2024 13:51:38 +0200 Subject: [PATCH] implement GetNode on mapblock --- mapblock.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 +}