forked from mrkubax10/industrialtest
Make industrialtest.api.addPower accept negative power amount
This commit is contained in:
parent
f82d4730eb
commit
f74f36aeb3
15
api.lua
15
api.lua
@ -19,6 +19,10 @@ local S=minetest.get_translator("industrialtest")
|
|||||||
industrialtest.api={}
|
industrialtest.api={}
|
||||||
industrialtest.api.maceratorRecipes={}
|
industrialtest.api.maceratorRecipes={}
|
||||||
|
|
||||||
|
local function clamp(num,min,max)
|
||||||
|
return math.max(math.min(num,max),min)
|
||||||
|
end
|
||||||
|
|
||||||
-- \brief Adds power storage to metadata
|
-- \brief Adds power storage to metadata
|
||||||
-- \param capacity How much EU item/node can store
|
-- \param capacity How much EU item/node can store
|
||||||
-- \param flow How much EU can flow in or out item/node per industrialtest.updateDelay
|
-- \param flow How much EU can flow in or out item/node per industrialtest.updateDelay
|
||||||
@ -93,13 +97,10 @@ end
|
|||||||
industrialtest.api.addPower=function(meta,amount)
|
industrialtest.api.addPower=function(meta,amount)
|
||||||
local powerAmount=meta:get_int("industrialtest.powerAmount")
|
local powerAmount=meta:get_int("industrialtest.powerAmount")
|
||||||
local powerCapacity=meta:get_int("industrialtest.powerCapacity")
|
local powerCapacity=meta:get_int("industrialtest.powerCapacity")
|
||||||
if powerAmount+amount>powerCapacity then
|
local prevPowerAmount=powerAmount
|
||||||
local addedAmount=powerCapacity-powerAmount
|
powerAmount=clamp(powerAmount+amount,0,powerCapacity)
|
||||||
meta:set_int("industrialtest.powerAmount",powerCapacity)
|
meta:set_int("industrialtest.powerAmount",powerAmount)
|
||||||
return addedAmount
|
return powerAmount-prevPowerAmount
|
||||||
end
|
|
||||||
meta:set_int("industrialtest.powerAmount",powerAmount+amount)
|
|
||||||
return 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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user