]> git.lizzy.rs Git - worldedit.git/blob - worldedit_commands/wand.lua
Reset region by double-punching air using the wand
[worldedit.git] / worldedit_commands / wand.lua
1 local function above_or_under(placer, pointed_thing)
2         if placer:get_player_control().sneak then
3                 return pointed_thing.above
4         else
5                 return pointed_thing.under
6         end
7 end
8
9 local punched_air_time = {}
10
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
16
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
21                         -- set and mark pos1
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
27                                 -- reset markers
28                                 minetest.registered_chatcommands["/reset"].func(name, "")
29                         end
30                         punched_air_time[name] = now
31                 end
32                 return itemstack -- nothing consumed, nothing changed
33         end,
34
35         on_place = function(itemstack, placer, pointed_thing)
36                 if placer ~= nil and pointed_thing ~= nil and pointed_thing.type == "node" then
37                         -- set and mark pos2
38                         local name = placer:get_player_name()
39                         worldedit.pos2[name] = above_or_under(placer, pointed_thing)
40                         worldedit.mark_pos2(name)
41                 end
42                 return itemstack -- nothing consumed, nothing changed
43         end,
44 })