Implement Transformers
This commit is contained in:
31
api.lua
31
api.lua
@@ -27,7 +27,8 @@ industrialtest.api.hvPowerFlow=10200
|
||||
industrialtest.api.evPowerFlow=40800
|
||||
industrialtest.api.ivPowerFlow=163800
|
||||
|
||||
local function clamp(num,min,max)
|
||||
industrialtest.internal={}
|
||||
industrialtest.internal.clamp=function(num,min,max)
|
||||
return math.max(math.min(num,max),min)
|
||||
end
|
||||
|
||||
@@ -43,6 +44,32 @@ industrialtest.api.addPowerStorage=function(meta,capacity,flow,ioConfig)
|
||||
meta:set_int("industrialtest.powerAmount",0)
|
||||
meta:set_string("industrialtest.ioConfig",ioConfig)
|
||||
end
|
||||
-- \brief Takes rotated node and side and outputs normalized side that can be used for ioConfig lookups
|
||||
-- \param pos Vector with node position
|
||||
-- \param side Node side. See industrialtest.api.addPowerStorage for possible values
|
||||
-- \returns Normalized side or in case of failure side argument back
|
||||
industrialtest.api.normalizeSide=function(pos,side)
|
||||
local node=minetest.get_node(pos)
|
||||
-- FIXME: improve code quality there
|
||||
local translation={
|
||||
[0]={
|
||||
1,2,3,4,5,6
|
||||
},
|
||||
[1]={
|
||||
5,6,3,4,2,1
|
||||
},
|
||||
[2]={
|
||||
1,2,3,4,6,5
|
||||
},
|
||||
[3]={
|
||||
6,5,3,4,1,2
|
||||
}
|
||||
}
|
||||
if node.param2>3 then
|
||||
return side
|
||||
end
|
||||
return translation[node.param2][side]
|
||||
end
|
||||
-- \brief Checks if metadata contains power storage
|
||||
-- \param meta MetaDataRef which should be checked
|
||||
-- \returns true if metadata contains power storage, false otherwise
|
||||
@@ -129,7 +156,7 @@ industrialtest.api.addPower=function(meta,amount)
|
||||
local powerAmount=meta:get_int("industrialtest.powerAmount")
|
||||
local powerCapacity=meta:get_int("industrialtest.powerCapacity")
|
||||
local prevPowerAmount=powerAmount
|
||||
powerAmount=clamp(powerAmount+amount,0,powerCapacity)
|
||||
powerAmount=industrialtest.internal.clamp(powerAmount+amount,0,powerCapacity)
|
||||
meta:set_int("industrialtest.powerAmount",powerAmount)
|
||||
return powerAmount-prevPowerAmount
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user