61 lines
2.1 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() return nil end
end
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
local check = minetest.dig_node(pointed_thing["under"])
if check then
local inv = placer:get_inventory()
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
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
-- format : image[X,Y;W,H;texture_name]
if direction == 0 then
sizex = (value / maxvalue) * sizex
elseif direction == 1 then
sizey = (value / maxvalue) * sizey
elseif direction == 2 then
posx = posx + (sizex - ( (value/maxvalue) * sizex) )
sizex = (value / maxvalue) * sizex
elseif direction == 3 then
posy = posy + (sizey - ( (value/maxvalue) * sizey) )
sizey = (value / maxvalue) * sizey
end
return "image[" .. posx .. "," .. posy .. "," .. "," .. sizex .. "," .. sizey .. "," .. texture .. "]"
end