check for u16 lighting_complete added in version 27, offset data accordingly

This commit is contained in:
NatureFreshMilk 2019-04-02 16:23:12 +02:00
parent 7c826012d9
commit c77b1c491f

View File

@ -20,8 +20,6 @@ func Parse(data []byte, mtime int64, pos *coords.MapBlockCoords) (*MapBlock, err
mapblock.Pos = pos mapblock.Pos = pos
mapblock.Size = len(data) mapblock.Size = len(data)
offset := 0
// version // version
mapblock.Version = data[0] mapblock.Version = data[0]
@ -33,8 +31,17 @@ func Parse(data []byte, mtime int64, pos *coords.MapBlockCoords) (*MapBlock, err
flags := data[1] flags := data[1]
mapblock.Underground = (flags & 0x01) == 0x01 mapblock.Underground = (flags & 0x01) == 0x01
content_width := data[4] var offset int
params_width := data[4]
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 { if content_width != 2 {
return nil, errors.New("content_width = " + strconv.Itoa(int(content_width))) return nil, errors.New("content_width = " + strconv.Itoa(int(content_width)))