blocks = {} function blocks.get(x, y, z) local err local cx, cy, cz = math.floor(x/CHUNK_SIZE), math.floor(y/CHUNK_SIZE), math.floor(z/CHUNK_SIZE) local chunk = chunks.get(cx, cy, xz) local x, y, z = x % CHUNK_SIZE, y % CHUNK_SIZE, z % CHUNK_SIZE return chunk:getBlock(x, y, z) end function blocks.getAll() local ret = {} for i, chunk in pairs(chunks.getAll()) do for ii, block in pairs(chunk:getBlocks()) do table.insert(ret, block) end end return ret end function blocks.set(x, y, z) local err local cx, cy, cz = math.floor(x/CHUNK_SIZE), math.floor(y/CHUNK_SIZE), math.floor(z/CHUNK_SIZE) local chunk = chunks.get(cx, cy, xz) local x, y, z = x % CHUNK_SIZE, y % CHUNK_SIZE, z % CHUNK_SIZE chunk:setBlock(x, y, z) end local meta = {} function meta:getChunk() return chunks.get(cid) end function meta:getX() local x, y, z = util.PosFromID(self.id) return x end function meta:getY() local x, y, z = util.PosFromID(self.id) return y end function meta:getZ() local x, y, z = util.PosFromID(self.id) return z end function meta:getPos() local x, y, z = util.PosFromID(self.id) return Vector(x, y, z) end function meta:getWorldX() return self:getChunk().x * CHUNK_SIZE + self:getX() end function meta:getWorldY() return self:getChunk().y * CHUNK_SIZE + self:getY() end function meta:getWorldZ() return self:getChunk().z * CHUNK_SIZE + self:getZ() end function meta:getWorldPos() return Vector(self:getWorldX(), self:getWorldY(), self:getWorldZ()) end function meta:isActive() return self.type > 0 end function meta:setBlockType(type) self.type = type end function meta:getBlockType() return self.type end meta.__index = meta function Block(chunk, x, y, z, type) local ret = { cid = chunk.id, id = util.IDFromPos(x, y, z), type = type } setmetatable(ret, meta) return ret end