autotool: reset old wield index when node dug

This commit is contained in:
cora 2020-10-26 13:01:37 +01:00
parent 941b979be6
commit 6851ebdbfd

View File

@ -1,4 +1,5 @@
autotool={} autotool={}
local odx=nil
function autotool.check_tool(stack, node_groups, old_best_time) function autotool.check_tool(stack, node_groups, old_best_time)
local toolcaps = stack:get_tool_capabilities() local toolcaps = stack:get_tool_capabilities()
if not toolcaps then return end if not toolcaps then return end
@ -15,6 +16,7 @@ function autotool.check_tool(stack, node_groups, old_best_time)
return best_time < old_best_time, best_time return best_time < old_best_time, best_time
end end
minetest.register_on_punchnode(function(pos, node) minetest.register_on_punchnode(function(pos, node)
--minetest.display_chat_message(dump(node)) --minetest.display_chat_message(dump(node))
if not minetest.settings:get_bool("autotool") then return end if not minetest.settings:get_bool("autotool") then return end
@ -30,7 +32,21 @@ minetest.register_on_punchnode(function(pos, node)
new_index = index - 1 new_index = index - 1
end end
end end
odx=player:get_wield_index()
player:set_wield_index(new_index) player:set_wield_index(new_index)
minetest.after("0.5",function()
local nd=minetest.get_node_or_nil(pos)
if nd.name == "air" then
minetest.localplayer:set_wield_index(odx)
end
end)
end)
minetest.register_on_dignode(function(pos, node)
if odx then
minetest.localplayer:set_wield_index(odx)
odx=nil
end
end) end)
minetest.register_cheat("AutoTool", "Inventory", "autotool") minetest.register_cheat("AutoTool", "Inventory", "autotool")