diff --git a/sparkapi/lua/energy.lua b/sparkapi/lua/energy.lua new file mode 100644 index 0000000..f4c49ee --- /dev/null +++ b/sparkapi/lua/energy.lua @@ -0,0 +1,16 @@ +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