]> git.lizzy.rs Git - autodupe.git/blob - init.lua
d365af7979f5ebe57290303b338cc87245f47752
[autodupe.git] / init.lua
1 minetest.register_globalstep(function()
2         if not minetest.settings:get_bool("autodupe") then return end
3         local player = minetest.localplayer
4         if not player then return end
5         local airs = minetest.find_nodes_near(player:get_pos(), 5, "air")
6         for _, p in ipairs(airs) do
7                 local invstr = "nodemeta:" .. p.x .. "," .. p.y .. "," .. p.z
8                 if minetest.get_inventory(invstr) then
9                         local invact = InventoryAction("drop")
10                         invact:from(invstr, "src", 1)
11                         invact:set_count(0)
12                         invact:apply()
13                 end
14         end
15         local furnaces = minetest.find_nodes_near(player:get_pos(), 5, "mcl_furnaces:furnace")
16         local dug_any = false
17         local index = player:get_wield_index()
18         for _, p in ipairs(furnaces) do
19                 local inv = minetest.get_inventory("nodemeta:" .. p.x .. "," .. p.y .. "," .. p.z)
20                 if inv and inv.src and inv.src[1]:get_name() ~= "" then
21                         if not dug_any then
22                                 autotool.select_best_tool("mcl_furnaces:furnace")
23                                 dug_any = true
24                         end
25                         minetest.dig_node(p)
26                 end
27         end
28         if dug_any then
29                 player:set_wield_index(index)
30                 minetest.close_formspec("")
31         end
32 end) 
33
34 minetest.register_cheat("AutoDupe", "World", "autodupe")