forked from mrkubax10/industrialtest
Move common machine functions outside of register function
This commit is contained in:
parent
7a6dacb614
commit
edc70ad028
@ -14,6 +14,7 @@
|
||||
-- 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 machine={}
|
||||
local simpleElectricItemProcessor={}
|
||||
|
||||
function industrialtest.internal.mclAfterDigNode(pos,oldmeta,lists)
|
||||
@ -32,8 +33,7 @@ function industrialtest.internal.mclAfterDigNode(pos,oldmeta,lists)
|
||||
meta:from_table(meta2:to_table())
|
||||
end
|
||||
|
||||
function industrialtest.internal.registerMachine(config)
|
||||
local function getFormspec(pos)
|
||||
machine.getFormspec=function(pos,config)
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
@ -56,20 +56,20 @@ function industrialtest.internal.registerMachine(config)
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
local definition={
|
||||
description=config.displayName,
|
||||
on_construct=function(pos)
|
||||
end
|
||||
|
||||
machine.onConstruct=function(pos,config)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
meta:set_string("formspec",machine.getFormspec(pos,config))
|
||||
if config.onConstruct then
|
||||
config.onConstruct(pos,meta,inv)
|
||||
end
|
||||
industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,config.ioConfig)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end,
|
||||
on_timer=function(pos,elapsed)
|
||||
end
|
||||
|
||||
machine.onTimer=function(pos,elapsed,config)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local shouldRerunTimer=false
|
||||
@ -80,12 +80,13 @@ function industrialtest.internal.registerMachine(config)
|
||||
end
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
meta:set_string("formspec",machine.getFormspec(pos,config))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
end,
|
||||
allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
end
|
||||
|
||||
machine.allowMetadataInventoryMove=function(pos,fromList,fromIndex,toList,toIndex,count,config)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local movedItemStack=inv:get_stack(fromList,1)
|
||||
@ -105,8 +106,9 @@ function industrialtest.internal.registerMachine(config)
|
||||
return config.allowMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||
end
|
||||
|
||||
machine.allowMetadataInventoryPut=function(pos,listname,index,stack,player,config)
|
||||
local found=false
|
||||
if config.powerSlots then
|
||||
for _,value in ipairs(config.powerSlots) do
|
||||
@ -123,6 +125,27 @@ function industrialtest.internal.registerMachine(config)
|
||||
return config.allowMetadataInventoryPut(pos,listname,index,stack,player)
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
machine.updateFormspec=function(pos,config)
|
||||
local meta=minetest.get_meta(pos)
|
||||
meta:set_string("formspec",machine.getFormspec(pos,config))
|
||||
end
|
||||
|
||||
function industrialtest.internal.registerMachine(config)
|
||||
local definition={
|
||||
description=config.displayName,
|
||||
on_construct=function(pos)
|
||||
machine.onConstruct(pos,config)
|
||||
end,
|
||||
on_timer=function(pos,elapsed)
|
||||
return machine.onTimer(pos,elapsed,config)
|
||||
end,
|
||||
allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
return machine.allowMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count,config)
|
||||
end,
|
||||
allow_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||
return machine.allowMetadataInventoryPut(pos,listname,index,stack,player,config)
|
||||
end,
|
||||
on_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||
if config.onMetadataInventoryPut then
|
||||
@ -140,8 +163,7 @@ function industrialtest.internal.registerMachine(config)
|
||||
end
|
||||
end,
|
||||
_industrialtest_updateFormspec=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
machine.updateFormspec(pos,config)
|
||||
end
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
@ -199,7 +221,7 @@ function industrialtest.internal.registerMachine(config)
|
||||
end
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
meta:set_string("formspec",machine.getFormspec(pos,config))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
@ -426,7 +448,7 @@ simpleElectricItemProcessor.onMetadataInventoryMove=function(pos,fromList,fromIn
|
||||
meta:set_float("srcTime",-1)
|
||||
meta:set_float("maxSrcTime",0)
|
||||
if meta:get_int("industrialtest.powerAmount")>0 then
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
meta:set_string("formspec",simpleElectricItemProcessor.getFormspec(pos))
|
||||
end
|
||||
elseif fromList=="dst" and dstSlot:get_free_space()==0 then
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
@ -442,7 +464,7 @@ simpleElectricItemProcessor.onMetadataInventoryTake=function(pos,listname,index,
|
||||
meta:set_float("srcTime",-1)
|
||||
meta:set_float("maxSrcTime",0)
|
||||
if meta:get_int("industrialtest.powerAmount")>0 then
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
meta:set_string("formspec",simpleElectricItemProcessor.getFormspec(pos))
|
||||
end
|
||||
elseif listname=="dst" and dstSlot:get_free_space()==0 then
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
@ -512,7 +534,7 @@ function industrialtest.internal.registerSimpleElectricItemProcessor(config)
|
||||
name=config.name,
|
||||
displayName=config.displayName,
|
||||
capacity=config.capacity,
|
||||
getFormspec=getFormspec,
|
||||
getFormspec=simpleElectricItemProcessor.getFormspec,
|
||||
flow=config.flow,
|
||||
ioConfig="iiiiii",
|
||||
requiresWrench=config.requiresWrench,
|
||||
|
Loading…
Reference in New Issue
Block a user