forked from mrkubax10/industrialtest
Some RE-Battery improvvements
This commit is contained in:
17
api.lua
17
api.lua
@@ -14,6 +14,8 @@
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
industrialtest.api={}
|
||||
|
||||
industrialtest.api.addPowerStorage=function(meta,capacity,flow,ioConfig)
|
||||
@@ -31,6 +33,17 @@ industrialtest.api.hasPowerStorage=function(meta)
|
||||
end
|
||||
return true
|
||||
end
|
||||
industrialtest.api.preparePowerStorageItem=function(itemstack)
|
||||
local meta=itemstack:get_meta()
|
||||
local def=minetest.registered_tools[itemstack:get_name()]
|
||||
if industrialtest.api.hasPowerStorage(meta) or not def or not def._industrialtest_powerStorage or not def._industrialtest_powerCapacity or not def._industrialtest_powerFlow then
|
||||
return false
|
||||
end
|
||||
itemstack:set_wear(65535)
|
||||
industrialtest.api.addPowerStorage(meta,def._industrialtest_powerCapacity,def._industrialtest_powerFlow,"n/a")
|
||||
meta:set_string("description",S("@1\n@2 / @3 EU",def.description,meta:get_int("industrialtest.powerAmount"),meta:get_int("industrialtest.powerCapacity")))
|
||||
return true
|
||||
end
|
||||
industrialtest.api.isFullyCharged=function(meta)
|
||||
return meta:get_int("industrialtest.powerAmount")>=meta:get_int("industrialtest.powerCapacity")
|
||||
end
|
||||
@@ -47,11 +60,13 @@ industrialtest.api.addPower=function(meta,amount)
|
||||
end
|
||||
industrialtest.api.addPowerToItem=function(itemstack,amount)
|
||||
local meta=itemstack:get_meta()
|
||||
local def=minetest.registered_tools[itemstack:get_name()]
|
||||
if not industrialtest.api.hasPowerStorage(meta) then
|
||||
return 0
|
||||
end
|
||||
local added=industrialtest.api.addPower(meta,amount)
|
||||
itemstack:set_wear(65535-meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*65535)
|
||||
itemstack:set_wear(65535-meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*65534)
|
||||
meta:set_string("description",S("@1\n@2 / @3 EU",def.description,meta:get_int("industrialtest.powerAmount"),meta:get_int("industrialtest.powerCapacity")))
|
||||
return added
|
||||
end
|
||||
industrialtest.api.transferPower=function(srcMeta,destMeta,amount)
|
||||
|
||||
Reference in New Issue
Block a user