locator mapobject

This commit is contained in:
NatureFreshMilk 2019-05-08 15:50:51 +02:00
parent 216c1dd6fa
commit 26f54449a2
3 changed files with 39 additions and 0 deletions

View File

@ -61,6 +61,7 @@ type MapObjectConfig struct {
ATM bool `json:"atm"`
Train bool `json:"train"`
Minecart bool `json:"minecart"`
Locator bool `json:"locator"`
}
type WebApiConfig struct {
@ -148,6 +149,7 @@ func ParseConfig(filename string) (*Config, error) {
ATM: true,
Train: true,
Minecart: false,
Locator: false,
}
mapblockaccessor := MapBlockAccessorConfig{

View File

@ -0,0 +1,29 @@
package mapobject
import (
"mapserver/mapblockparser"
"mapserver/mapobjectdb"
)
type Locator struct{}
func (this *Locator) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
md := block.Metadata.GetMetadata(x, y, z)
nodename := block.GetNodeName(x, y, z)
var level = "1"
switch nodename {
case "locator:beacon_2":
level = "2"
case "locator:beacon_3":
level = "3"
}
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "locator")
o.Attributes["owner"] = md["owner"]
o.Attributes["name"] = md["name"]
o.Attributes["active"] = md["active"]
o.Attributes["level"] = level
return o
}

View File

@ -150,5 +150,13 @@ func Setup(ctx *app.App) {
l.AddMapObject("atm:atm", &ATM{})
}
//locator
if ctx.Config.MapObjects.Locator {
loc := &Locator{}
l.AddMapObject("locator:beacon_1", loc)
l.AddMapObject("locator:beacon_2", loc)
l.AddMapObject("locator:beacon_3", loc)
}
ctx.BlockAccessor.Eventbus.AddListener(&l)
}