diff --git a/mod.conf b/mod.conf index cecff13..dbfbe93 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,5 @@ name = pick_and_place description = Pick and place utility depends = wield_events -optional_depends = mapsync \ No newline at end of file +optional_depends = mapsync +min_minetest_version = 5.5.0 \ No newline at end of file diff --git a/place_tool.lua b/place_tool.lua index d8851e5..8596c7c 100644 --- a/place_tool.lua +++ b/place_tool.lua @@ -1,5 +1,17 @@ local has_mapsync = minetest.get_modpath("mapsync") +local function get_pos(player, size) + local distance = vector.distance(vector.new(), size) + local radius = math.ceil(distance / 2) + local offset = vector.round(vector.divide(size, 2)) + + local pos1 = pick_and_place.get_pointed_position(player, radius + 2) + pos1 = vector.subtract(pos1, offset) + local pos2 = vector.add(pos1, vector.subtract(size, 1)) + + return pos1, pos2 +end + minetest.register_tool("pick_and_place:place", { description = "Placement tool", inventory_image = "pick_and_place_plus.png^[colorize:#0000ff", @@ -15,10 +27,7 @@ minetest.register_tool("pick_and_place:place", { local meta = itemstack:get_meta() local schematic = meta:get_string("schematic") local size = minetest.string_to_pos(meta:get_string("size")) - local distance = vector.distance(vector.new(), size) - - local pos1 = pick_and_place.get_pointed_position(player, math.max(10, distance) + 5) - local pos2 = vector.add(pos1, vector.subtract(size, 1)) + local pos1, pos2 = get_pos(player, size) if controls.aux1 then -- removal @@ -37,10 +46,7 @@ minetest.register_tool("pick_and_place:place", { local meta = itemstack:get_meta() local size = minetest.string_to_pos(meta:get_string("size")) - local distance = vector.distance(vector.new(), size) - - local pos1 = pick_and_place.get_pointed_position(player, math.max(10, distance) + 5) - local pos2 = vector.add(pos1, vector.subtract(size, 1)) + local pos1, pos2 = get_pos(player, size) if controls.aux1 then -- removal preview