Some RE-Battery improvvements
This commit is contained in:
parent
3671e96a18
commit
f82170b5e5
17
api.lua
17
api.lua
|
@ -14,6 +14,8 @@
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
local S=minetest.get_translator("industrialtest")
|
||||||
|
|
||||||
industrialtest.api={}
|
industrialtest.api={}
|
||||||
|
|
||||||
industrialtest.api.addPowerStorage=function(meta,capacity,flow,ioConfig)
|
industrialtest.api.addPowerStorage=function(meta,capacity,flow,ioConfig)
|
||||||
|
@ -31,6 +33,17 @@ industrialtest.api.hasPowerStorage=function(meta)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
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)
|
industrialtest.api.isFullyCharged=function(meta)
|
||||||
return meta:get_int("industrialtest.powerAmount")>=meta:get_int("industrialtest.powerCapacity")
|
return meta:get_int("industrialtest.powerAmount")>=meta:get_int("industrialtest.powerCapacity")
|
||||||
end
|
end
|
||||||
|
@ -47,11 +60,13 @@ industrialtest.api.addPower=function(meta,amount)
|
||||||
end
|
end
|
||||||
industrialtest.api.addPowerToItem=function(itemstack,amount)
|
industrialtest.api.addPowerToItem=function(itemstack,amount)
|
||||||
local meta=itemstack:get_meta()
|
local meta=itemstack:get_meta()
|
||||||
|
local def=minetest.registered_tools[itemstack:get_name()]
|
||||||
if not industrialtest.api.hasPowerStorage(meta) then
|
if not industrialtest.api.hasPowerStorage(meta) then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
local added=industrialtest.api.addPower(meta,amount)
|
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
|
return added
|
||||||
end
|
end
|
||||||
industrialtest.api.transferPower=function(srcMeta,destMeta,amount)
|
industrialtest.api.transferPower=function(srcMeta,destMeta,amount)
|
||||||
|
|
|
@ -474,6 +474,7 @@ if industrialtest.mclAvailable then
|
||||||
end
|
end
|
||||||
-- assign element keys for elements that are required later
|
-- assign element keys for elements that are required later
|
||||||
industrialtest.elementKeys.stick="mcl_core:stick"
|
industrialtest.elementKeys.stick="mcl_core:stick"
|
||||||
|
industrialtest.elementKeys.powerCarrier="mesecons:mesecon"
|
||||||
|
|
||||||
-- register required minerals that are not available in MCL
|
-- register required minerals that are not available in MCL
|
||||||
industrialtest.registerMetal("tin","Tin",3,3)
|
industrialtest.registerMetal("tin","Tin",3,3)
|
||||||
|
|
|
@ -19,7 +19,10 @@ local S=minetest.get_translator("industrialtest")
|
||||||
-- Power storage items
|
-- Power storage items
|
||||||
minetest.register_tool("industrialtest:re_battery",{
|
minetest.register_tool("industrialtest:re_battery",{
|
||||||
description=S("RE-Battery"),
|
description=S("RE-Battery"),
|
||||||
inventory_image="industrialtest_re_battery.png"
|
inventory_image="industrialtest_re_battery.png",
|
||||||
|
_industrialtest_powerStorage=true,
|
||||||
|
_industrialtest_powerCapacity=7000,
|
||||||
|
_industrialtest_powerFlow=200
|
||||||
})
|
})
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
|
@ -33,10 +36,13 @@ minetest.register_craft({
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Item callbacks
|
-- Item callbacks
|
||||||
minetest.register_on_craft(function(itemstack,player,oldCraftGrid,craftInv)
|
minetest.register_on_player_inventory_action(function(player,action,inventory,info)
|
||||||
if itemstack:get_name()=="industrialtest:re_battery" then
|
if action=="put" then
|
||||||
itemstack:set_wear(65535)
|
if industrialtest.api.preparePowerStorageItem(info.stack) then
|
||||||
local meta=itemstack:get_meta()
|
inventory:set_stack(info.listname,info.index,info.stack)
|
||||||
industrialtest.api.addPowerStorage(meta,7000,100,"n/a")
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
minetest.register_on_craft(function(itemstack)
|
||||||
|
industrialtest.api.preparePowerStorageItem(itemstack)
|
||||||
|
end)
|
||||||
|
|
Loading…
Reference in New Issue