refactor is a straight copy-paste. this code could really stand some cleanup (unused vars, unnecessary use of the MapCache layer, forced allocation of all blocks even if they are not being unhidden, etc.), but that can come in a later PR.