From 71504969e7f4ce6fcbb6aca7c235f7a1a0287915 Mon Sep 17 00:00:00 2001 From: Oversword Date: Wed, 10 Mar 2021 22:45:47 +0000 Subject: [PATCH] Make sure pushers to not keep running if they have been stopped; Allow tubelib machines to have a 'first_cycle' time for first run --- tubelib/node_states.lua | 21 ++++++++++++++++++++- tubelib/pusher.lua | 6 +++++- tubelib_addons1/pusher_fast.lua | 6 +++++- tubelib_addons3/pusher.lua | 6 +++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/tubelib/node_states.lua b/tubelib/node_states.lua index 14b58d8..2a3b445 100644 --- a/tubelib/node_states.lua +++ b/tubelib/node_states.lua @@ -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 diff --git a/tubelib/pusher.lua b/tubelib/pusher.lua index c39f287..fb26b79 100644 --- a/tubelib/pusher.lua +++ b/tubelib/pusher.lua @@ -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 - State:keep_running(pos, meta, COUNTDOWN_TICKS) + if State.get_state(pos, meta) ~= tubelib.STOPPED then + State:keep_running(pos, meta, COUNTDOWN_TICKS) + end return end State:idle(pos, meta) diff --git a/tubelib_addons1/pusher_fast.lua b/tubelib_addons1/pusher_fast.lua index bfcf2bb..c379444 100644 --- a/tubelib_addons1/pusher_fast.lua +++ b/tubelib_addons1/pusher_fast.lua @@ -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 - State:keep_running(pos, meta, COUNTDOWN_TICKS) + if State.get_state(pos, meta) ~= tubelib.STOPPED then + State:keep_running(pos, meta, COUNTDOWN_TICKS) + end return end State:idle(pos, meta) diff --git a/tubelib_addons3/pusher.lua b/tubelib_addons3/pusher.lua index f6e2fbc..bb6e9b1 100644 --- a/tubelib_addons3/pusher.lua +++ b/tubelib_addons3/pusher.lua @@ -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 - State:keep_running(pos, meta, COUNTDOWN_TICKS, 1) + if State.get_state(pos, meta) ~= tubelib.STOPPED then + State:keep_running(pos, meta, COUNTDOWN_TICKS, 1) + end return end State:idle(pos, meta)