1 local function above_or_under(placer, pointed_thing)
2 if placer:get_player_control().sneak then
3 return pointed_thing.above
5 return pointed_thing.under
9 local punched_air_time = {}
11 minetest.register_tool(":worldedit:wand", {
12 description = "WorldEdit Wand tool\nLeft-click to set 1st position, right-click to set 2nd",
13 inventory_image = "worldedit_wand.png",
14 stack_max = 1, -- there is no need to have more than one
15 liquids_pointable = true, -- ground with only water on can be selected as well
17 on_use = function(itemstack, placer, pointed_thing)
18 if placer == nil or pointed_thing == nil then return itemstack end
19 local name = placer:get_player_name()
20 if pointed_thing.type == "node" then
22 worldedit.pos1[name] = above_or_under(placer, pointed_thing)
23 worldedit.mark_pos1(name)
24 elseif pointed_thing.type == "nothing" then
25 local now = minetest.get_us_time()
26 if now - (punched_air_time[name] or 0) < 1000 * 1000 then
28 minetest.registered_chatcommands["/reset"].func(name, "")
30 punched_air_time[name] = now
32 return itemstack -- nothing consumed, nothing changed
35 on_place = function(itemstack, placer, pointed_thing)
36 if placer ~= nil and pointed_thing ~= nil and pointed_thing.type == "node" then
38 local name = placer:get_player_name()
39 worldedit.pos2[name] = above_or_under(placer, pointed_thing)
40 worldedit.mark_pos2(name)
42 return itemstack -- nothing consumed, nothing changed