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:
Oversword 2021-03-10 22:45:47 +00:00
parent 7b29a553df
commit 71504969e7
4 changed files with 35 additions and 4 deletions

@ -84,6 +84,7 @@ function NodeStates:new(attr)
local o = {
-- mandatory
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
has_item_meter = attr.has_item_meter, -- true/false
-- optional
@ -175,9 +176,27 @@ function NodeStates:start(pos, meta, called_from_on_timer)
if self.formspec_func then
meta:set_string("formspec", self.formspec_func(self, pos, meta))
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
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
end

@ -39,6 +39,7 @@ local M = minetest.get_meta
local STANDBY_TICKS = 5
local COUNTDOWN_TICKS = 5
local CYCLE_TIME = 2
local FIRST_CYCLE = 0.5
local State = tubelib.NodeStates:new({
node_name_passive = "tubelib:pusher",
@ -46,6 +47,7 @@ local State = tubelib.NodeStates:new({
node_name_defect = "tubelib:pusher_defect",
infotext_name = S("Tubelib Pusher"),
cycle_time = CYCLE_TIME,
first_cycle_time = FIRST_CYCLE,
standby_ticks = STANDBY_TICKS,
has_item_meter = true,
aging_factor = 10,
@ -61,7 +63,9 @@ local function pushing(pos, meta)
State:blocked(pos, meta)
return
end
if State.get_state(pos, meta) ~= tubelib.STOPPED then
State:keep_running(pos, meta, COUNTDOWN_TICKS)
end
return
end
State:idle(pos, meta)

@ -39,6 +39,7 @@ local M = minetest.get_meta
local STANDBY_TICKS = 5
local COUNTDOWN_TICKS = 5
local CYCLE_TIME = 1
local FIRST_CYCLE = 0.5
local State = tubelib.NodeStates:new({
node_name_passive = "tubelib_addons1:pusher_fast",
@ -46,6 +47,7 @@ local State = tubelib.NodeStates:new({
node_name_defect = "tubelib_addons1:pusher_fast_defect",
infotext_name = S("Fast Pusher"),
cycle_time = CYCLE_TIME,
first_cycle_time = FIRST_CYCLE,
standby_ticks = STANDBY_TICKS,
has_item_meter = true,
aging_factor = 30,
@ -61,7 +63,9 @@ local function pushing(pos, meta)
State:blocked(pos, meta)
return
end
if State.get_state(pos, meta) ~= tubelib.STOPPED then
State:keep_running(pos, meta, COUNTDOWN_TICKS)
end
return
end
State:idle(pos, meta)

@ -24,6 +24,7 @@ local M = minetest.get_meta
local STANDBY_TICKS = 5
local COUNTDOWN_TICKS = 5
local CYCLE_TIME = 2
local FIRST_CYCLE = 0.5
local State = tubelib.NodeStates:new({
node_name_passive = "tubelib_addons3:pusher",
@ -31,6 +32,7 @@ local State = tubelib.NodeStates:new({
node_name_defect = "tubelib_addons3:pusher_defect",
infotext_name = S("HighPerf Pusher"),
cycle_time = CYCLE_TIME,
first_cycle_time = FIRST_CYCLE,
standby_ticks = STANDBY_TICKS,
has_item_meter = true,
aging_factor = 50,
@ -46,7 +48,9 @@ local function pushing(pos, meta)
State:blocked(pos, meta)
return
end
if State.get_state(pos, meta) ~= tubelib.STOPPED then
State:keep_running(pos, meta, COUNTDOWN_TICKS, 1)
end
return
end
State:idle(pos, meta)