mapparser

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 11 Imported by: 1

README

Minetest map parser library for go

Coverage Status

Features

  • Extracts metadata/inventories
  • NodeID/Param1/Param2 handling
  • Supports zlib compressed mapblocks
  • zstd compressed mapblocks (minetest 5.5+)

Example

// read mapblock data from db/file/somewhere else
data, err := ioutil.ReadFile("mapblock.bin")
if err != nil {
    panic(err)
}

// parse
mapblock, err := Parse(data)
if err != nil {
    panic(err)
}

// mapblock version
fmt.Printf("Version: %d", mapblock.Version)

// nodes
fmt.Printf("%s", mapblock.GetNodeName(10,0,2)) // node-name
fmt.Printf("%s", mapblock.GetNodeId(10,0,2)) //raw nodeid
fmt.Printf("%s", mapblock.GetParam2(10,0,2)) //param2

// node-id mapping
for id, name := range mapblock.BlockMapping {
    fmt.Printf("%d = %s", id, name)
}

// inventories
invMap := mapblock.Metadata.GetInventoryMapAtPos(10,0,0)
mainInv := invMap["main"]
for _, item := range mainInv {
    fmt.Printf("%s %d", item.Name, item.Count)
}

// metadata
md := mapblock.Metadata.GetMetadata(10,0,1)
for key, value := range md {
    fmt.Printf("%s = %s", key, value)
}

License

Code: MIT

Documentation

Index

Constants

View Source
const (
	INVENTORY_TERMINATOR = "EndInventory"
	INVENTORY_END        = "EndInventoryList"
	INVENTORY_START      = "List"
	ITEM_PREFIX          = "Item"
	ITEM_EMPTY           = "Empty"
)
View Source
const MapDataSize = 16384

Variables

View Source
var ErrMapblockVersion = errors.New("mapblock version unsupported")
View Source
var ErrNoData = errors.New("no data")

Functions

func FromNodePos added in v0.1.1

func FromNodePos(pos int) (int, int, int)

converts the index back to a vector

func GetNodePos added in v0.1.1

func GetNodePos(x, y, z int) int

converts a vector to an integer for indexing the internal mapblock positions

func Parse

func Parse(data []byte) (*types.MapBlock, error)

func ParseNetwork added in v1.0.3

func ParseNetwork(ser_ver uint8, data []byte) (*types.MapBlock, error)

Types

type CountedReader

type CountedReader struct {
	Reader *bytes.Reader
	Count  int
}

func (*CountedReader) Read

func (r *CountedReader) Read(p []byte) (int, error)

func (*CountedReader) ReadByte

func (r *CountedReader) ReadByte() (byte, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL