diff --git a/server/mapblockparser/iterate.go b/server/mapblockparser/iterate.go new file mode 100644 index 0000000..b33a80d --- /dev/null +++ b/server/mapblockparser/iterate.go @@ -0,0 +1,12 @@ +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) + } + } + } +} diff --git a/server/mapblockparser/mapblock.go b/server/mapblockparser/mapblock.go index 9e519fe..7792c39 100644 --- a/server/mapblockparser/mapblock.go +++ b/server/mapblockparser/mapblock.go @@ -89,6 +89,10 @@ func (md *Metadata) GetInventoryMap(pos int) map[string]*Inventory { 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] diff --git a/server/mapobject/setup.go b/server/mapobject/setup.go index 0331bac..6228794 100644 --- a/server/mapobject/setup.go +++ b/server/mapobject/setup.go @@ -40,34 +40,28 @@ func (this *Listener) OnEvent(eventtype string, o interface{}) { for k, v := range this.objectlisteners { if k == name { //block matches + mapblockparser.IterateMapblock(func(x,y,z int){ + nodeid := block.GetNodeId(x, y, z) + if nodeid == id { + fields := logrus.Fields{ + "mbpos": block.Pos, + "x": x, + "y": y, + "z": z, + "type": name, + "nodeid": nodeid, + } + log.WithFields(fields).Debug("OnEvent()") - for x := 0; x < 16; x++ { - for y := 0; y < 16; y++ { - for z := 0; z < 16; z++ { - nodeid := block.GetNodeId(x, y, z) - if nodeid == id { - fields := logrus.Fields{ - "mbpos": block.Pos, - "x": x, - "y": y, - "z": z, - "type": name, - "nodeid": nodeid, - } - log.WithFields(fields).Debug("OnEvent()") + obj := v.onMapObject(x, y, z, block) - obj := v.onMapObject(x, y, z, block) - - if obj != nil { - this.ctx.Objectdb.AddMapData(obj) - this.ctx.WebEventbus.Emit("mapobject-created", obj) - } - } - } //z - } //y - } //x - - } + if obj != nil { + this.ctx.Objectdb.AddMapData(obj) + this.ctx.WebEventbus.Emit("mapobject-created", obj) + } + } + }) + } // k==name } //for k,v } //for id, name } diff --git a/server/mapobject/smartshop.go b/server/mapobject/smartshop.go new file mode 100644 index 0000000..8298dc7 --- /dev/null +++ b/server/mapobject/smartshop.go @@ -0,0 +1,23 @@ +package mapobject + +import ( + "mapserver/mapblockparser" + "mapserver/mapobjectdb" +) + +type SmartShopBlock struct{} + +func (this *SmartShopBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject { + md := block.Metadata.GetMetadata(x, y, z) + + o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "shop") + o.Attributes["type"] = "smartshop" + //TODO: 4 objects per coordinate + + //invMap := block.Metadata.GetInventoryMapAtPos(x, y, z) + + + o.Attributes["index"] = md["index"] + + return o +}