2019-09-04 12:28:48 +02:00

67 lines
2.1 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
local node = minetest.get_node(pointed_thing["under"])
if minetest.get_item_group(node["name"], "sparktech_techy") > 0 then
local nodemeta = minetest.get_meta(pointed_thing["under"])
local item = ItemStack(node["name"])
if minetest.get_item_group(item:get_name(), "sparktech_energy_storeonbreak") > 0 then
item:set_metadata(nodemeta:get_int("energy"))
end
minetest.remove_node(pointed_thing["under"])
sparktech.remove_node_from_net(pointed_thing.under, node)
local node_inv = nodemeta:get_inventory()
local inv = placer:get_inventory()
local inventory_lists = node_inv:get_lists()
for i, list in pairs(inventory_lists) do
for n=1, #list do
if inv:room_for_item("main", list[n]) then
inv:add_item("main", list[n])
else
minetest.item_drop(list[n], placer, pointed_thing["under"])
end
end
end
if inv:room_for_item("main", item) then
inv:add_item("main", item)
else
minetest.item_drop(item, placer, pointed_thing["under"])
end
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