From cb5b6461a38465fbb0f393cad7efe6f746e495bb Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Wed, 10 Sep 2014 08:21:51 +0200 Subject: [PATCH] Map content in DecodedBlock.Content() thru the index map to pull this logic out of the renderer. --- tilemapper/blockdecoder.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tilemapper/blockdecoder.go b/tilemapper/blockdecoder.go index 5c7b6fd..cb4dcf2 100644 --- a/tilemapper/blockdecoder.go +++ b/tilemapper/blockdecoder.go @@ -144,21 +144,26 @@ func NewDecodedBlock(data []byte, nameIndex map[string]int) (db *DecodedBlock, e return } -func (db *DecodedBlock) Content(x, y, z int) int { +func (db *DecodedBlock) Content(x, y, z int) (content int, found bool) { pos := z<<8 + y<<4 + x switch { case db.Version >= 24: pos <<= 1 - return int(db.MapContent[pos])<<8 | int(db.MapContent[pos+1]) + content = int(db.MapContent[pos])<<8 | int(db.MapContent[pos+1]) case db.Version >= 20: if db.MapContent[pos] <= 0x80 { - return int(db.MapContent[pos]) + content = int(db.MapContent[pos]) + } else { + content = int(db.MapContent[pos])<<4 | int(db.MapContent[pos+0x2000])>>4 } - return int(db.MapContent[pos])<<4 | int(db.MapContent[pos+0x2000])>>4 default: - return db.IgnoreId + return } + if content != db.AirId && content != db.IgnoreId { + content, found = db.IndexMap[content] + } + return } func NewPosBuf(data []byte) *PosBuf {