2019-01-06 23:00:24 +03:00
|
|
|
package mapblockparser
|
|
|
|
|
|
|
|
type MapBlock struct {
|
2019-01-18 17:18:42 +03:00
|
|
|
Size int `json:"size"`
|
2019-01-18 13:04:37 +03:00
|
|
|
Version byte `json:"version"`
|
|
|
|
Underground bool `json:"underground"`
|
|
|
|
Mapdata []byte `json:"mapdata"`
|
|
|
|
Metadata Metadata `json:"metadata"`
|
|
|
|
BlockMapping map[int]string `json:"blockmapping"`
|
2019-01-18 15:50:59 +03:00
|
|
|
Mtime int64 `json:"mtime"`
|
2019-01-18 13:04:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Metadata struct {
|
|
|
|
Inventories map[int]map[string]*Inventory `json:"inventories"`
|
|
|
|
Pairs map[int]map[string]string `json:"pairs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Item struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Count int `json:"count"`
|
|
|
|
Wear int `json:"wear"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Inventory struct {
|
|
|
|
Size int `json:"size"`
|
|
|
|
Items []Item `json:"items"`
|
2019-01-07 10:59:06 +03:00
|
|
|
}
|
|
|
|
|
2019-01-13 18:37:03 +03:00
|
|
|
func getNodePos(x, y, z int) int {
|
2019-01-10 18:04:20 +03:00
|
|
|
return x + (y * 16) + (z * 256)
|
|
|
|
}
|
|
|
|
|
2019-01-13 18:37:03 +03:00
|
|
|
func (mb *MapBlock) GetNodeName(x, y, z int) string {
|
|
|
|
pos := getNodePos(x, y, z)
|
|
|
|
id := readU16(mb.Mapdata, pos*2)
|
2019-01-10 18:04:20 +03:00
|
|
|
return mb.BlockMapping[id]
|
|
|
|
}
|
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
func NewMapblock() MapBlock {
|
|
|
|
mb := MapBlock{}
|
|
|
|
mb.Metadata = NewMetadata()
|
2019-01-07 21:53:05 +03:00
|
|
|
mb.BlockMapping = make(map[int]string)
|
2019-01-07 21:38:53 +03:00
|
|
|
return mb
|
|
|
|
}
|
2019-01-07 10:59:06 +03:00
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
func NewMetadata() Metadata {
|
|
|
|
md := Metadata{}
|
|
|
|
md.Inventories = make(map[int]map[string]*Inventory)
|
|
|
|
md.Pairs = make(map[int]map[string]string)
|
|
|
|
return md
|
|
|
|
}
|
2019-01-07 18:06:03 +03:00
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
func (md *Metadata) GetPairsMap(pos int) map[string]string {
|
2019-01-07 18:06:03 +03:00
|
|
|
pairsMap := md.Pairs[pos]
|
|
|
|
if pairsMap == nil {
|
2019-01-07 18:35:26 +03:00
|
|
|
pairsMap = make(map[string]string)
|
2019-01-07 18:06:03 +03:00
|
|
|
md.Pairs[pos] = pairsMap
|
|
|
|
}
|
|
|
|
|
|
|
|
return pairsMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func (md *Metadata) GetInventoryMap(pos int) map[string]*Inventory {
|
|
|
|
invMap := md.Inventories[pos]
|
|
|
|
if invMap == nil {
|
|
|
|
invMap = make(map[string]*Inventory)
|
|
|
|
md.Inventories[pos] = invMap
|
|
|
|
}
|
|
|
|
|
|
|
|
return invMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func (md *Metadata) GetInventory(pos int, name string) *Inventory {
|
|
|
|
m := md.GetInventoryMap(pos)
|
|
|
|
inv := m[name]
|
|
|
|
if inv == nil {
|
|
|
|
inv = &Inventory{}
|
|
|
|
m[name] = inv
|
|
|
|
}
|
|
|
|
|
|
|
|
return inv
|
2019-01-07 10:59:06 +03:00
|
|
|
}
|