Skip to content

Commit

Permalink
implement GetNode on mapblock
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Sep 2, 2024
1 parent f486032 commit 57a4f76
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mapblock.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "fmt"

type MapBlock struct {
Size int `json:"size"`
Version byte `json:"version"`
Expand Down Expand Up @@ -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
}

0 comments on commit 57a4f76

Please sign in to comment.