Skip to content

Instantly share code, notes, and snippets.

@zerowidth
Created December 30, 2010 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerowidth/760082 to your computer and use it in GitHub Desktop.
Save zerowidth/760082 to your computer and use it in GitHub Desktop.
module Golem
class ServerMapConverter
def self.convert(src_path, dest_path)
new(src_path, dest_path).convert
end
attr_reader :src, :dest
def initialize(src_path, dest_path)
@src = Pathname.new(src_path).expand_path
@dest = Pathname.new(dest_path).expand_path
end
def convert
Dir.chdir(dest) do
each_chunk_file do |file|
# next unless file.basename.to_s == "c.0.0.dat"
dump_converted file
end
end
end
def dump_converted(file)
data = NBTParser.parse(File.read(file))
level = data[""]["Level"]
# ["Data", "Entities", "LastUpdate", "xPos", "zPos", "TileEntities", "TerrainPopulated", "SkyLight", "HeightMap", "BlockLight", "Blocks"]
# puts level["Blocks"].size
# puts level["BlockLight"].size
# puts level["SkyLight"].size
x = level["xPos"]
z = level["zPos"]
fn = "#{x}.#{z}.blocks"
puts "writing #{fn}"
File.open(fn, "w") do |f|
f.puts level["Blocks"].pack("C*")
end
end
def each_chunk_file
src.each_child do |top|
next unless top.directory?
top.each_child do |sub|
next unless sub.directory?
sub.each_child do |file|
next unless file.basename.to_s =~ /\.dat$/
yield file
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment