mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 23:33:44 +01:00
Make sure pushers to not keep running if they have been stopped; Allow tubelib machines to have a 'first_cycle' time for first run
This commit is contained in:
parent
7b29a553df
commit
71504969e7
@ -84,6 +84,7 @@ function NodeStates:new(attr)
|
|||||||
local o = {
|
local o = {
|
||||||
-- mandatory
|
-- mandatory
|
||||||
cycle_time = attr.cycle_time, -- for running state
|
cycle_time = attr.cycle_time, -- for running state
|
||||||
|
first_cycle_time = attr.first_cycle_time, -- for first run, not required
|
||||||
standby_ticks = attr.standby_ticks, -- for standby state
|
standby_ticks = attr.standby_ticks, -- for standby state
|
||||||
has_item_meter = attr.has_item_meter, -- true/false
|
has_item_meter = attr.has_item_meter, -- true/false
|
||||||
-- optional
|
-- optional
|
||||||
@ -175,9 +176,27 @@ function NodeStates:start(pos, meta, called_from_on_timer)
|
|||||||
if self.formspec_func then
|
if self.formspec_func then
|
||||||
meta:set_string("formspec", self.formspec_func(self, pos, meta))
|
meta:set_string("formspec", self.formspec_func(self, pos, meta))
|
||||||
end
|
end
|
||||||
minetest.get_node_timer(pos):start(self.cycle_time)
|
local cycle_time = self.cycle_time
|
||||||
|
if self.first_cycle_time then
|
||||||
|
if meta:get_int("tubelib_first_run") == 1 then
|
||||||
|
meta:set_int("tubelib_first_run", 0)
|
||||||
|
cycle_time = self.cycle_time
|
||||||
|
else
|
||||||
|
meta:set_int("tubelib_first_run", 1)
|
||||||
|
cycle_time = self.first_cycle_time
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.get_node_timer(pos):start(cycle_time)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
if self.first_cycle_time and meta:get_int("tubelib_first_run") == 1 then
|
||||||
|
local cycle_time = self.cycle_time
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
minetest.after(0, function ()
|
||||||
|
timer:set(cycle_time, timer:get_elapsed())
|
||||||
|
end)
|
||||||
|
meta:set_int("tubelib_first_run", 0)
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ local M = minetest.get_meta
|
|||||||
local STANDBY_TICKS = 5
|
local STANDBY_TICKS = 5
|
||||||
local COUNTDOWN_TICKS = 5
|
local COUNTDOWN_TICKS = 5
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
|
local FIRST_CYCLE = 0.5
|
||||||
|
|
||||||
local State = tubelib.NodeStates:new({
|
local State = tubelib.NodeStates:new({
|
||||||
node_name_passive = "tubelib:pusher",
|
node_name_passive = "tubelib:pusher",
|
||||||
@ -46,6 +47,7 @@ local State = tubelib.NodeStates:new({
|
|||||||
node_name_defect = "tubelib:pusher_defect",
|
node_name_defect = "tubelib:pusher_defect",
|
||||||
infotext_name = S("Tubelib Pusher"),
|
infotext_name = S("Tubelib Pusher"),
|
||||||
cycle_time = CYCLE_TIME,
|
cycle_time = CYCLE_TIME,
|
||||||
|
first_cycle_time = FIRST_CYCLE,
|
||||||
standby_ticks = STANDBY_TICKS,
|
standby_ticks = STANDBY_TICKS,
|
||||||
has_item_meter = true,
|
has_item_meter = true,
|
||||||
aging_factor = 10,
|
aging_factor = 10,
|
||||||
@ -61,7 +63,9 @@ local function pushing(pos, meta)
|
|||||||
State:blocked(pos, meta)
|
State:blocked(pos, meta)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if State.get_state(pos, meta) ~= tubelib.STOPPED then
|
||||||
State:keep_running(pos, meta, COUNTDOWN_TICKS)
|
State:keep_running(pos, meta, COUNTDOWN_TICKS)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
State:idle(pos, meta)
|
State:idle(pos, meta)
|
||||||
|
@ -39,6 +39,7 @@ local M = minetest.get_meta
|
|||||||
local STANDBY_TICKS = 5
|
local STANDBY_TICKS = 5
|
||||||
local COUNTDOWN_TICKS = 5
|
local COUNTDOWN_TICKS = 5
|
||||||
local CYCLE_TIME = 1
|
local CYCLE_TIME = 1
|
||||||
|
local FIRST_CYCLE = 0.5
|
||||||
|
|
||||||
local State = tubelib.NodeStates:new({
|
local State = tubelib.NodeStates:new({
|
||||||
node_name_passive = "tubelib_addons1:pusher_fast",
|
node_name_passive = "tubelib_addons1:pusher_fast",
|
||||||
@ -46,6 +47,7 @@ local State = tubelib.NodeStates:new({
|
|||||||
node_name_defect = "tubelib_addons1:pusher_fast_defect",
|
node_name_defect = "tubelib_addons1:pusher_fast_defect",
|
||||||
infotext_name = S("Fast Pusher"),
|
infotext_name = S("Fast Pusher"),
|
||||||
cycle_time = CYCLE_TIME,
|
cycle_time = CYCLE_TIME,
|
||||||
|
first_cycle_time = FIRST_CYCLE,
|
||||||
standby_ticks = STANDBY_TICKS,
|
standby_ticks = STANDBY_TICKS,
|
||||||
has_item_meter = true,
|
has_item_meter = true,
|
||||||
aging_factor = 30,
|
aging_factor = 30,
|
||||||
@ -61,7 +63,9 @@ local function pushing(pos, meta)
|
|||||||
State:blocked(pos, meta)
|
State:blocked(pos, meta)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if State.get_state(pos, meta) ~= tubelib.STOPPED then
|
||||||
State:keep_running(pos, meta, COUNTDOWN_TICKS)
|
State:keep_running(pos, meta, COUNTDOWN_TICKS)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
State:idle(pos, meta)
|
State:idle(pos, meta)
|
||||||
|
@ -24,6 +24,7 @@ local M = minetest.get_meta
|
|||||||
local STANDBY_TICKS = 5
|
local STANDBY_TICKS = 5
|
||||||
local COUNTDOWN_TICKS = 5
|
local COUNTDOWN_TICKS = 5
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
|
local FIRST_CYCLE = 0.5
|
||||||
|
|
||||||
local State = tubelib.NodeStates:new({
|
local State = tubelib.NodeStates:new({
|
||||||
node_name_passive = "tubelib_addons3:pusher",
|
node_name_passive = "tubelib_addons3:pusher",
|
||||||
@ -31,6 +32,7 @@ local State = tubelib.NodeStates:new({
|
|||||||
node_name_defect = "tubelib_addons3:pusher_defect",
|
node_name_defect = "tubelib_addons3:pusher_defect",
|
||||||
infotext_name = S("HighPerf Pusher"),
|
infotext_name = S("HighPerf Pusher"),
|
||||||
cycle_time = CYCLE_TIME,
|
cycle_time = CYCLE_TIME,
|
||||||
|
first_cycle_time = FIRST_CYCLE,
|
||||||
standby_ticks = STANDBY_TICKS,
|
standby_ticks = STANDBY_TICKS,
|
||||||
has_item_meter = true,
|
has_item_meter = true,
|
||||||
aging_factor = 50,
|
aging_factor = 50,
|
||||||
@ -46,7 +48,9 @@ local function pushing(pos, meta)
|
|||||||
State:blocked(pos, meta)
|
State:blocked(pos, meta)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if State.get_state(pos, meta) ~= tubelib.STOPPED then
|
||||||
State:keep_running(pos, meta, COUNTDOWN_TICKS, 1)
|
State:keep_running(pos, meta, COUNTDOWN_TICKS, 1)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
State:idle(pos, meta)
|
State:idle(pos, meta)
|
||||||
|
Loading…
Reference in New Issue
Block a user