Skip to content

Instantly share code, notes, and snippets.

@zerowidth
Created November 5, 2010 16:51
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/664436 to your computer and use it in GitHub Desktop.
Save zerowidth/664436 to your computer and use it in GitHub Desktop.
generate flat map chunks for easy testing (minecraft alpha server)
#!/usr/bin/env ruby
require "fileutils"
require "pathname"
require "zlib"
world = Pathname.new File.expand_path("./world")
0.upto(3) do |x|
0.upto(3) do |z|
out = ""
out << [10, 0, 10, 5, "Level"].pack("cncna5")
block_data = [7, 4, "Data", 16384] + [0] * 128 * 256
out << block_data.pack("cna4Nc16384")
out << [9, 8, "Entities", 10, 0].pack("cna8cN")
last_update = 0
big = last_update >> 32
little = last_update - (last_update >> 32 << 32)
out << [4, 10, "LastUpdate", big, little].pack("cna10NN")
out << [3, 4, "xPos", x].pack("cna4N")
out << [3, 4, "zPos", z].pack("cna4N")
out << [9, 12, "TileEntities", 10, 0].pack("cna12cN")
out << [1, 16, "TerrainPopulated", 1].pack("cna16c")
# sky_light = [0] * 64 + [240] + [255] * 63
sky_light = [0] * 32 + [255] * 32
sky_light = [7, 8, "SkyLight", 16384] + sky_light * 256
out << sky_light.pack("cna8NC16384")
heights = [7, 9, "HeightMap", 256] + [64] * 256
out << heights.pack("cna9NC256")
block_light = [0] * 128
block_light = [7, 10, "BlockLight", 16384] + block_light * 256
out << block_light.pack("cna10NC16384")
column = [7, 7, 7, 7, 7] + [3] * 58 + [2] + [0] * 64
blocks = [7, 6, "Blocks", 32768] + column * 256
out << blocks.pack("cna6Nc32768")
# close out the Level and "" complex entities
out << [0, 0].pack("cc")
fn = world + "#{x}/#{z}/c.#{x}.#{z}.dat"
puts "writing #{fn}..."
Zlib::GzipWriter.open(fn) { |gz| gz << out }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment