Improve detector, fix filler bug

This commit is contained in:
Joachim Stolberg 2021-09-19 20:02:24 +02:00
parent 1e36775c18
commit 9218c3097b
11 changed files with 142 additions and 39 deletions

View File

@ -1126,6 +1126,7 @@ techage.manual_DE.aText = {
"Der Detektor ist eine spezieller Röhrenblock\\, der erkennt\\, wenn Items über die Röhre weitergegeben werden. Es muss dazu auf beiden Seiten mit der Röhre verbunden sein. Werden Items mit einem Schieber in den Detektor geschoben\\, gibt er diese automatisch weiter.\n"..
"Er sendet ein 'on'\\, wenn ein Item erkannt wird\\, gefolgt von einem 'off' eine Sekunde später.\n"..
"Danach werden weitere Kommando für 8 Sekunden blockiert.\n"..
"Die Wartezeit\\, sowie die Items\\, die ein Kommando auslösen sollen\\, können über das Gabelschlüssel-Menü konfiguriert werden.\n"..
"\n"..
"\n"..
"\n",

View File

@ -1125,6 +1125,7 @@ techage.manual_EN.aText = {
"The detector is a special tube block that detects when items are passed on through the tube. To do this\\, it must be connected to tubes on both sides. If items are pushed into the detector with a pusher\\, they are automatically passed on.\n"..
"It sends an 'on' when an item is recognized\\, followed by an 'off' a second later.\n"..
"Then further commands are blocked for 8 seconds.\n"..
"The waiting time and the items that should trigger a command can be configured using the open-ended wrench menu. \n"..
"\n"..
"\n"..
"\n",
@ -1200,7 +1201,7 @@ techage.manual_EN.aText = {
"\n"..
"\n",
"",
"The Techage Info Tool (wrench) has several functions. It shows the time\\, position\\, temperature and biome when an unknown block is clicked on.\n"..
"The Techage Info Tool (open-ended wrench) has several functions. It shows the time\\, position\\, temperature and biome when an unknown block is clicked on.\n"..
"If you click on a TechAge block with command interface\\, all available data will be shown (see also \"Logic / switching blocks\").\n"..
"\n"..
"With Shift + right click an extended menu can be opened for some blocks. Depending on the block\\, further data can be called up or special settings can be made here. In the case of a generator\\, for example\\, the charging curve/switch-off can be programmed. \n"..

View File

@ -74,12 +74,12 @@ local function node_timer(pos, elapsed)
if not inv:is_empty("src") then
local taken = techage.get_items(pos, inv, "src", 1)
if liquid.is_container_empty(taken:get_name()) then
return liquid.fill_container({x = pos.x, y = pos.y+1, z = pos.z}, inv, taken:get_name())
liquid.fill_container({x = pos.x, y = pos.y+1, z = pos.z}, inv, taken:get_name())
else
return liquid.empty_container({x = pos.x, y = pos.y-1, z = pos.z}, inv, taken:get_name())
liquid.empty_container({x = pos.x, y = pos.y-1, z = pos.z}, inv, taken:get_name())
end
end
return false
return true
end
minetest.register_node("techage:filler", {
@ -124,7 +124,7 @@ minetest.register_node("techage:filler", {
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
use_texture_alpha = techage.CLIP,
use_texture_alpha = techage.CLIP,
is_ground_content = false,
groups = {cracky=2, crumbly=2, choppy=2},
sounds = default.node_sound_defaults(),

View File

@ -210,8 +210,16 @@ TA2 Cylinder=TA2 Zylinder
### detector.lua ###
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.
TA3 Detector=TA3 Detektor
TA4 Detector=TA4 Detektor
Waiting time between two 'on' commands=Wartezeit zwischen zwei 'on'-Kommandos
### detector.lua ###
### logic_block.lua ###
Blocking Time=Sperrzeit
### display.lua ###
@ -370,6 +378,7 @@ loaded=geladen
### formspecs.lua ###
Block has a wrench menu=Block hat ein Gabelschlüssel-Menü
Charge termination=Ladebegrenzung
Current output [ku]=Aktueller Ausgabewert
Maximum output [ku]=Maximaler Ausgabewert
@ -595,7 +604,8 @@ no usable water=Kein brauchbares Wasser
@nRule:@n<output> @= on/off if <input-expression> is true@n=@nRegel:@n<output> @= on/off if <input-expression> is true@n
@nThe internal processing time for all@ncommands is 100 ms.=@nDie interne Durchlaufzeit für alle@nKommandos beträgt 100 ms.
@nValid operators:@nand or on off me @=@= ~@= ( )@n=@nGültige Operatoren:@nand or on off @=@= ~@= ( )@n
Blocking Time=Sperrzeit
Clear=Löschen
Debug=Debug
Help=Hilfe
Inputs=Eingänge
Outputs=Ausgänge
@ -750,7 +760,7 @@ TA Power Pole Top 2 (for landlines)=TA Strommastkopf 2 (für Überlandleitungen)
### power_terminal2.lua ###
Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@n=Kommandos@nhelp . . . diesen Text ausgeben@ncls . . . . . Bildschirm löschen@ngen . . . . Alle Generatoren ausgeben@nsto . . . . . Alle Speichersysteme ausgeben@n
Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@ncon . . . . . print main consumers@n=Kommandos@nhelp . . . diesen Text ausgeben@ncls . . . . . Bildschirm löschen@ngen . . . . Alle Generatoren ausgeben@nsto . . . . . Alle Speichersysteme ausgeben@ncon . . . . . Hauptverbraucher ausgeben@n
Consumer=Verbraucher
Network Data=Netzwerkdaten
Number of consumers:=Anzahl der Verbraucher
@ -902,7 +912,6 @@ TA Lamp=TA Lampe
TA1 Sluice Gate=TA1 Schleusenschieber
TA1 Sluice Handle=TA1 Schleusengriff
Your pond is too small!=Der Teich ist zu klein!
### solarcell.lua ###
@ -1099,11 +1108,6 @@ Usmium Powder=Usmium Pulver
TA Valve=TA Ventil
TA3 Valve=TA3 Ventil
### water.lua ###
Flowing Water=Fließendes Wasser
Water Source=Wasserquelle
### waterinlet.lua ###
Error: No natural water!=Fehler: Kein natürliches Wasser!
@ -1132,3 +1136,8 @@ This is not the surface of the ocean!=Das ist nicht die Meeresoberfläche!
[TA4 Wind Turbine]=[TA4 Windkraftanlage]
biome and no ocean!=Biom und keine Meer (ocean)!
is a suitable place for a wind turbine!=ist ein geeigneter Ort für eine Windkraftanlage!
##### not used anymore #####
Maximum command transmission frequency=Maximale Sendefrequenz für Kommandos

View File

@ -210,8 +210,16 @@ TA2 Cylinder=
### detector.lua ###
Configured Items=
Items which generate an 'on' command.@nIf empty, all passed items generate an 'on' command.=
TA3 Detector=
TA4 Detector=
Waiting time between two 'on' commands=
### detector.lua ###
### logic_block.lua ###
Blocking Time=
### display.lua ###
@ -370,6 +378,7 @@ loaded=
### formspecs.lua ###
Block has a wrench menu=
Charge termination=
Current output [ku]=
Maximum output [ku]=
@ -595,7 +604,8 @@ no usable water=
@nRule:@n<output> @= on/off if <input-expression> is true@n=
@nThe internal processing time for all@ncommands is 100 ms.=
@nValid operators:@nand or on off me @=@= ~@= ( )@n=
Blocking Time=
Clear=
Debug=
Help=
Inputs=
Outputs=
@ -750,7 +760,7 @@ TA Power Pole Top 2 (for landlines)=
### power_terminal2.lua ###
Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@n=
Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@ncon . . . . . print main consumers@n=
Consumer=
Network Data=
Number of consumers:=
@ -902,7 +912,6 @@ TA Lamp=
TA1 Sluice Gate=
TA1 Sluice Handle=
Your pond is too small!=
### solarcell.lua ###
@ -1099,11 +1108,6 @@ Usmium Powder=
TA Valve=
TA3 Valve=
### water.lua ###
Flowing Water=
Water Source=
### waterinlet.lua ###
Error: No natural water!=

View File

@ -20,6 +20,24 @@ local NDEF = function(pos) return (minetest.registered_nodes[techage.get_node_lv
local logic = techage.logic
local BLOCKING_TIME = 8 -- seconds
local WRENCH_MENU = {
{
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"),
default = "8",
},
{
type = "items",
name = "config",
label = S("Configured Items"),
tooltip = S("Items which generate an 'on' command.\nIf empty, all passed items generate an 'on' command."),
size = 4,
}
}
local function switch_on(pos)
local mem = techage.get_mem(pos)
local t = minetest.get_gametime()
@ -31,7 +49,7 @@ local function switch_on(pos)
logic.swap_node(pos, "techage:ta4_detector_on")
end
logic.send_on(pos, M(pos), 1)
mem.time = t + BLOCKING_TIME
mem.time = t + (tonumber(M(pos):get_string("blockingtime")) or BLOCKING_TIME)
end
end
@ -48,12 +66,15 @@ end
local function formspec(meta)
local numbers = meta:get_string("numbers") or ""
return "size[7.5,3]"..
techage.wrench_image(7, -0.1) ..
"field[0.5,1;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"button_exit[2,2;3,1;exit;"..S("Save").."]"
end
local function after_place_node(pos, placer)
local meta = M(pos)
local inv = meta:get_inventory()
inv:set_size('cfg', 4)
logic.after_place_node(pos, placer, "techage:ta3_detector_off", NDEF(pos).description)
logic.infotext(meta, NDEF(pos).description)
meta:set_string("formspec", formspec(meta))
@ -97,6 +118,7 @@ minetest.register_node("techage:ta3_detector_off", {
on_receive_fields = on_receive_fields,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
ta3_formspec = WRENCH_MENU,
on_rotate = screwdriver.disallow,
paramtype = "light",
@ -124,6 +146,7 @@ minetest.register_node("techage:ta3_detector_on", {
on_rotate = screwdriver.disallow,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
ta3_formspec = WRENCH_MENU,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
@ -148,6 +171,7 @@ minetest.register_node("techage:ta4_detector_off", {
on_receive_fields = on_receive_fields,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
ta3_formspec = WRENCH_MENU,
on_rotate = screwdriver.disallow,
paramtype = "light",
@ -175,6 +199,7 @@ minetest.register_node("techage:ta4_detector_on", {
on_rotate = screwdriver.disallow,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
ta3_formspec = WRENCH_MENU,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
@ -204,7 +229,10 @@ minetest.register_craft({
techage.register_node({"techage:ta3_detector_off", "techage:ta3_detector_on"}, {
on_push_item = function(pos, in_dir, stack)
if techage.safe_push_items(pos, in_dir, stack) then
switch_on(pos)
local inv = minetest.get_inventory({type = "node", pos = pos})
if not inv or inv:is_empty("cfg") or inv:contains_item("cfg", ItemStack(stack:get_name())) then
switch_on(pos)
end
return true
end
return false

View File

@ -695,6 +695,7 @@ Detektoren scannen ihre Umgebung ab und senden ein `on`-Kommando, wenn das Gesuc
Der Detektor ist eine spezieller Röhrenblock, der erkennt, wenn Items über die Röhre weitergegeben werden. Es muss dazu auf beiden Seiten mit der Röhre verbunden sein. Werden Items mit einem Schieber in den Detektor geschoben, gibt er diese automatisch weiter.
Er sendet ein `on`, wenn ein Item erkannt wird, gefolgt von einem `off` eine Sekunde später.
Danach werden weitere Kommando für 8 Sekunden blockiert.
Die Wartezeit, sowie die Items, die ein Kommando auslösen sollen, können über das Gabelschlüssel-Menü konfiguriert werden.
[ta3_detector|image]

View File

@ -690,6 +690,7 @@ Detectors scan their surroundings and send an `on` command when the search is re
The detector is a special tube block that detects when items are passed on through the tube. To do this, it must be connected to tubes on both sides. If items are pushed into the detector with a pusher, they are automatically passed on.
It sends an `on` when an item is recognized, followed by an `off` a second later.
Then further commands are blocked for 8 seconds.
The waiting time and the items that should trigger a command can be configured using the open-ended wrench menu.
[ta3_detector|image]
@ -810,7 +811,7 @@ The processing power is up to 8 times one item every 4 seconds.
### Techage Info Tool
The Techage Info Tool (wrench) has several functions. It shows the time, position, temperature and biome when an unknown block is clicked on.
The Techage Info Tool (open-ended wrench) has several functions. It shows the time, position, temperature and biome when an unknown block is clicked on.
If you click on a TechAge block with command interface, all available data will be shown (see also "Logic / switching blocks").
With Shift + right click an extended menu can be opened for some blocks. Depending on the block, further data can be called up or special settings can be made here. In the case of a generator, for example, the charging curve/switch-off can be programmed.

View File

@ -165,6 +165,11 @@ end
-------------------------------------------------------------------------------
-- API formspec functions
-------------------------------------------------------------------------------
function techage.wrench_image(x, y)
return "image["..x.."," .. y .. ";0.5,0.5;techage_inv_wrench.png]" ..
"tooltip["..x.."," .. y .. ";0.5,0.5;" .. S("Block has a wrench menu") .. ";#0C3D32;#FFFFFF]"
end
function techage.storage_formspec(self, pos, nvm, label, netw_data, curr_load, max_load)
return "size[6.3,4]" ..
default.gui_bg ..

View File

@ -143,7 +143,8 @@ local function settings_menu(pos, playername)
context[playername] = pos
if form_def then
minetest.show_formspec(playername, "techage:ta_formspec", menu.generate_formspec(pos, ndef, form_def))
minetest.show_formspec(playername, "techage:ta_formspec",
menu.generate_formspec(pos, ndef, form_def, playername))
end
end
@ -162,10 +163,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec)
if form_def then
if menu.eval_input(pos, ndef, form_def, fields) then
if menu.eval_input(pos, ndef, form_def, fields, playername) then
--context[playername] = pos
minetest.after(0.2, function()
minetest.show_formspec(playername, "techage:ta_formspec", menu.generate_formspec(pos, ndef, form_def))
minetest.show_formspec(playername, "techage:ta_formspec",
menu.generate_formspec(pos, ndef, form_def, playername))
end)
end
end

View File

@ -22,10 +22,25 @@ local function index(list, x)
return nil
end
local function allow_put(inv, listname, index, stack, player)
local list = inv:get_list(listname)
stack:set_count(1)
inv:set_stack(listname, index, stack)
return 0
end
local function allow_take(inv, listname, index, stack, player)
local list = inv:get_list(listname)
stack:set_count(0)
inv:set_stack(listname, index, stack)
return 0
end
-- generate the formspec string to be placed into a container frame
local function generate_formspec_substring(pos, meta, form_def)
local function generate_formspec_substring(pos, meta, form_def, player_name)
local tbl = {}
local player_inv_needed = false
if meta and form_def then
local nvm = techage.get_nvm(pos)
@ -97,6 +112,9 @@ local function generate_formspec_substring(pos, meta, form_def)
local idx = index(l, val) or 1
tbl[#tbl+1] = "dropdown[4.72," .. (offs) .. ";5.5,1.4;" .. elem.name .. ";" .. elem.choices .. ";" .. idx .. "]"
end
elseif elem.type == "items" then
tbl[#tbl+1] = "list[detached:" .. minetest.formspec_escape(player_name) .. "_techage_wrench_menu;cfg;4.75," .. offs .. ";" .. elem.size .. ",1;]"
player_inv_needed = true
end
end
if nvm.running or techage.is_running(nvm) then
@ -104,7 +122,8 @@ local function generate_formspec_substring(pos, meta, form_def)
tbl[#tbl+1] = "label[0," .. offs .. ";" .. S("Note: You can't change any values while the block is running!") .. "]"
end
end
return table.concat(tbl, "")
return player_inv_needed, table.concat(tbl, "")
end
local function value_check(elem, value)
@ -114,7 +133,7 @@ local function value_check(elem, value)
return true
end
local function evaluate_data(pos, meta, form_def, fields)
local function evaluate_data(pos, meta, form_def, fields, player_name)
local res = true
if meta and form_def then
@ -166,22 +185,56 @@ local function evaluate_data(pos, meta, form_def, fields)
if fields[elem.name] ~= nil then
meta:set_string(elem.name, fields[elem.name])
end
elseif elem.type == "items" then
local inv_name = minetest.formspec_escape(player_name) .. "_techage_wrench_menu"
local dinv = minetest.get_inventory({type = "detached", name = inv_name})
local ninv = minetest.get_inventory({type = "node", pos = pos})
if dinv and ninv then
for i = 1, ninv:get_size("cfg") do
ninv:set_stack("cfg", i, dinv:get_stack("cfg", i))
end
end
end
end
end
return res
end
function menu.generate_formspec(pos, ndef, form_def)
function menu.generate_formspec(pos, ndef, form_def, player_name)
local meta = minetest.get_meta(pos)
local number = techage.get_node_number(pos)
local mem = techage.get_mem(pos)
mem.star = ((mem.star or 0) + 1) % 2
local star = mem.star == 1 and "*" or ""
local inv_name = minetest.formspec_escape(player_name) .. "_techage_wrench_menu"
minetest.create_detached_inventory(inv_name, {
allow_put = allow_put,
allow_take = allow_take})
local dinv = minetest.get_inventory({type = "detached", name = inv_name})
local ninv = minetest.get_inventory({type = "node", pos = pos})
if dinv and ninv then
dinv:set_size('cfg', ninv:get_size("cfg"))
for i = 1, ninv:get_size("cfg") do
dinv:set_stack("cfg", i, ninv:get_stack("cfg", i))
end
end
if meta and number and ndef and form_def then
local title = ndef.description .. " (" .. number .. ")"
local player_inv_needed, text = generate_formspec_substring(pos, meta, form_def, player_name)
local buttons
if player_inv_needed then
buttons = "button[0.5,6.2;3,1;refresh;" .. S("Refresh") .. "]" ..
"button_exit[3.5,6.2;3,1;cancel;" .. S("Cancel") .. "]" ..
"button[6.5,6.2;3,1;save;" .. S("Save") .. "]" ..
"list[current_player;main;1,7.2;8,2;]"
else
buttons = "button[0.5,8.4;3,1;refresh;" .. S("Refresh") .. "]" ..
"button_exit[3.5,8.4;3,1;cancel;" .. S("Cancel") .. "]" ..
"button[6.5,8.4;3,1;save;" .. S("Save") .. "]"
end
return "size[10,9]" ..
default.gui_bg ..
default.gui_bg_img ..
@ -190,22 +243,20 @@ function menu.generate_formspec(pos, ndef, form_def)
"label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" ..
"label[9.5,-0.1;" .. minetest.colorize( "#000000", star) .. "]" ..
"container[0,1]" ..
generate_formspec_substring(pos, meta, form_def) ..
text ..
"container_end[]" ..
"button[0.5,8.4;3,1;refresh;" .. S("Refresh") .. "]" ..
"button_exit[3.5,8.4;3,1;cancel;" .. S("Cancel") .. "]" ..
"button[6.5,8.4;3,1;save;" .. S("Save") .. "]"
buttons
end
return ""
end
function menu.eval_input(pos, ndef, form_def, fields)
function menu.eval_input(pos, ndef, form_def, fields, player_name)
--print(dump(fields))
if fields.save then
local meta = minetest.get_meta(pos)
evaluate_data(pos, meta, form_def, fields)
evaluate_data(pos, meta, form_def, fields, player_name)
end
return fields.refresh or fields.save
end
return menu
return menu