Improve injector and detector

This commit is contained in:
Joachim Stolberg 2021-09-27 21:34:24 +02:00
parent d2002ce2cd
commit 801d2f5492
6 changed files with 32 additions and 9 deletions

View File

@ -152,6 +152,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
formspec_func = tNode.formspec,
on_state_change = tNode.on_state_change,
can_start = tNode.can_start,
quick_start = tNode.quick_start,
has_power = tNode.has_power or power_used and has_power or nil,
start_node = power_used and start_node or nil,
stop_node = power_used and stop_node or nil,

View File

@ -175,7 +175,7 @@ local function pushing(pos, crd, meta, nvm)
end
end
local function keep_running(pos, elapsed)
local function node_timer(pos, elapsed)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
pushing(pos, crd, M(pos), nvm)
@ -253,6 +253,7 @@ local _, node_name_ta3, node_name_ta4 =
standby_ticks = STANDBY_TICKS,
formspec = formspec,
tubing = tubing,
quick_start = node_timer,
after_place_node = function(pos, placer)
local meta = M(pos)
local node = minetest.get_node(pos)
@ -268,7 +269,7 @@ local _, node_name_ta3, node_name_ta4 =
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = function() return 0 end,
on_receive_fields = on_receive_fields,
node_timer = keep_running,
node_timer = node_timer,
on_rotate = screwdriver.disallow,
groups = {choppy=2, cracky=2, crumbly=2},

View File

@ -183,6 +183,7 @@ function NodeStates:new(attr)
stop_node = attr.stop_node,
formspec_func = attr.formspec_func,
on_state_change = attr.on_state_change,
quick_start = attr.quick_start,
}
setmetatable(o, self)
self.__index = self
@ -272,6 +273,12 @@ function NodeStates:start(pos, nvm)
self.on_state_change(pos, state, RUNNING)
end
start_timer_delayed(pos, self.cycle_time)
print("start", self.quick_start)
if self.quick_start then
print("quick_start")
self.quick_start(pos, 0)
end
return true
end
return false

View File

@ -228,9 +228,11 @@ TA2 Cylinder=TA2 Zylinder
Configured Items=Konfigurierte Gegenstände
Items which generate an 'on' command.@nIf empty, all passed items generate an 'on' command.=Items, die einen 'on'-Kommando generieren.@nWenn leer, generieren alle übergebenen Items einen 'on'-Befehl.
On Time=ON Zeit
TA3 Detector=TA3 Detektor
TA4 Detector=TA4 Detektor
Waiting time between two 'on' commands=Wartezeit zwischen zwei 'on'-Kommandos
The time after the 'off' command@nuntil the next 'on' command is accepted.=Die Zeit nach dem 'off' Kommando,@nbis das nächste 'on' Kommando akzeptiert wird.
The time between the 'on' and 'off' commands.=Die Zeit zwischen den 'on' und 'off' Kommandos.
### detector.lua ###
### logic_block.lua ###
@ -1159,5 +1161,3 @@ is a suitable place for a wind turbine!=ist ein geeigneter Ort für eine Windkra
##### not used anymore #####
Maximum command transmission frequency=Maximale Sendefrequenz für Kommandos

View File

@ -228,9 +228,11 @@ TA2 Cylinder=
Configured Items=
Items which generate an 'on' command.@nIf empty, all passed items generate an 'on' command.=
On Time=
TA3 Detector=
TA4 Detector=
Waiting time between two 'on' commands=
The time after the 'off' command@nuntil the next 'on' command is accepted.=
The time between the 'on' and 'off' commands.=
### detector.lua ###
### logic_block.lua ###

View File

@ -19,14 +19,23 @@ local NDEF = function(pos) return (minetest.registered_nodes[techage.get_node_lv
local logic = techage.logic
local BLOCKING_TIME = 8 -- seconds
local ON_TIME = 1
local WRENCH_MENU = {
{
type = "dropdown",
choices = "1,2,4,6,8,12,16",
name = "ontime",
label = S("On Time") .. " [s]",
tooltip = S("The time between the 'on' and 'off' commands."),
default = "1",
},
{
type = "dropdown",
choices = "2,4,6,8,12,16,20",
name = "blockingtime",
label = S("Blocking Time") .. " [s]",
tooltip = S("Waiting time between two 'on' commands"),
tooltip = S("The time after the 'off' command\nuntil the next 'on' command is accepted."),
default = "8",
},
{
@ -48,8 +57,11 @@ local function switch_on(pos)
else
logic.swap_node(pos, "techage:ta4_detector_on")
end
logic.send_on(pos, M(pos), 1)
mem.time = t + (tonumber(M(pos):get_string("blockingtime")) or BLOCKING_TIME)
local meta = M(pos)
local on_time = math.max(meta:get_int("ontime"), ON_TIME)
local blocking_time = tonumber(meta:get_string("blockingtime")) or BLOCKING_TIME
logic.send_on(pos, meta, on_time)
mem.time = t + blocking_time + on_time
end
end