Skip to content

Commit

Permalink
export mapblock indexing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Jan 31, 2022
1 parent 4c92b50 commit 5669a88
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions mapblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func (mb *MapBlock) IsEmpty() bool {
}

func (mb *MapBlock) GetNodeId(x, y, z int) int {
pos := getNodePos(x, y, z)
pos := GetNodePos(x, y, z)
return mb.Mapdata.ContentId[pos]
}

func (mb *MapBlock) GetParam2(x, y, z int) int {
pos := getNodePos(x, y, z)
pos := GetNodePos(x, y, z)
return mb.Mapdata.Param2[pos]
}

Expand Down
4 changes: 2 additions & 2 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewMetadata() *Metadata {
}

func (md *Metadata) GetMetadata(x, y, z int) map[string]string {
return md.GetPairsMap(getNodePos(x, y, z))
return md.GetPairsMap(GetNodePos(x, y, z))
}

func (md *Metadata) GetPairsMap(pos int) map[string]string {
Expand All @@ -37,7 +37,7 @@ func (md *Metadata) GetInventoryMap(pos int) map[string]*Inventory {
}

func (md *Metadata) GetInventoryMapAtPos(x, y, z int) map[string]*Inventory {
return md.GetInventoryMap(getNodePos(x, y, z))
return md.GetInventoryMap(GetNodePos(x, y, z))
}

func (md *Metadata) GetInventory(pos int, name string) *Inventory {
Expand Down
6 changes: 4 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package mapparser

func getNodePos(x, y, z int) int {
// converts a vector to an integer for indexing the internal mapblock positions
func GetNodePos(x, y, z int) int {
return x + (y * 16) + (z * 256)
}

func fromNodePos(pos int) (int, int, int) {
// converts the index back to a vector
func FromNodePos(pos int) (int, int, int) {
x := pos % 16
pos /= 16
y := pos % 16
Expand Down
4 changes: 2 additions & 2 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

func TestToNodePos(t *testing.T) {
pos := getNodePos(5, 8, 12)
pos := GetNodePos(5, 8, 12)

x, y, z := fromNodePos(pos)
x, y, z := FromNodePos(pos)
fmt.Println(pos)

if x != 5 {
Expand Down

0 comments on commit 5669a88

Please sign in to comment.