partial switch to mapparser lib
This commit is contained in:
parent
e3064547c7
commit
73c93af328
1
go.mod
1
go.mod
@ -4,6 +4,7 @@ require (
|
|||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/lib/pq v1.10.2
|
github.com/lib/pq v1.10.2
|
||||||
github.com/mattn/go-sqlite3 v1.14.8
|
github.com/mattn/go-sqlite3 v1.14.8
|
||||||
|
github.com/minetest-go/mapparser v0.1.0 // indirect
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
github.com/prometheus/client_golang v1.11.0
|
github.com/prometheus/client_golang v1.11.0
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
4
go.sum
4
go.sum
@ -50,6 +50,8 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
|
|||||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||||
|
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||||
|
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
@ -64,6 +66,8 @@ github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxz
|
|||||||
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
|
github.com/minetest-go/mapparser v0.1.0 h1:wjVrS2QXURnphPlqqPRD6vt1gvkT55RRUjroT3G5Two=
|
||||||
|
github.com/minetest-go/mapparser v0.1.0/go.mod h1:Jnf9+Oe8Hs8IJw6Tk8XPd72NTJkjxLOamTpO51KJoXU=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
@ -3,9 +3,9 @@ package mapblockaccessor
|
|||||||
import (
|
import (
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"mapserver/eventbus"
|
"mapserver/eventbus"
|
||||||
"mapserver/mapblockparser"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
cache "github.com/patrickmn/go-cache"
|
cache "github.com/patrickmn/go-cache"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
var lock = &sync.RWMutex{}
|
var lock = &sync.RWMutex{}
|
||||||
|
|
||||||
func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockparser.MapBlock, error) {
|
func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapparser.MapBlock, error) {
|
||||||
key := getKey(pos)
|
key := getKey(pos)
|
||||||
|
|
||||||
//maintenance
|
//maintenance
|
||||||
@ -40,7 +40,7 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockpar
|
|||||||
if cachedblock == nil {
|
if cachedblock == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else {
|
} else {
|
||||||
return cachedblock.(*mapblockparser.MapBlock), nil
|
return cachedblock.(*mapparser.MapBlock), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockpar
|
|||||||
if cachedblock == nil {
|
if cachedblock == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else {
|
} else {
|
||||||
return cachedblock.(*mapblockparser.MapBlock), nil
|
return cachedblock.(*mapparser.MapBlock), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockpar
|
|||||||
|
|
||||||
getCacheMissCount.Inc()
|
getCacheMissCount.Inc()
|
||||||
|
|
||||||
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime, pos)
|
mapblock, err := mapparser.Parse(block.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,16 @@ package mapblockaccessor
|
|||||||
import (
|
import (
|
||||||
"mapserver/eventbus"
|
"mapserver/eventbus"
|
||||||
"mapserver/layer"
|
"mapserver/layer"
|
||||||
"mapserver/mapblockparser"
|
|
||||||
"mapserver/settings"
|
"mapserver/settings"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
cache "github.com/patrickmn/go-cache"
|
cache "github.com/patrickmn/go-cache"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FindNextLegacyBlocksResult struct {
|
type FindNextLegacyBlocksResult struct {
|
||||||
HasMore bool
|
HasMore bool
|
||||||
List []*mapblockparser.MapBlock
|
List []*mapparser.MapBlock
|
||||||
UnfilteredCount int
|
UnfilteredCount int
|
||||||
Progress float64
|
Progress float64
|
||||||
LastMtime int64
|
LastMtime int64
|
||||||
@ -29,7 +29,7 @@ func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []*l
|
|||||||
blocks := nextResult.List
|
blocks := nextResult.List
|
||||||
result := FindNextLegacyBlocksResult{}
|
result := FindNextLegacyBlocksResult{}
|
||||||
|
|
||||||
mblist := make([]*mapblockparser.MapBlock, 0)
|
mblist := make([]*mapparser.MapBlock, 0)
|
||||||
result.HasMore = nextResult.HasMore
|
result.HasMore = nextResult.HasMore
|
||||||
result.UnfilteredCount = nextResult.UnfilteredCount
|
result.UnfilteredCount = nextResult.UnfilteredCount
|
||||||
result.Progress = nextResult.Progress
|
result.Progress = nextResult.Progress
|
||||||
@ -46,7 +46,7 @@ func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []*l
|
|||||||
|
|
||||||
key := getKey(block.Pos)
|
key := getKey(block.Pos)
|
||||||
|
|
||||||
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime, block.Pos)
|
mapblock, err := mapparser.Parse(block.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"x": block.Pos.X,
|
"x": block.Pos.X,
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"mapserver/eventbus"
|
"mapserver/eventbus"
|
||||||
"mapserver/layer"
|
"mapserver/layer"
|
||||||
"mapserver/mapblockparser"
|
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
cache "github.com/patrickmn/go-cache"
|
cache "github.com/patrickmn/go-cache"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -15,7 +15,7 @@ type FindMapBlocksByMtimeResult struct {
|
|||||||
HasMore bool
|
HasMore bool
|
||||||
LastPos *coords.MapBlockCoords
|
LastPos *coords.MapBlockCoords
|
||||||
LastMtime int64
|
LastMtime int64
|
||||||
List []*mapblockparser.MapBlock
|
List []*mapparser.MapBlock
|
||||||
UnfilteredCount int
|
UnfilteredCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, laye
|
|||||||
|
|
||||||
result := FindMapBlocksByMtimeResult{}
|
result := FindMapBlocksByMtimeResult{}
|
||||||
|
|
||||||
mblist := make([]*mapblockparser.MapBlock, 0)
|
mblist := make([]*mapparser.MapBlock, 0)
|
||||||
var newlastpos *coords.MapBlockCoords
|
var newlastpos *coords.MapBlockCoords
|
||||||
result.HasMore = len(blocks) == limit
|
result.HasMore = len(blocks) == limit
|
||||||
result.UnfilteredCount = len(blocks)
|
result.UnfilteredCount = len(blocks)
|
||||||
@ -65,7 +65,7 @@ func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, laye
|
|||||||
|
|
||||||
key := getKey(block.Pos)
|
key := getKey(block.Pos)
|
||||||
|
|
||||||
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime, block.Pos)
|
mapblock, err := mapparser.Parse(block.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"x": block.Pos.X,
|
"x": block.Pos.X,
|
||||||
|
@ -2,12 +2,12 @@ package mapblockaccessor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"mapserver/mapblockparser"
|
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
cache "github.com/patrickmn/go-cache"
|
cache "github.com/patrickmn/go-cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *MapBlockAccessor) Update(pos *coords.MapBlockCoords, mb *mapblockparser.MapBlock) {
|
func (a *MapBlockAccessor) Update(pos *coords.MapBlockCoords, mb *mapparser.MapBlock) {
|
||||||
key := getKey(pos)
|
key := getKey(pos)
|
||||||
cacheBlockCount.Inc()
|
cacheBlockCount.Inc()
|
||||||
a.blockcache.Set(key, mb, cache.DefaultExpiration)
|
a.blockcache.Set(key, mb, cache.DefaultExpiration)
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CountedReader struct {
|
|
||||||
Reader *bytes.Reader
|
|
||||||
Count int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *CountedReader) Read(p []byte) (int, error) {
|
|
||||||
i, err := r.Reader.Read(p)
|
|
||||||
r.Count += i
|
|
||||||
return i, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *CountedReader) ReadByte() (byte, error) {
|
|
||||||
i, err := r.Reader.ReadByte()
|
|
||||||
r.Count++
|
|
||||||
return i, err
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
func IterateMapblock(cb func(x, y, z int)) {
|
|
||||||
for x := 0; x < 16; x++ {
|
|
||||||
for y := 0; y < 16; y++ {
|
|
||||||
for z := 0; z < 16; z++ {
|
|
||||||
cb(x, y, z)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
var log *logrus.Entry
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log = logrus.WithFields(logrus.Fields{"prefix": "mapblockaccessor"})
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mapserver/coords"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MapBlock struct {
|
|
||||||
Pos *coords.MapBlockCoords `json:"pos"`
|
|
||||||
Size int `json:"size"`
|
|
||||||
Version byte `json:"version"`
|
|
||||||
Underground bool `json:"underground"`
|
|
||||||
Mapdata *MapData `json:"mapdata"`
|
|
||||||
Metadata *Metadata `json:"metadata"`
|
|
||||||
BlockMapping map[int]string `json:"blockmapping"`
|
|
||||||
Mtime int64 `json:"mtime"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type MapData struct {
|
|
||||||
ContentId []int `json:"contentid"`
|
|
||||||
Param1 []int `json:"param1"`
|
|
||||||
Param2 []int `json:"param2"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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"`
|
|
||||||
//TODO: metadata
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *MapBlock) IsEmpty() bool {
|
|
||||||
if len(this.BlockMapping) == 0 {
|
|
||||||
// only air
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(this.BlockMapping) == 1 {
|
|
||||||
for _, name := range this.BlockMapping {
|
|
||||||
if name == "vacuum:vacuum" {
|
|
||||||
// only vacuum
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// other stuff
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Item) IsEmpty() bool {
|
|
||||||
return this.Name == "" && this.Count == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
type Inventory struct {
|
|
||||||
Size int `json:"size"`
|
|
||||||
Items []*Item `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func getNodePos(x, y, z int) int {
|
|
||||||
return x + (y * 16) + (z * 256)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (inv *Inventory) IsEmpty() bool {
|
|
||||||
if len(inv.Items) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range inv.Items {
|
|
||||||
if item.Name != "" && item.Count > 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mb *MapBlock) GetNodeId(x, y, z int) int {
|
|
||||||
pos := getNodePos(x, y, z)
|
|
||||||
return mb.Mapdata.ContentId[pos]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mb *MapBlock) GetParam2(x, y, z int) int {
|
|
||||||
pos := getNodePos(x, y, z)
|
|
||||||
return mb.Mapdata.Param2[pos]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mb *MapBlock) GetNodeName(x, y, z int) string {
|
|
||||||
id := mb.GetNodeId(x, y, z)
|
|
||||||
return mb.BlockMapping[id]
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMapblock() *MapBlock {
|
|
||||||
mb := MapBlock{}
|
|
||||||
mb.Metadata = NewMetadata()
|
|
||||||
mb.BlockMapping = make(map[int]string)
|
|
||||||
return &mb
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMetadata() *Metadata {
|
|
||||||
md := Metadata{}
|
|
||||||
md.Inventories = make(map[int]map[string]*Inventory)
|
|
||||||
md.Pairs = make(map[int]map[string]string)
|
|
||||||
return &md
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *Metadata) GetMetadata(x, y, z int) map[string]string {
|
|
||||||
return md.GetPairsMap(getNodePos(x, y, z))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *Metadata) GetPairsMap(pos int) map[string]string {
|
|
||||||
pairsMap := md.Pairs[pos]
|
|
||||||
if pairsMap == nil {
|
|
||||||
pairsMap = make(map[string]string)
|
|
||||||
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) GetInventoryMapAtPos(x, y, z int) map[string]*Inventory {
|
|
||||||
return md.GetInventoryMap(getNodePos(x, y, z))
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"compress/zlib"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func parseMapdata(mapblock *MapBlock, data []byte) (int, error) {
|
|
||||||
r := bytes.NewReader(data)
|
|
||||||
|
|
||||||
cr := new(CountedReader)
|
|
||||||
cr.Reader = r
|
|
||||||
|
|
||||||
z, err := zlib.NewReader(cr)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer z.Close()
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
io.Copy(buf, z)
|
|
||||||
|
|
||||||
if buf.Len() != 16384 {
|
|
||||||
return 0, errors.New("Mapdata length invalid: " + strconv.Itoa(buf.Len()))
|
|
||||||
}
|
|
||||||
|
|
||||||
rawdata := buf.Bytes()
|
|
||||||
|
|
||||||
mapd := MapData{
|
|
||||||
ContentId: make([]int, 4096),
|
|
||||||
Param1: make([]int, 4096),
|
|
||||||
Param2: make([]int, 4096),
|
|
||||||
}
|
|
||||||
mapblock.Mapdata = &mapd
|
|
||||||
|
|
||||||
for i := 0; i < 4096; i++ {
|
|
||||||
mapd.ContentId[i] = readU16(rawdata, i*2)
|
|
||||||
mapd.Param1[i] = readU8(rawdata, (4096*2)+i)
|
|
||||||
mapd.Param2[i] = readU8(rawdata, (4096*3)+i)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cr.Count, nil
|
|
||||||
}
|
|
@ -1,180 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"compress/zlib"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
lua vm: https://github.com/yuin/gopher-lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
const (
|
|
||||||
INVENTORY_TERMINATOR = "EndInventory"
|
|
||||||
INVENTORY_END = "EndInventoryList"
|
|
||||||
INVENTORY_START = "List"
|
|
||||||
)
|
|
||||||
|
|
||||||
func readU16(data []byte, offset int) int {
|
|
||||||
return (int(data[offset]) << 8) | int(data[offset+1])
|
|
||||||
}
|
|
||||||
|
|
||||||
func readU8(data []byte, offset int) int {
|
|
||||||
return int(data[offset])
|
|
||||||
}
|
|
||||||
|
|
||||||
func readU32(data []byte, offset int) int {
|
|
||||||
return int(data[offset])<<24 |
|
|
||||||
int(data[offset+1])<<16 |
|
|
||||||
int(data[offset+2])<<8 |
|
|
||||||
int(data[offset+3])
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
|
||||||
r := bytes.NewReader(data)
|
|
||||||
|
|
||||||
cr := new(CountedReader)
|
|
||||||
cr.Reader = r
|
|
||||||
|
|
||||||
z, err := zlib.NewReader(cr)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer z.Close()
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
io.Copy(buf, z)
|
|
||||||
|
|
||||||
if cr.Count == 0 {
|
|
||||||
return 0, errors.New("no data")
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata := buf.Bytes()
|
|
||||||
|
|
||||||
log.WithFields(logrus.Fields{"metadata-length": len(metadata)}).Trace("Parsing metadata")
|
|
||||||
|
|
||||||
offset := 0
|
|
||||||
version := metadata[offset]
|
|
||||||
|
|
||||||
if version == 0 {
|
|
||||||
//No data?
|
|
||||||
return cr.Count, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
offset++
|
|
||||||
count := readU16(metadata, offset)
|
|
||||||
|
|
||||||
offset += 2
|
|
||||||
|
|
||||||
for i := 0; i < count; i++ {
|
|
||||||
position := readU16(metadata, offset)
|
|
||||||
pairsMap := mapblock.Metadata.GetPairsMap(position)
|
|
||||||
|
|
||||||
offset += 2
|
|
||||||
valuecount := readU32(metadata, offset)
|
|
||||||
|
|
||||||
offset += 4
|
|
||||||
for j := 0; j < valuecount; j++ {
|
|
||||||
keyLength := readU16(metadata, offset)
|
|
||||||
offset += 2
|
|
||||||
|
|
||||||
key := string(metadata[offset : keyLength+offset])
|
|
||||||
offset += keyLength
|
|
||||||
|
|
||||||
valueLength := readU32(metadata, offset)
|
|
||||||
offset += 4
|
|
||||||
|
|
||||||
if len(metadata) <= valueLength+offset {
|
|
||||||
return 0, errors.New("metadata too short: " + strconv.Itoa(len(metadata)) +
|
|
||||||
", valuelength: " + strconv.Itoa(int(valueLength)))
|
|
||||||
}
|
|
||||||
|
|
||||||
value := string(metadata[offset : valueLength+offset])
|
|
||||||
offset += valueLength
|
|
||||||
|
|
||||||
pairsMap[key] = value
|
|
||||||
|
|
||||||
priv := 0
|
|
||||||
if version >= 2 { /* private tag doesn't exist in version=1 */
|
|
||||||
priv = readU8(metadata, offset)
|
|
||||||
offset++
|
|
||||||
}
|
|
||||||
|
|
||||||
if priv != 0 {
|
|
||||||
// do something usefull
|
|
||||||
logrus.Trace("Private items in Inventory")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentInventoryName *string
|
|
||||||
var currentInventory *Inventory
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(bytes.NewReader(metadata[offset:]))
|
|
||||||
for scanner.Scan() {
|
|
||||||
txt := scanner.Text()
|
|
||||||
offset += len(txt) + 1
|
|
||||||
|
|
||||||
log.WithFields(logrus.Fields{"txt": txt, "position": position}).Trace("Parsing inventory")
|
|
||||||
|
|
||||||
if strings.HasPrefix(txt, INVENTORY_START) {
|
|
||||||
pairs := strings.Split(txt, " ")
|
|
||||||
currentInventoryName = &pairs[1]
|
|
||||||
currentInventory = mapblock.Metadata.GetInventory(position, *currentInventoryName)
|
|
||||||
currentInventory.Size = 0
|
|
||||||
|
|
||||||
} else if txt == INVENTORY_END {
|
|
||||||
currentInventoryName = nil
|
|
||||||
currentInventory = nil
|
|
||||||
} else if currentInventory != nil {
|
|
||||||
//content
|
|
||||||
if strings.HasPrefix(txt, "Item") {
|
|
||||||
item := Item{}
|
|
||||||
parts := strings.Split(txt, " ")
|
|
||||||
|
|
||||||
if len(parts) >= 2 {
|
|
||||||
item.Name = parts[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(parts) >= 3 {
|
|
||||||
val, err := strconv.ParseInt(parts[2], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
item.Count = int(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(parts) >= 4 {
|
|
||||||
val, err := strconv.ParseInt(parts[3], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
item.Count = int(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
currentInventory.Items = append(currentInventory.Items, &item)
|
|
||||||
currentInventory.Size += 1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if txt == INVENTORY_TERMINATOR {
|
|
||||||
break
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return 0, errors.New("Malformed inventory: " + txt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return cr.Count, nil
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"mapserver/coords"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Parse(data []byte, mtime int64, pos *coords.MapBlockCoords) (*MapBlock, error) {
|
|
||||||
if len(data) == 0 {
|
|
||||||
return nil, errors.New("no data")
|
|
||||||
}
|
|
||||||
|
|
||||||
timer := prometheus.NewTimer(parseDuration)
|
|
||||||
defer timer.ObserveDuration()
|
|
||||||
|
|
||||||
mapblock := NewMapblock()
|
|
||||||
mapblock.Mtime = mtime
|
|
||||||
mapblock.Pos = pos
|
|
||||||
mapblock.Size = len(data)
|
|
||||||
|
|
||||||
// version
|
|
||||||
mapblock.Version = data[0]
|
|
||||||
|
|
||||||
if mapblock.Version < 25 || mapblock.Version > 28 {
|
|
||||||
return nil, errors.New("mapblock-version not supported: " + strconv.Itoa(int(mapblock.Version)))
|
|
||||||
}
|
|
||||||
|
|
||||||
//flags
|
|
||||||
flags := data[1]
|
|
||||||
mapblock.Underground = (flags & 0x01) == 0x01
|
|
||||||
|
|
||||||
var offset int
|
|
||||||
|
|
||||||
if mapblock.Version >= 27 {
|
|
||||||
offset = 4
|
|
||||||
} else {
|
|
||||||
//u16 lighting_complete not present
|
|
||||||
offset = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
content_width := data[offset]
|
|
||||||
params_width := data[offset+1]
|
|
||||||
|
|
||||||
if content_width != 2 {
|
|
||||||
return nil, errors.New("content_width = " + strconv.Itoa(int(content_width)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if params_width != 2 {
|
|
||||||
return nil, errors.New("params_width = " + strconv.Itoa(int(params_width)))
|
|
||||||
}
|
|
||||||
|
|
||||||
//mapdata (blocks)
|
|
||||||
if mapblock.Version >= 27 {
|
|
||||||
offset = 6
|
|
||||||
|
|
||||||
} else {
|
|
||||||
offset = 4
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//metadata
|
|
||||||
count, err := parseMapdata(mapblock, data[offset:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += count
|
|
||||||
|
|
||||||
count, err = parseMetadata(mapblock, data[offset:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += count
|
|
||||||
|
|
||||||
//static objects
|
|
||||||
|
|
||||||
offset++ //static objects version
|
|
||||||
staticObjectsCount := readU16(data, offset)
|
|
||||||
offset += 2
|
|
||||||
for i := 0; i < staticObjectsCount; i++ {
|
|
||||||
offset += 13
|
|
||||||
dataSize := readU16(data, offset)
|
|
||||||
offset += dataSize + 2
|
|
||||||
}
|
|
||||||
|
|
||||||
//timestamp
|
|
||||||
offset += 4
|
|
||||||
|
|
||||||
//mapping version
|
|
||||||
offset++
|
|
||||||
|
|
||||||
numMappings := readU16(data, offset)
|
|
||||||
offset += 2
|
|
||||||
for i := 0; i < numMappings; i++ {
|
|
||||||
nodeId := readU16(data, offset)
|
|
||||||
offset += 2
|
|
||||||
|
|
||||||
nameLen := readU16(data, offset)
|
|
||||||
offset += 2
|
|
||||||
|
|
||||||
blockName := string(data[offset : offset+nameLen])
|
|
||||||
offset += nameLen
|
|
||||||
|
|
||||||
mapblock.BlockMapping[nodeId] = blockName
|
|
||||||
}
|
|
||||||
|
|
||||||
parsedMapBlocks.Inc()
|
|
||||||
return mapblock, nil
|
|
||||||
}
|
|
@ -1,122 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"mapserver/coords"
|
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestReadU16(t *testing.T) {
|
|
||||||
v := readU16([]byte{0x00, 0x00}, 0)
|
|
||||||
if v != 0 {
|
|
||||||
t.Error(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
v = readU16([]byte{0x00, 0x01}, 0)
|
|
||||||
if v != 1 {
|
|
||||||
t.Error(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
v = readU16([]byte{0x01, 0x00}, 0)
|
|
||||||
if v != 256 {
|
|
||||||
t.Error(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
func TestReadU32(t *testing.T) {
|
|
||||||
v := readU32([]byte{0x00, 0x00, 0x00, 0x00}, 0)
|
|
||||||
if v != 0 {
|
|
||||||
t.Error(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
|
||||||
|
|
||||||
data, err := ioutil.ReadFile("testdata/0.0.0")
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mapblock, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if mapblock.Version != 28 {
|
|
||||||
t.Error("wrong mapblock version: " + strconv.Itoa(int(mapblock.Version)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if !mapblock.Underground {
|
|
||||||
t.Error("Underground flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(mapblock.Mapdata.ContentId) != 4096 {
|
|
||||||
t.Error("Mapdata length wrong")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(mapblock.Mapdata.Param2) != 4096 {
|
|
||||||
t.Error("Mapdata length wrong")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(mapblock.Mapdata.Param1) != 4096 {
|
|
||||||
t.Error("Mapdata length wrong")
|
|
||||||
}
|
|
||||||
|
|
||||||
pairs := mapblock.Metadata.GetPairsMap(0)
|
|
||||||
if pairs["owner"] != "pipo" {
|
|
||||||
t.Error(pairs["owner"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse2(t *testing.T) {
|
|
||||||
|
|
||||||
data, err := ioutil.ReadFile("testdata/11.0.2")
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mapblock, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range mapblock.BlockMapping {
|
|
||||||
fmt.Println("Key", k, "Value", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse3(t *testing.T) {
|
|
||||||
|
|
||||||
data, err := ioutil.ReadFile("testdata/0.1.0")
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseMetadata(t *testing.T) {
|
|
||||||
|
|
||||||
data, err := ioutil.ReadFile("testdata/mb-with-metadata.bin")
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mb, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
str, err := json.MarshalIndent(mb, "", " ")
|
|
||||||
fmt.Println(string(str))
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package mapblockparser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
parsedMapBlocks = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Name: "mapblocks_parsed_count",
|
|
||||||
Help: "Overall count of parsed mapblocks",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
parseDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
|
|
||||||
Name: "mapblock_parse_time",
|
|
||||||
Help: "Histogram for mapblock parse timings",
|
|
||||||
Buckets: prometheus.LinearBuckets(0.001, 0.002, 10),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
prometheus.MustRegister(parsedMapBlocks)
|
|
||||||
prometheus.MustRegister(parseDuration)
|
|
||||||
}
|
|
BIN
mapblockparser/testdata/0.-1.0
vendored
BIN
mapblockparser/testdata/0.-1.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.0.0
vendored
BIN
mapblockparser/testdata/0.0.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.1.0
vendored
BIN
mapblockparser/testdata/0.1.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.10.0
vendored
BIN
mapblockparser/testdata/0.10.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.2.0
vendored
BIN
mapblockparser/testdata/0.2.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.3.0
vendored
BIN
mapblockparser/testdata/0.3.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.4.0
vendored
BIN
mapblockparser/testdata/0.4.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.5.0
vendored
BIN
mapblockparser/testdata/0.5.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.6.0
vendored
BIN
mapblockparser/testdata/0.6.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.7.0
vendored
BIN
mapblockparser/testdata/0.7.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.8.0
vendored
BIN
mapblockparser/testdata/0.8.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/0.9.0
vendored
BIN
mapblockparser/testdata/0.9.0
vendored
Binary file not shown.
BIN
mapblockparser/testdata/11.0.2
vendored
BIN
mapblockparser/testdata/11.0.2
vendored
Binary file not shown.
BIN
mapblockparser/testdata/mb-with-metadata.bin
vendored
BIN
mapblockparser/testdata/mb-with-metadata.bin
vendored
Binary file not shown.
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ATM struct{}
|
type ATM struct{}
|
||||||
|
|
||||||
func (this *ATM) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *ATM) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
nodename := block.GetNodeName(x, y, z)
|
nodename := block.GetNodeName(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "atm")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "atm")
|
||||||
|
|
||||||
if nodename == "atm:wtt" {
|
if nodename == "atm:wtt" {
|
||||||
o.Attributes["type"] = "wiretransfer"
|
o.Attributes["type"] = "wiretransfer"
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BonesBlock struct{}
|
type BonesBlock struct{}
|
||||||
|
|
||||||
func (this *BonesBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *BonesBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
invMap := block.Metadata.GetInventoryMapAtPos(x, y, z)
|
invMap := block.Metadata.GetInventoryMapAtPos(x, y, z)
|
||||||
@ -18,7 +20,7 @@ func (this *BonesBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "bones")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "bones")
|
||||||
o.Attributes["time"] = md["time"]
|
o.Attributes["time"] = md["time"]
|
||||||
|
|
||||||
if _, ok := md["owner"]; ok {
|
if _, ok := md["owner"]; ok {
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BorderBlock struct{}
|
type BorderBlock struct{}
|
||||||
|
|
||||||
func (this *BorderBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *BorderBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "border")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "border")
|
||||||
o.Attributes["name"] = md["name"]
|
o.Attributes["name"] = md["name"]
|
||||||
o.Attributes["index"] = md["index"]
|
o.Attributes["index"] = md["index"]
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DigilineLcdBlock struct{}
|
type DigilineLcdBlock struct{}
|
||||||
|
|
||||||
func (this *DigilineLcdBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *DigilineLcdBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "digilinelcd")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "digilinelcd")
|
||||||
o.Attributes["text"] = md["text"]
|
o.Attributes["text"] = md["text"]
|
||||||
o.Attributes["channel"] = md["channel"]
|
o.Attributes["channel"] = md["channel"]
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DigitermsBlock struct{}
|
type DigitermsBlock struct{}
|
||||||
|
|
||||||
func (this *DigitermsBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *DigitermsBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "digiterm")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "digiterm")
|
||||||
o.Attributes["display_text"] = md["display_text"]
|
o.Attributes["display_text"] = md["display_text"]
|
||||||
o.Attributes["channel"] = md["channel"]
|
o.Attributes["channel"] = md["channel"]
|
||||||
|
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mapserver/coords"
|
||||||
"mapserver/luaparser"
|
"mapserver/luaparser"
|
||||||
"mapserver/mapblockparser"
|
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FancyVend struct{}
|
type FancyVend struct{}
|
||||||
|
|
||||||
func (this *FancyVend) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *FancyVend) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
nodename := block.GetNodeName(x, y, z)
|
nodename := block.GetNodeName(x, y, z)
|
||||||
invMap := block.Metadata.GetInventoryMapAtPos(x, y, z)
|
invMap := block.Metadata.GetInventoryMapAtPos(x, y, z)
|
||||||
@ -46,7 +47,7 @@ func (this *FancyVend) onMapObject(x, y, z int, block *mapblockparser.MapBlock)
|
|||||||
"x": x,
|
"x": x,
|
||||||
"y": y,
|
"y": y,
|
||||||
"z": z,
|
"z": z,
|
||||||
"pos": block.Pos,
|
"pos": mbpos,
|
||||||
"err": err,
|
"err": err,
|
||||||
}
|
}
|
||||||
log.WithFields(fields).Error("Fancyvend setting error")
|
log.WithFields(fields).Error("Fancyvend setting error")
|
||||||
@ -84,7 +85,7 @@ func (this *FancyVend) onMapObject(x, y, z int, block *mapblockparser.MapBlock)
|
|||||||
|
|
||||||
stock_factor := int(float64(stock) / float64(out_count))
|
stock_factor := int(float64(stock) / float64(out_count))
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "shop")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "shop")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["type"] = "fancyvend"
|
o.Attributes["type"] = "fancyvend"
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JumpdriveBlock struct{}
|
type JumpdriveBlock struct{}
|
||||||
|
|
||||||
func (this *JumpdriveBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *JumpdriveBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "jumpdrive")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "jumpdrive")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["radius"] = md["radius"]
|
o.Attributes["radius"] = md["radius"]
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LabelBlock struct{}
|
type LabelBlock struct{}
|
||||||
|
|
||||||
func (this *LabelBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *LabelBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "label")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "label")
|
||||||
o.Attributes["text"] = md["text"]
|
o.Attributes["text"] = md["text"]
|
||||||
o.Attributes["size"] = md["size"]
|
o.Attributes["size"] = md["size"]
|
||||||
o.Attributes["direction"] = md["direction"]
|
o.Attributes["direction"] = md["direction"]
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Locator struct{}
|
type Locator struct{}
|
||||||
|
|
||||||
func (this *Locator) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *Locator) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
nodename := block.GetNodeName(x, y, z)
|
nodename := block.GetNodeName(x, y, z)
|
||||||
|
|
||||||
@ -19,7 +21,7 @@ func (this *Locator) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *m
|
|||||||
level = "3"
|
level = "3"
|
||||||
}
|
}
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "locator")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "locator")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["name"] = md["name"]
|
o.Attributes["name"] = md["name"]
|
||||||
o.Attributes["active"] = md["active"]
|
o.Attributes["active"] = md["active"]
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LuaControllerBlock struct{}
|
type LuaControllerBlock struct{}
|
||||||
|
|
||||||
func (this *LuaControllerBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *LuaControllerBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
//md := block.Metadata.GetMetadata(x, y, z)
|
//md := block.Metadata.GetMetadata(x, y, z)
|
||||||
nodename := block.GetNodeName(x, y, z)
|
nodename := block.GetNodeName(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "luacontroller")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "luacontroller")
|
||||||
//o.Attributes["code"] = md["code"]
|
//o.Attributes["code"] = md["code"]
|
||||||
//o.Attributes["lc_memory"] = md["lc_memory"]
|
//o.Attributes["lc_memory"] = md["lc_memory"]
|
||||||
|
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MissionBlock struct{}
|
type MissionBlock struct{}
|
||||||
|
|
||||||
func (this *MissionBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *MissionBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
if md["hidden"] == "1" {
|
if md["hidden"] == "1" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "mission")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "mission")
|
||||||
o.Attributes["name"] = md["name"]
|
o.Attributes["name"] = md["name"]
|
||||||
o.Attributes["time"] = md["time"]
|
o.Attributes["time"] = md["time"]
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NuclearReactorBlock struct{}
|
type NuclearReactorBlock struct{}
|
||||||
|
|
||||||
func (this *NuclearReactorBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *NuclearReactorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "nuclearreactor")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "nuclearreactor")
|
||||||
o.Attributes["burn_time"] = md["burn_time"]
|
o.Attributes["burn_time"] = md["burn_time"]
|
||||||
o.Attributes["structure_accumulated_badness"] = md["structure_accumulated_badness"]
|
o.Attributes["structure_accumulated_badness"] = md["structure_accumulated_badness"]
|
||||||
|
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PoiBlock struct {
|
type PoiBlock struct {
|
||||||
Color string
|
Color string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *PoiBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *PoiBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "poi")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "poi")
|
||||||
o.Attributes["name"] = md["name"]
|
o.Attributes["name"] = md["name"]
|
||||||
o.Attributes["category"] = md["category"]
|
o.Attributes["category"] = md["category"]
|
||||||
o.Attributes["url"] = md["url"]
|
o.Attributes["url"] = md["url"]
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrivProtectorBlock struct{}
|
type PrivProtectorBlock struct{}
|
||||||
|
|
||||||
func (this *PrivProtectorBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *PrivProtectorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "privprotector")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "privprotector")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["priv"] = md["priv"]
|
o.Attributes["priv"] = md["priv"]
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProtectorBlock struct{}
|
type ProtectorBlock struct{}
|
||||||
|
|
||||||
func (this *ProtectorBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *ProtectorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "protector")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "protector")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["members"] = md["members"]
|
o.Attributes["members"] = md["members"]
|
||||||
|
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type QuarryBlock struct{}
|
type QuarryBlock struct{}
|
||||||
|
|
||||||
func (this *QuarryBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *QuarryBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
if md["owner"] == "" {
|
if md["owner"] == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "technicquarry")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "technicquarry")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["dug"] = md["dug"]
|
o.Attributes["dug"] = md["dug"]
|
||||||
o.Attributes["enabled"] = md["enabled"]
|
o.Attributes["enabled"] = md["enabled"]
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SignBlock struct {
|
type SignBlock struct {
|
||||||
Material string
|
Material string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *SignBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *SignBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "sign")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "sign")
|
||||||
o.Attributes["display_text"] = md["text"]
|
o.Attributes["display_text"] = md["text"]
|
||||||
o.Attributes["material"] = this.Material
|
o.Attributes["material"] = this.Material
|
||||||
|
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SmartShopBlock struct{}
|
type SmartShopBlock struct{}
|
||||||
|
|
||||||
func (this *SmartShopBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) []*mapobjectdb.MapObject {
|
func (this *SmartShopBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) []*mapobjectdb.MapObject {
|
||||||
list := make([]*mapobjectdb.MapObject, 0)
|
list := make([]*mapobjectdb.MapObject, 0)
|
||||||
|
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
@ -32,7 +34,7 @@ func (this *SmartShopBlock) onMapObject(x, y, z int, block *mapblockparser.MapBl
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "shop")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "shop")
|
||||||
o.Attributes["type"] = "smartshop"
|
o.Attributes["type"] = "smartshop"
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TechnicAnchorBlock struct{}
|
type TechnicAnchorBlock struct{}
|
||||||
|
|
||||||
func (this *TechnicAnchorBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *TechnicAnchorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "technicanchor")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "technicanchor")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["radius"] = md["radius"]
|
o.Attributes["radius"] = md["radius"]
|
||||||
o.Attributes["locked"] = md["locked"]
|
o.Attributes["locked"] = md["locked"]
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TechnicSwitchBlock struct{}
|
type TechnicSwitchBlock struct{}
|
||||||
|
|
||||||
func (this *TechnicSwitchBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *TechnicSwitchBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "technicswitch")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "technicswitch")
|
||||||
o.Attributes["active"] = md["active"]
|
o.Attributes["active"] = md["active"]
|
||||||
o.Attributes["channel"] = md["channel"]
|
o.Attributes["channel"] = md["channel"]
|
||||||
o.Attributes["supply"] = md["supply"]
|
o.Attributes["supply"] = md["supply"]
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TrainBlock struct{}
|
type TrainBlock struct{}
|
||||||
|
|
||||||
func (this *TrainBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *TrainBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "train")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "train")
|
||||||
o.Attributes["station"] = md["station"]
|
o.Attributes["station"] = md["station"]
|
||||||
o.Attributes["line"] = md["line"]
|
o.Attributes["line"] = md["line"]
|
||||||
o.Attributes["index"] = md["index"]
|
o.Attributes["index"] = md["index"]
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TravelnetBlock struct{}
|
type TravelnetBlock struct{}
|
||||||
|
|
||||||
func (tn *TravelnetBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (tn *TravelnetBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
// ignore (P) prefixed stations
|
// ignore (P) prefixed stations
|
||||||
@ -17,7 +19,7 @@ func (tn *TravelnetBlock) onMapObject(x, y, z int, block *mapblockparser.MapBloc
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "travelnet")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "travelnet")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["station_name"] = md["station_name"]
|
o.Attributes["station_name"] = md["station_name"]
|
||||||
o.Attributes["station_network"] = md["station_network"]
|
o.Attributes["station_network"] = md["station_network"]
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package mapobject
|
package mapobject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/mapblockparser"
|
"mapserver/coords"
|
||||||
"mapserver/mapobjectdb"
|
"mapserver/mapobjectdb"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type XPProtectorBlock struct{}
|
type XPProtectorBlock struct{}
|
||||||
|
|
||||||
func (this *XPProtectorBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
func (this *XPProtectorBlock) onMapObject(mbpos *coords.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject {
|
||||||
md := block.Metadata.GetMetadata(x, y, z)
|
md := block.Metadata.GetMetadata(x, y, z)
|
||||||
|
|
||||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "xpprotector")
|
o := mapobjectdb.NewMapObject(mbpos, x, y, z, "xpprotector")
|
||||||
o.Attributes["owner"] = md["owner"]
|
o.Attributes["owner"] = md["owner"]
|
||||||
o.Attributes["xpthreshold"] = md["xpthreshold"]
|
o.Attributes["xpthreshold"] = md["xpthreshold"]
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ package tilerendererjob
|
|||||||
import (
|
import (
|
||||||
"mapserver/app"
|
"mapserver/app"
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"mapserver/mapblockparser"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/minetest-go/mapparser"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ func getTileKey(tc *coords.TileCoords) string {
|
|||||||
strconv.Itoa(tc.Zoom) + "/" + strconv.Itoa(tc.LayerId)
|
strconv.Itoa(tc.Zoom) + "/" + strconv.Itoa(tc.LayerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderMapblocks(ctx *app.App, mblist []*mapblockparser.MapBlock) int {
|
func renderMapblocks(ctx *app.App, mblist []*mapparser.MapBlock) int {
|
||||||
tileRenderedMap := make(map[string]bool)
|
tileRenderedMap := make(map[string]bool)
|
||||||
tilecount := 0
|
tilecount := 0
|
||||||
totalRenderedMapblocks.Add(float64(len(mblist)))
|
totalRenderedMapblocks.Add(float64(len(mblist)))
|
||||||
|
Loading…
Reference in New Issue
Block a user