40 lines
1.4 KiB
Lua
40 lines
1.4 KiB
Lua
if not sparktech then sparktech = {} end
|
|
function sparktech.register_wrench(name, dictionary)
|
|
local dig_stlye_alt = minetest.settings:get_bool("spark_dig_stlye_alt")
|
|
local on_use = nil
|
|
if dig_stlye_alt then
|
|
on_use = function(one, player, pointedobject)
|
|
if pointedobject == nil or pointedobject["type"] ~= "object" or pointedobject["ref"] == nil then
|
|
return nil
|
|
end
|
|
local item = pointedobject.ref
|
|
local lua_item = item:get_luaentity()
|
|
local player_inv = player:get_inventory()
|
|
notify.hud.sendtext(minetest.get_player_by_name("nep"), dump2(item), 60)
|
|
if player_inv:room_for_item("main", ItemStack(lua_item.itemstring)) then
|
|
player:get_inventory():add_item("main", ItemStack(lua_item.itemstring))
|
|
lua_item.itemstring = ""
|
|
lua_item.object:remove()
|
|
end
|
|
end
|
|
end
|
|
local on_place = function(itemstack, placer, pointed_thing)
|
|
if pointed_thing["type"] == "node" then
|
|
if not sparktech.dig_node then dofile("./dig.lua") end
|
|
|
|
if minetest.get_item_group(minetest.get_node(pointed_thing["under"])["name"], "sparktech_techy") > 0 then
|
|
sparktech.dig_node(pointed_thing["under"], placer:get_inventory(), "main", false, placer)
|
|
end
|
|
end
|
|
return itemstack
|
|
end
|
|
if dictionary["on_use"] == nil then
|
|
dictionary["on_use"] = on_use
|
|
end
|
|
if dictionary["on_place"] == nil then
|
|
dictionary["on_place"] = on_place
|
|
end
|
|
|
|
minetest.register_tool(name, dictionary)
|
|
end
|