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 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 worldedit.registered_commands["reset"].func(name)
30 punched_air_time[name] = now
31 elseif pointed_thing.type == "object" then
32 local entity = pointed_thing.ref:get_luaentity()
33 if entity and entity.name == "worldedit:pos2" then
35 worldedit.pos1[name] = worldedit.pos2[name]
36 worldedit.mark_pos1(name)
41 on_place = function(itemstack, placer, pointed_thing)
42 if placer == nil or (pointed_thing or {}).type ~= "node" then
45 local name = placer:get_player_name()
47 worldedit.pos2[name] = above_or_under(placer, pointed_thing)
48 worldedit.mark_pos2(name)
49 return itemstack -- nothing consumed, nothing changed
52 on_secondary_use = function(itemstack, user, pointed_thing)
53 if user == nil or (pointed_thing or {}).type ~= "object" then
56 local name = user:get_player_name()
57 local entity = pointed_thing.ref:get_luaentity()
58 if entity and entity.name == "worldedit:pos1" then
60 worldedit.pos2[name] = worldedit.pos1[name]
61 worldedit.mark_pos2(name)
63 return itemstack -- nothing consumed, nothing changed