Add all code for generating a grid on world creation.

Not tested ; will likely need much testing and bugfix.
This commit is contained in:
Gaël C
2021-06-03 20:08:57 +02:00
parent 19efeaaff6
commit cb297af047
4 changed files with 105 additions and 29 deletions

View File

@ -1,6 +1,6 @@
local worldpath = minetest.world_data_path
local function load_map(filename, bytes, signed, size)
function mapgen_rivers.load_map(filename, bytes, signed, size)
local file = io.open(worldpath .. filename, 'rb')
local data = file:read('*all')
if #data < bytes*size then
@ -28,4 +28,28 @@ local function load_map(filename, bytes, signed, size)
return map
end
return load_map
function mapgen_rivers.write_map(filename, data, bytes)
local size = #data
local file = io.open(worldpath .. filename, 'wb')
local mfloor = math.floor
local schar = string.char
local upack = unpack
local bytelist = {}
for j=1, bytes do
bytelist[j] = 0
end
for i=1, size do
local n = mfloor(data[i])
for j=bytes, 2, -1 do
bytelist[j] = n % 256
n = mfloor(n / 256)
end
bytelist[1] = n % 256
file:write(schar(upack(bytelist)))
end
file:close()
end