diff --git a/server/mapblockparser/mapblock.go b/server/mapblockparser/mapblock.go index f378d66..ddb1ee2 100644 --- a/server/mapblockparser/mapblock.go +++ b/server/mapblockparser/mapblock.go @@ -9,12 +9,18 @@ type MapBlock struct { Size int `json:"size"` Version byte `json:"version"` Underground bool `json:"underground"` - Mapdata []byte `json:"mapdata"` + 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"` @@ -37,7 +43,7 @@ func getNodePos(x, y, z int) int { func (mb *MapBlock) GetNodeName(x, y, z int) string { pos := getNodePos(x, y, z) - id := readU16(mb.Mapdata, pos*2) + id := mb.Mapdata.ContentId[pos] return mb.BlockMapping[id] } diff --git a/server/mapblockparser/mapdata.go b/server/mapblockparser/mapdata.go index 70bca87..2c384b5 100644 --- a/server/mapblockparser/mapdata.go +++ b/server/mapblockparser/mapdata.go @@ -30,7 +30,20 @@ func parseMapdata(mapblock *MapBlock, data []byte) (int, error) { return 0, errors.New("Mapdata length invalid: " + strconv.Itoa(buf.Len())) } - mapblock.Mapdata = buf.Bytes() + 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, (i*2)+2) + mapd.Param2[i] = readU8(rawdata, (i*2)+3) //TODO: last item has wrong value + } return cr.Count, nil } diff --git a/server/mapblockparser/metadata.go b/server/mapblockparser/metadata.go index 53ed80c..cd335f9 100644 --- a/server/mapblockparser/metadata.go +++ b/server/mapblockparser/metadata.go @@ -25,6 +25,10 @@ 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 | diff --git a/server/mapblockrenderer/renderer.go b/server/mapblockrenderer/renderer.go index 87e1a96..d3b6893 100644 --- a/server/mapblockrenderer/renderer.go +++ b/server/mapblockrenderer/renderer.go @@ -136,7 +136,9 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB if x > 0 { //same mapblock left = mb.GetNodeName(x-1, y, z) - leftAbove = mb.GetNodeName(x-1, y+1, z) + if y < 15 { + leftAbove = mb.GetNodeName(x-1, y+1, z) + } } else { //neighbouring mapblock @@ -145,14 +147,18 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB if neighbourMapblock != nil && err == nil { left = neighbourMapblock.GetNodeName(15, y, z) - leftAbove = neighbourMapblock.GetNodeName(15, y+1, z) + if y < 15 { + leftAbove = neighbourMapblock.GetNodeName(15, y+1, z) + } } } if z < 14 { //same mapblock top = mb.GetNodeName(x, y, z+1) - topAbove = mb.GetNodeName(x, y+1, z+1) + if y < 15 { + topAbove = mb.GetNodeName(x, y+1, z+1) + } } else { //neighbouring mapblock @@ -161,7 +167,9 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB if neighbourMapblock != nil && err == nil { top = neighbourMapblock.GetNodeName(x, y, 0) - topAbove = neighbourMapblock.GetNodeName(x, y+1, z+0) + if y < 15 { + topAbove = neighbourMapblock.GetNodeName(x, y+1, z+0) + } } } diff --git a/server/web/mapobjects.go b/server/web/mapobjects.go index 1d1ffb5..03a0c29 100644 --- a/server/web/mapobjects.go +++ b/server/web/mapobjects.go @@ -1,10 +1,10 @@ package web import ( + "encoding/json" "mapserver/app" "mapserver/coords" "mapserver/mapobjectdb" - "encoding/json" "net/http" "strconv" "strings"