From 7c55cfaeaf9499bc37e561e0a7307aac90619c39 Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Sun, 26 Apr 2020 10:21:24 -0400 Subject: [PATCH] Various command-related fixes --- commands.lua | 6 +++++- map_formspec.lua | 2 +- table.lua | 12 ++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/commands.lua b/commands.lua index 0e0668f..ecdf4e6 100644 --- a/commands.lua +++ b/commands.lua @@ -16,14 +16,18 @@ minetest.register_chatcommand("map", { if detail then detail = tonumber(detail); + else + detail = MAXINT; end if scale then scale = tonumber(scale); + else + scale = 1; end cartographer.map_sound("cartographer_open_map", player); - minetest.show_formspec(name, "map", cartographer.get_map_formspec(data, math.floor(player_x / scale + 0.5), math.floor(player_z / scale + 0.5), 40, 40, detail or MAXINT, scale or 1, true)); + minetest.show_formspec(name, "map", cartographer.get_map_formspec(data, math.floor((player_x / scale) + 0.5), math.floor((player_z / scale) + 0.5), 40, 40, detail, scale, true)); end, }) diff --git a/map_formspec.lua b/map_formspec.lua index e48bdce..e38ed66 100644 --- a/map_formspec.lua +++ b/map_formspec.lua @@ -141,7 +141,7 @@ end function cartographer.get_map_formspec(data, x, y, w, h, detail, scale, height_mode) local formspec_width = (w + 1) * TILE_OFFSET + 0.01; local formspec_height = (h + 1) * TILE_OFFSET + 0.01; - return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(data, x - (w * 0.5), y - (h * 0.5), w, h, x, z, detail, scale, height_mode), + return map_formspec_prefix:format(formspec_width, formspec_height)..generate_map(data, x - (w * 0.5), y - (h * 0.5), w, h, x, y, detail, scale, height_mode), formspec_width, formspec_height; end diff --git a/table.lua b/table.lua index 35a6b6a..6d3434a 100644 --- a/table.lua +++ b/table.lua @@ -674,21 +674,21 @@ minetest.register_node("cartographer:advanced_table", { }); function cartographer.register_map_material_name(name, material, value) - if _cartographer.materials_by_name[name] == nil then + if _cartographer.materials_by_name[name] then + _cartographer.materials_by_name[name][material] = value or 1; + else _cartographer.materials_by_name[name] = { [material] = value or 1, }; - else - _cartographer.materials_by_name[name][material] = value; end end function cartographer.register_map_material_group(name, material, value) - if _cartographer.materials_by_group[name] == nil then + if _cartographer.materials_by_group[name] then + _cartographer.materials_by_group[name][material] = value or 1; + else _cartographer.materials_by_group[name] = { [material] = value or 1, }; - else - _cartographer.materials_by_group[name][material] = value; end end