Improve energy storage detection, increase Lua controller editor contrast

master
Joachim Stolberg 2021-02-01 23:20:41 +01:00
parent b74c596b00
commit 2f7dbc1771
2 changed files with 46 additions and 17 deletions

View File

@ -73,21 +73,46 @@ local function chat(owner, text)
return text return text
end end
local function get_radius(pos, in_dir) local function get_diameter(pos, in_dir)
local dir = tubelib2.Dir6dToVector[in_dir] local dir = tubelib2.Dir6dToVector[in_dir]
local pos2 = vector.add(pos, vector.multiply(dir, 8)) local pos2, node
pos2 = vector.add(pos, vector.multiply(dir, 4))
node = minetest.get_node(pos2)
if node.name == "techage:ta3_pipe_wall_entry" then
return
end
if node.name == "techage:ta4_pipe_inlet" then
return 5
end
pos2 = vector.add(pos, vector.multiply(dir, 6))
node = minetest.get_node(pos2)
if node.name == "techage:ta3_pipe_wall_entry" then
return
end
if node.name == "techage:ta4_pipe_inlet" then
return 7
end
pos2 = vector.add(pos, vector.multiply(dir, 8))
node = minetest.get_node(pos2)
if node.name == "techage:ta3_pipe_wall_entry" then
return
end
if node.name == "techage:ta4_pipe_inlet" then
return 9
end
pos2 = vector.add(pos, vector.multiply(dir, 10))
local poses = minetest.find_nodes_in_area(pos, pos2, {"techage:ta4_pipe_inlet"}) local poses = minetest.find_nodes_in_area(pos, pos2, {"techage:ta4_pipe_inlet"})
if #poses == 2 then if #poses > 1 then
local radius = vector.distance(poses[1], poses[2]) / 2 return vector.distance(pos, poses[2]) + 1
if radius == 2 or radius == 3 or radius == 4 then
return radius
end end
end end
return 1
end
local function check_volume(pos, in_dir, owner) local function check_volume(pos, in_dir, owner)
local radius = get_radius(pos, in_dir) local radius = (get_diameter(pos, in_dir) - 1) / 2
if radius then if radius then
local dir = tubelib2.Dir6dToVector[in_dir] local dir = tubelib2.Dir6dToVector[in_dir]
local cpos = vector.add(pos, vector.multiply(dir, radius)) local cpos = vector.add(pos, vector.multiply(dir, radius))
@ -113,7 +138,7 @@ end
-- provide position behind the obsidian_glass -- provide position behind the obsidian_glass
local function check_window(pos, in_dir) local function check_window(pos, in_dir)
local radius = get_radius(pos, in_dir) local radius = (get_diameter(pos, in_dir) - 1) / 2
if radius then if radius then
local dir = tubelib2.Dir6dToVector[in_dir] local dir = tubelib2.Dir6dToVector[in_dir]
local cpos = vector.add(pos, vector.multiply(dir, radius)) local cpos = vector.add(pos, vector.multiply(dir, radius))
@ -134,7 +159,7 @@ end
techage.register_node({"techage:ta4_pipe_inlet"}, { techage.register_node({"techage:ta4_pipe_inlet"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
if topic == "diameter" then if topic == "diameter" then
return get_radius(pos, in_dir) * 2 - 1 return get_diameter(pos, in_dir)
elseif topic == "integrity" then elseif topic == "integrity" then
return check_volume(pos, in_dir, payload) return check_volume(pos, in_dir, payload)
elseif topic == "volume" then elseif topic == "volume" then

View File

@ -180,9 +180,10 @@ local function formspec1(meta)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"style_type[textarea;font=mono]".. "style_type[textarea;font=mono;textcolor=#FFFFFF;border=false]"..
"tabheader[0,0;tab;init,func,loop,outp,notes,help;1;;true]".. "tabheader[0,0;tab;init,func,loop,outp,notes,help;1;;true]"..
"textarea[0.3,0.2;10,8.3;init;function init();"..init.."]".. "textarea[0.3,0.2;10,8.3;init;function init();"..init.."]"..
"background[0.1,0.3;9.8,7.0;techage_form_mask.png]"..
"label[0,7.3;end]".. "label[0,7.3;end]"..
"button_exit[4.4,7.5;1.8,1;cancel;Cancel]".. "button_exit[4.4,7.5;1.8,1;cancel;Cancel]"..
"button[6.3,7.5;1.8,1;save;Save]".. "button[6.3,7.5;1.8,1;save;Save]"..
@ -198,9 +199,10 @@ local function formspec2(meta)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"style_type[textarea;font=mono]".. "style_type[textarea;font=mono;textcolor=#FFFFFF;border=false]"..
"tabheader[0,0;tab;init,func,loop,outp,notes,help;2;;true]".. "tabheader[0,0;tab;init,func,loop,outp,notes,help;2;;true]"..
"textarea[0.3,0.2;10,8.3;func;functions:;"..func.."]".. "textarea[0.3,0.2;10,8.3;func;functions:;"..func.."]"..
"background[0.1,0.3;9.8,7.0;techage_form_mask.png]"..
"button_exit[4.4,7.5;1.8,1;cancel;Cancel]".. "button_exit[4.4,7.5;1.8,1;cancel;Cancel]"..
"button[6.3,7.5;1.8,1;save;Save]".. "button[6.3,7.5;1.8,1;save;Save]"..
"button[8.2,7.5;1.8,1;"..cmnd.."]" "button[8.2,7.5;1.8,1;"..cmnd.."]"
@ -215,9 +217,10 @@ local function formspec3(meta)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"style_type[textarea;font=mono]".. "style_type[textarea;font=mono;textcolor=#FFFFFF;border=false]"..
"tabheader[0,0;tab;init,func,loop,outp,notes,help;3;;true]".. "tabheader[0,0;tab;init,func,loop,outp,notes,help;3;;true]"..
"textarea[0.3,0.2;10,8.3;loop;function loop(ticks, elapsed);"..loop.."]".. "textarea[0.3,0.2;10,8.3;loop;function loop(ticks, elapsed);"..loop.."]"..
"background[0.1,0.3;9.8,7.0;techage_form_mask.png]"..
"label[0,7.3;end]".. "label[0,7.3;end]"..
"button_exit[4.4,7.5;1.8,1;cancel;Cancel]".. "button_exit[4.4,7.5;1.8,1;cancel;Cancel]"..
"button[6.3,7.5;1.8,1;save;Save]".. "button[6.3,7.5;1.8,1;save;Save]"..
@ -248,9 +251,10 @@ local function formspec5(meta)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"style_type[textarea;font=mono]".. "style_type[textarea;font=mono;textcolor=#FFFFFF;border=false]"..
"tabheader[0,0;tab;init,func,loop,outp,notes,help;5;;true]".. "tabheader[0,0;tab;init,func,loop,outp,notes,help;5;;true]"..
"textarea[0.3,0.2;10,8.3;notes;Notepad:;"..notes.."]".. "textarea[0.3,0.2;10,8.3;notes;Notepad:;"..notes.."]"..
"background[0.1,0.3;9.8,7.0;techage_form_mask.png]"..
"button_exit[6.3,7.5;1.8,1;cancel;Cancel]".. "button_exit[6.3,7.5;1.8,1;cancel;Cancel]"..
"button[8.2,7.5;1.8,1;save;Save]" "button[8.2,7.5;1.8,1;save;Save]"
end end
@ -261,7 +265,7 @@ local function formspec6(items, pos, text)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"style_type[textarea;font=mono]".. "style_type[textarea;font=mono;textcolor=#FFFFFF]"..
"tabheader[0,0;tab;init,func,loop,outp,notes,help;6;;true]".. "tabheader[0,0;tab;init,func,loop,outp,notes,help;6;;true]"..
"label[0,-0.2;Functions:]".. "label[0,-0.2;Functions:]"..
"dropdown[0.3,0.2;10,8.3;functions;"..items..";"..pos.."]".. "dropdown[0.3,0.2;10,8.3;functions;"..items..";"..pos.."]"..