Move configuration to in-game settings
This commit is contained in:
parent
63960f3de1
commit
9b57098fca
@ -94,7 +94,7 @@ function industrialtest.api.powerFlow(pos,sides,flowOverride)
|
||||
def._industrialtest_self:triggerIfNeeded(endpoint.position)
|
||||
else
|
||||
-- Support for bare definitions that don't use industrialtest pseudo-OOP
|
||||
minetest.get_node_timer(endpoint.position):start(industrialtest.updateDelay)
|
||||
minetest.get_node_timer(endpoint.position):start(industrialtest.config.updateDelay)
|
||||
end
|
||||
if not industrialtest.api.isFullyCharged(endpointMeta) then
|
||||
roomAvailable=true
|
||||
|
@ -316,7 +316,8 @@ override={
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local result=inv:add_item(listname,stack)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
local nodeDef=minetest.registered_nodes[node.name]
|
||||
nodeDef._industrialtest_self:triggerIfNeeded(pos)
|
||||
return result
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
|
10
init.lua
10
init.lua
@ -19,9 +19,11 @@ local modpath=minetest.get_modpath("industrialtest")
|
||||
-- table with global functions, variables etc
|
||||
industrialtest={}
|
||||
|
||||
-- Initial constants
|
||||
industrialtest.updateDelay=1 -- Note: Make this value smaller to make machines update more frequently (it may make server more laggy)
|
||||
industrialtest.developerMode=true -- Enables additional utils useful when developing mod
|
||||
-- Settings
|
||||
industrialtest.config={
|
||||
updateDelay=minetest.settings:get("industrialtest.updateDelay") or 1,
|
||||
developerMode=minetest.settings:get_bool("industrialtest.developerMode",false)
|
||||
}
|
||||
|
||||
-- Others
|
||||
industrialtest.random=PseudoRandom(os.time())
|
||||
@ -92,7 +94,7 @@ dofile(modpath.."/tools/wrench.lua")
|
||||
dofile(modpath.."/upgrades.lua")
|
||||
dofile(modpath.."/craftitems.lua")
|
||||
dofile(modpath.."/nodes.lua")
|
||||
if industrialtest.developerMode then
|
||||
if industrialtest.config.developerMode then
|
||||
dofile(modpath.."/utils.lua")
|
||||
end
|
||||
dofile(modpath.."/cables.lua")
|
||||
|
@ -66,7 +66,7 @@ function industrialtest.ActivatedMachine.activate(self,pos)
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
self:afterActivation(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
minetest.get_node_timer(pos):start(industrialtest.config.updateDelay)
|
||||
end
|
||||
|
||||
function industrialtest.ActivatedMachine.deactivate(self,pos)
|
||||
@ -75,7 +75,7 @@ function industrialtest.ActivatedMachine.deactivate(self,pos)
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
self:afterDeactivation(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
minetest.get_node_timer(pos):start(industrialtest.config.updateDelay)
|
||||
end
|
||||
|
||||
function industrialtest.ActivatedMachine.shouldActivate(self,pos)
|
||||
|
@ -140,7 +140,7 @@ function industrialtest.CanningMachine.allowMetadataInventoryTake(self,pos,listn
|
||||
local targetSlot=inv:get_stack("dst",1)
|
||||
if ((listname=="src" and stack:get_count()==fuelSlot:get_count()) or (listname=="dst" and stack:get_count()==targetSlot:get_count())) and meta:get_float("srcTime")>0 then
|
||||
meta:set_float("srcTime",0)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
self:updateFormspec(pos)
|
||||
end
|
||||
return industrialtest.ActivatedElectricMachine.allowMetadataInventoryTake(self,pos,listname,index,stack,player)
|
||||
end
|
||||
@ -153,12 +153,12 @@ function industrialtest.CanningMachine.onMetadataInventoryMove(self,pos,fromList
|
||||
local targetSlot=inv:get_stack("dst",1)
|
||||
if ((fromList=="src" and count==fuelSlot:get_count()) or (fromList=="dst" and count==targetSlot:get_count())) and meta:get_float("srcTime")>0 then
|
||||
meta:set_float("srcTime",0)
|
||||
meta:set_string("formspec",canningMachine.getFormspec(pos))
|
||||
self:updateFormspec(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function industrialtest.CanningMachine.onMetadataInventoryPut(self,pos,listname,index,stack)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
self:triggerIfNeeded(pos)
|
||||
industrialtest.ActivatedElectricMachine.onMetadataInventoryPut(self,pos,listname,index,stack)
|
||||
end
|
||||
|
||||
|
@ -291,7 +291,7 @@ industrialtest.MFSUChargepad:register()
|
||||
minetest.register_abm({
|
||||
label="Chargepad updating",
|
||||
nodenames=industrialtest.internal.chargepads,
|
||||
interval=industrialtest.updateDelay,
|
||||
interval=industrialtest.config.updateDelay,
|
||||
chance=1,
|
||||
action=function(pos,node)
|
||||
local def=minetest.registered_nodes[node.name]
|
||||
|
@ -32,7 +32,7 @@ function industrialtest.ElectricMachine.onConstruct(self,pos)
|
||||
def._industrialtest_self:flowPower(conn)
|
||||
else
|
||||
-- Support for bare definitions that don't use industrialtest pseudo-OOP
|
||||
minetest.get_node_timer(conn):start(industrialtest.updateDelay)
|
||||
minetest.get_node_timer(conn):start(industrialtest.config.updateDelay)
|
||||
end
|
||||
else
|
||||
local def=minetest.registered_nodes[minetest.get_node(conn).name]
|
||||
@ -46,7 +46,7 @@ function industrialtest.ElectricMachine.onConstruct(self,pos)
|
||||
def._industrialtest_self:flowPower(network)
|
||||
else
|
||||
-- Support for bare definitions that don't use industrialtest pseudo-OOP
|
||||
minetest.get_node_timer(network):start(industrialtest.updateDelay)
|
||||
minetest.get_node_timer(network):start(industrialtest.config.updateDelay)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -177,7 +177,7 @@ function industrialtest.ElectricMachine.requestPower(self,pos)
|
||||
def._industrialtest_self:flowPower(network)
|
||||
else
|
||||
-- Support for bare definitions that don't use industrialtest pseudo-OOP
|
||||
minetest.get_node_timer(network):start(industrialtest.updateDelay)
|
||||
minetest.get_node_timer(network):start(industrialtest.config.updateDelay)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -366,7 +366,7 @@ minetest.register_abm({
|
||||
label="Water Mill generating",
|
||||
nodenames={"industrialtest:water_mill"},
|
||||
neighbors=neighbors,
|
||||
interval=industrialtest.updateDelay,
|
||||
interval=industrialtest.config.updateDelay,
|
||||
chance=1,
|
||||
action=function(pos)
|
||||
industrialtest.WaterMill:action(pos)
|
||||
|
@ -19,7 +19,7 @@ industrialtest.Generator=table.copy(industrialtest.ActivatedElectricMachine)
|
||||
industrialtest.internal.unpackTableInto(industrialtest.Generator,{
|
||||
name="industrialtest:generator",
|
||||
description=S("Generator"),
|
||||
tiles={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
@ -85,7 +85,7 @@ function industrialtest.Generator.getFormspec(self,pos)
|
||||
end
|
||||
|
||||
function industrialtest.Generator.onMetadataInventoryPut(self,pos,listname,index,stack)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
self:triggerIfNeeded(pos)
|
||||
industrialtest.ActivatedElectricMachine.onMetadataInventoryPut(self,pos,listname,index,stack)
|
||||
end
|
||||
|
||||
|
@ -131,7 +131,7 @@ function industrialtest.IronFurnace.allowMetadataInventoryTake(self,pos,listname
|
||||
self:updateFormspec(pos)
|
||||
end
|
||||
elseif listname=="dst" and dstSlot:get_free_space()==0 then
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
self:triggerIfNeeded(pos)
|
||||
end
|
||||
return industrialtest.ActivatedMachine.allowMetadataInventoryTake(self,pos,listname,index,stack)
|
||||
end
|
||||
@ -148,13 +148,13 @@ function industrialtest.IronFurnace.onMetadataInventoryMove(self,pos,fromList,fr
|
||||
self:updateFormspec(pos)
|
||||
end
|
||||
elseif fromList=="dst" and dstSlot:get_free_space()==0 then
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
self:triggerIfNeeded(pos)
|
||||
end
|
||||
industrialtest.ActivatedMachine.onMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count)
|
||||
end
|
||||
|
||||
function industrialtest.IronFurnace.onMetadataInventoryPut(self,pos,listname,index,stack)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
self:triggerIfNeeded(pos)
|
||||
industrialtest.ActivatedMachine.onMetadataInventoryPut(self,pos,listname,index,stack)
|
||||
end
|
||||
|
||||
|
@ -73,7 +73,7 @@ end
|
||||
function industrialtest.Machine.trigger(self,pos)
|
||||
local timer=minetest.get_node_timer(pos)
|
||||
if not timer:is_started() then
|
||||
timer:start(industrialtest.updateDelay)
|
||||
timer:start(industrialtest.config.updateDelay)
|
||||
end
|
||||
end
|
||||
|
||||
@ -259,7 +259,7 @@ function industrialtest.Machine.createDefinitionTable(self)
|
||||
return inv, "src", mcl_util.select_stack(hop_inv, hop_list, inv, "src")
|
||||
end
|
||||
def._mcl_hoppers_on_after_push=function(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
self:triggerIfNeeded(pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -193,7 +193,7 @@ minetest.register_craft({
|
||||
minetest.register_abm({
|
||||
name="Solar panel updating",
|
||||
nodenames=solarPanels,
|
||||
interval=industrialtest.updateDelay,
|
||||
interval=industrialtest.config.updateDelay,
|
||||
chance=1,
|
||||
action=function(pos,node)
|
||||
local def=minetest.registered_nodes[node.name]
|
||||
|
@ -122,7 +122,7 @@ minetest.register_craft({
|
||||
minetest.register_abm({
|
||||
name="Wind mill updating",
|
||||
nodenames={"industrialtest:wind_mill"},
|
||||
interval=industrialtest.updateDelay,
|
||||
interval=industrialtest.config.updateDelay,
|
||||
chance=1,
|
||||
action=function(pos)
|
||||
industrialtest.WindMill:action(pos)
|
||||
|
5
settingtypes.txt
Normal file
5
settingtypes.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# This determines value how frequently machines update
|
||||
industrialtest.updateDelay (Update delay) float 1.0
|
||||
|
||||
# Enables additional utils useful when developing mod
|
||||
industrialtest.developerMode (Developer mode) bool false
|
@ -23,7 +23,7 @@ industrialtest.internal.unpackTableInto(industrialtest.BatPackBase,{
|
||||
local updateDelta=0
|
||||
function industrialtest.BatPackBase.update(self,player,inv,itemstack,dtime)
|
||||
updateDelta=updateDelta+dtime
|
||||
if updateDelta<industrialtest.updateDelay then
|
||||
if updateDelta<industrialtest.config.updateDelay then
|
||||
return false
|
||||
end
|
||||
updateDelta=0
|
||||
|
@ -45,7 +45,7 @@ industrialtest.internal.unpackTableInto(industrialtest.QuantumHelmet,{
|
||||
local quantumHelmetUpdateDelta=0
|
||||
function industrialtest.QuantumHelmet.update(self,player,inv,itemstack,dtime)
|
||||
quantumHelmetUpdateDelta=quantumHelmetUpdateDelta+dtime
|
||||
if quantumHelmetUpdateDelta<industrialtest.updateDelay then
|
||||
if quantumHelmetUpdateDelta<industrialtest.config.updateDelay then
|
||||
return false
|
||||
end
|
||||
quantumHelmetUpdateDelta=0
|
||||
|
@ -27,7 +27,7 @@ industrialtest.internal.unpackTableInto(industrialtest.SolarHelmet,{
|
||||
local updateDelta=0
|
||||
function industrialtest.SolarHelmet.update(self,player,inv,itemstack,dtime)
|
||||
updateDelta=updateDelta+dtime
|
||||
if updateDelta<industrialtest.updateDelay then
|
||||
if updateDelta<industrialtest.config.updateDelay then
|
||||
return false
|
||||
end
|
||||
updateDelta=0
|
||||
|
Loading…
x
Reference in New Issue
Block a user