Make map size configurable

This commit is contained in:
Nils Dagsson Moskopp 2022-05-17 13:00:47 +02:00
parent d70a251c3b
commit f47d59fc4a
Signed by: erle
GPG Key ID: A3BC671C35191080
1 changed files with 9 additions and 7 deletions

View File

@ -25,13 +25,15 @@ maps.sent = {}
maps.posx = {} maps.posx = {}
maps.posz = {} maps.posz = {}
local size = 80
local worldpath = minetest.get_worldpath() local worldpath = minetest.get_worldpath()
local textures_dir = worldpath .. "/maps/" local textures_dir = worldpath .. "/maps/"
minetest.mkdir(textures_dir) minetest.mkdir(textures_dir)
maps.create_map = function(pos, player_name) maps.create_map = function(pos, player_name)
local minp = vector.multiply(vector.floor(vector.divide(pos, 64)), 64) local minp = vector.multiply(vector.floor(vector.divide(pos, size)), size)
local maxp = vector.add(minp, vector.new(63, 63, 63)) local maxp = vector.add(minp, vector.new(size - 1, size - 1, size - 1))
local prefix, _ = minetest.pos_to_string(maxp) local prefix, _ = minetest.pos_to_string(maxp)
prefix, _ = prefix:gsub("%(", "") prefix, _ = prefix:gsub("%(", "")
@ -88,8 +90,8 @@ maps.create_map = function(pos, player_name)
{ 0, 47, 0 }, -- leaves { 0, 47, 0 }, -- leaves
{ 255, 0, 0 }, -- fire { 255, 0, 0 }, -- fire
} }
for x = 1,66,1 do for x = 1,size,1 do
for z = 1,66,1 do for z = 1,size,1 do
local color = { 0 } local color = { 0 }
pixels[z] = pixels[z] or {} pixels[z] = pixels[z] or {}
pixels[z][x] = color pixels[z][x] = color
@ -99,8 +101,8 @@ maps.create_map = function(pos, player_name)
local color_map = function(color, query) local color_map = function(color, query)
local positions = minetest.find_nodes_in_area_under_air(minp, maxp, query) local positions = minetest.find_nodes_in_area_under_air(minp, maxp, query)
for _, p in ipairs(positions) do for _, p in ipairs(positions) do
local z = p.z - minp.z + 2 local z = p.z - minp.z + 1
local x = p.x - minp.x + 2 local x = p.x - minp.x + 1
pixels[z][x] = { color } pixels[z][x] = { color }
end end
end end
@ -200,7 +202,7 @@ minetest.register_globalstep(
maps.create_map(pos, player_name) maps.create_map(pos, player_name)
end end
local x = (pos.x - minp.x - 32) * 4 local x = (pos.x - minp.x - (size/2)) * 4
local y = (minp.z - pos.z) * 4 - 2 local y = (minp.z - pos.z) * 4 - 2
player:hud_change( player:hud_change(
maps.dots[player_name], maps.dots[player_name],