diff --git a/common.lua b/common.lua index 89c345d..ae8d3c8 100644 --- a/common.lua +++ b/common.lua @@ -18,3 +18,9 @@ function pick_and_place.sort_pos(pos1, pos2) end return pos1, pos2 end + +function pick_and_place.get_formatted_size(pos1, pos2) + pos2 = pos2 or pos1 + pos1, pos2 = pick_and_place.sort_pos(pos1, pos2) + return minetest.pos_to_string(vector.add(vector.subtract(pos2, pos1), 1)) +end \ No newline at end of file diff --git a/configure_tool.lua b/configure_tool.lua index 596a05d..72afdc1 100644 --- a/configure_tool.lua +++ b/configure_tool.lua @@ -38,9 +38,11 @@ minetest.register_tool("pick_and_place:configure", { on_step = function(_, player) local playername = player:get_player_name() local pointed_pos = pick_and_place.get_pointed_position(player) + local pointed_pos2 = pos1[playername] + local text = pick_and_place.get_formatted_size(pointed_pos, pointed_pos2) -- update preview - pick_and_place.show_preview(playername, "pick_and_place.png", "#ffffff", pointed_pos, pos1[playername]) + pick_and_place.show_preview(playername, "pick_and_place.png", "#ffffff", pointed_pos, pointed_pos2, text) end, on_deselect = function(_, player) local playername = player:get_player_name() diff --git a/pick_tool.lua b/pick_tool.lua index 3d9e5b7..fefbd07 100644 --- a/pick_tool.lua +++ b/pick_tool.lua @@ -32,10 +32,12 @@ minetest.register_tool("pick_and_place:pick", { on_step = function(_, player) local playername = player:get_player_name() local pointed_pos = pick_and_place.get_pointed_position(player) + local pointed_pos2 = pos1[playername] - if pos1[playername] then + if pointed_pos2 then -- first position already selected - pick_and_place.show_preview(playername, "pick_and_place.png", "#00ff00", pointed_pos, pos1[playername]) + local text = pick_and_place.get_formatted_size(pointed_pos, pointed_pos2) + pick_and_place.show_preview(playername, "pick_and_place.png", "#00ff00", pointed_pos, pointed_pos2, text) else -- nothing selected yet pick_and_place.show_preview(playername, "pick_and_place.png", "#00ff00", pointed_pos) diff --git a/preview.lua b/preview.lua index b11bc81..97a2b6b 100644 --- a/preview.lua +++ b/preview.lua @@ -2,7 +2,7 @@ -- playername => key local active_preview = {} -function pick_and_place.show_preview(playername, texture, color, pos1, pos2) +function pick_and_place.show_preview(playername, texture, color, pos1, pos2, text) pos2 = pos2 or pos1 texture = texture .. "^[colorize:" .. color @@ -11,7 +11,8 @@ function pick_and_place.show_preview(playername, texture, color, pos1, pos2) local key = minetest.pos_to_string(pos1) .. "/" .. minetest.pos_to_string(pos2) .. "/" .. - texture + texture .. "/" .. + (text or "") if active_preview[playername] == key then -- already active on the same region @@ -28,6 +29,7 @@ function pick_and_place.show_preview(playername, texture, color, pos1, pos2) local ent = pick_and_place.add_entity(origin, key) ent:set_properties({ visual_size = visual_size, + nametag = text, textures = { texture, texture,