From c77b1c491f4c3d08f93de9e430e84ee7d2ddbac5 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Tue, 2 Apr 2019 16:23:12 +0200 Subject: [PATCH] check for u16 lighting_complete added in version 27, offset data accordingly --- server/mapblockparser/parse.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/mapblockparser/parse.go b/server/mapblockparser/parse.go index 2612cfa..36ba7d5 100644 --- a/server/mapblockparser/parse.go +++ b/server/mapblockparser/parse.go @@ -20,8 +20,6 @@ func Parse(data []byte, mtime int64, pos *coords.MapBlockCoords) (*MapBlock, err mapblock.Pos = pos mapblock.Size = len(data) - offset := 0 - // version mapblock.Version = data[0] @@ -33,8 +31,17 @@ func Parse(data []byte, mtime int64, pos *coords.MapBlockCoords) (*MapBlock, err flags := data[1] mapblock.Underground = (flags & 0x01) == 0x01 - content_width := data[4] - params_width := data[4] + 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)))