This repository has been archived on 2020-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
minetest-mod-sparktech/sparkapi/lua/energy.lua

17 lines
489 B
Lua

if not sparktech then sparktech = {} end
function sparktech.can_drain_energy(target_pos, ammount) ---
--- check whether you can drain
return minetest.get_meta(target_pos):get_int("energy") >= ammount
end
function sparktech.drain_energy(target_pos, ammount)
local target = minetest.get_meta(target_pos)
local current = target:get_int("energy")
if sparktech.can_drain_energy(target_pos, ammount) then
target:set_int("energy", current - ammount)
return true
end
return false
end