1
0
forked from MTSR/mapserver

mb iterator

This commit is contained in:
NatureFreshMilk 2019-02-08 11:23:04 +01:00
parent 35b5224822
commit edda1561b9
4 changed files with 59 additions and 26 deletions

View File

@ -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)
}
}
}
}

View File

@ -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]

View File

@ -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
}

View File

@ -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
}