105 lines
3.9 KiB
Lua
105 lines
3.9 KiB
Lua
sparktech = {}
|
|
function sparktech.register_wrench(name, dictionary)
|
|
local dig_stlye_alt = minetest.setting_getbool("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
|
|
minetest.debug(dump2(pointedobject))
|
|
return nil
|
|
end
|
|
local inventory = pointedobject["ref"]:get_wielded_item()
|
|
minetest.debug(dump2(inventory))
|
|
player:get_inventory():add_item("main",pointedobject["ref"]:get_wielded_item())
|
|
end -- this should work, it doesnt, for some reason
|
|
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
|
|
|
|
function sparktech.makebar(texture, posx, posy, sizex, sizey, value, maxvalue, direction)
|
|
-- direction = where to cut the texture either from thr right(0), below(1) left(2) or above (3)
|
|
-- default is right(0)
|
|
--texture texture name , no folder required
|
|
--sizex the size to modify
|
|
if direction == nil then direction = 0 end --direction is optional this way
|
|
-- format : image[X,Y;W,H;texture_name]
|
|
|
|
local ratio = value / maxvalue
|
|
|
|
if direction == 0 then
|
|
sizex = ratio * sizex
|
|
elseif direction == 1 then
|
|
sizey = ratio * sizey
|
|
elseif direction == 2 then -- Formspecs still suck
|
|
-- the coordinat system for width and position is not on the same scale! as fallback
|
|
-- 2 and 3 will act like 0 and 1 :/
|
|
--posx = posx + (sizex - (ratio * sizex))
|
|
sizex = ratio * sizex
|
|
elseif direction == 3 then
|
|
--posy = posy + (sizey - (ratio * sizey))
|
|
sizey = ratio * sizey
|
|
end
|
|
|
|
return "image[" .. posx .. "," .. posy .. ";" .. sizex .. "," .. sizey .. ";" .. texture .. "]"
|
|
end
|
|
function sparktech.add_inventory(size_x, size_y, formspec) -- pass an unfinished formspec with minimum size, this function adds an inventory
|
|
if not size_x or size_x < 11.5 then size_x = 11.5 end
|
|
if not size_y or size_y < 0 then size_y = 0 end
|
|
local l_formspec = "size[" .. tostring(size_x) .. "," .. (size_y + 4) .. "]" ..
|
|
"list[current_player;main;0," .. size_y .. ";8,3;8]" ..
|
|
"list[current_player;main;0," .. (size_y + 3.2 ) .. ";8,1;]"..
|
|
"list[current_player;craft;8.5," .. size_y .. ";3,3]" ..
|
|
"list[current_player;craftpreview;8.5," .. (size_y + 3.2) .. ";1,1]" ..
|
|
"listcolors[#fc059db0;#fc059dd0]" ..
|
|
"bgcolor[#FC05E344;false]"
|
|
if not formspec then formspec = "" end
|
|
l_formspec = l_formspec .. formspec
|
|
minetest.debug(dump(l_formspec))
|
|
minetest.debug(l_formspec)
|
|
return l_formspec
|
|
end
|