further logic nodes added

This commit is contained in:
Joachim Stolberg 2019-08-23 23:35:37 +02:00
parent f085883e55
commit b2ff68fe8c
21 changed files with 746 additions and 62 deletions

View File

@ -23,27 +23,27 @@ local InventoryState = {}
local function store_action(pos, player, action, stack)
local meta = minetest.get_meta(pos)
local name = player and player:get_player_name() or ""
local number = meta:get_string("number")
local number = meta:get_string("node_number")
local item = stack:get_name().." "..stack:get_count()
PlayerActions[number] = {name, action, item}
end
local function send_off_command(pos)
local meta = minetest.get_meta(pos)
local dest_num = meta:get_string("dest_num")
local own_num = meta:get_string("number")
local owner = meta:get_string("owner")
techage.send_multi(dest_num, owner, nil, "off", own_num)
local numbers = meta:get_string("numbers") or ""
if numbers ~= "" then
local own_num = meta:get_string("node_number")
techage.send_multi(numbers, "off", own_num)
end
end
local function send_command(pos)
local meta = minetest.get_meta(pos)
local dest_num = meta:get_string("dest_num")
if dest_num ~= "" then
local own_num = meta:get_string("number")
local owner = meta:get_string("owner")
techage.send_multi(dest_num, owner, nil, "on", own_num)
local numbers = meta:get_string("numbers") or ""
if numbers ~= "" then
local own_num = meta:get_string("node_number")
techage.send_multi(numbers, "on", own_num)
minetest.after(1, send_off_command, pos)
end
end
@ -110,12 +110,16 @@ minetest.register_node("techage:chest_ta2", {
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local number = techage.add_node(pos, "techage:chest_ta2")
meta:set_string("number", number)
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec2())
meta:set_string("infotext", S("TA2 Protected Chest").." "..number)
end,
techage_set_numbers = function(pos, numbers, player_name)
return techage.logic.set_numbers(pos, numbers, player_name, S("TA2 Protected Chest"))
end,
can_dig = can_dig,
after_dig_node = after_dig_node,
allow_metadata_inventory_put = allow_metadata_inventory_put,
@ -159,12 +163,16 @@ minetest.register_node("techage:chest_ta3", {
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local number = techage.add_node(pos, "techage:chest_ta3")
meta:set_string("number", number)
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec3())
meta:set_string("infotext", S("TA3 Protected Chest").." "..number)
end,
techage_set_numbers = function(pos, numbers, player_name)
return techage.logic.set_numbers(pos, numbers, player_name, S("TA3 Protected Chest"))
end,
can_dig = can_dig,
after_dig_node = after_dig_node,
allow_metadata_inventory_put = allow_metadata_inventory_put,
@ -208,12 +216,16 @@ minetest.register_node("techage:chest_ta4", {
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local number = techage.add_node(pos, "techage:chest_ta4")
meta:set_string("number", number)
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec4())
meta:set_string("infotext", S("TA4 Protected Chest").." "..number)
end,
techage_set_numbers = function(pos, numbers, player_name)
return techage.logic.set_numbers(pos, numbers, player_name, S("TA4 Protected Chest"))
end,
can_dig = can_dig,
after_dig_node = after_dig_node,
allow_metadata_inventory_put = allow_metadata_inventory_put,
@ -249,16 +261,8 @@ techage.register_node({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_
return techage.get_inv_state(inv, "main")
elseif topic == "player_action" then
local meta = minetest.get_meta(pos)
local number = meta:get_string("number")
local number = meta:get_string("node_number")
return PlayerActions[number]
elseif topic == "set_numbers" then
if techage.check_numbers(payload) then
local meta = minetest.get_meta(pos)
meta:set_string("dest_num", payload)
local number = meta:get_string("number")
meta:set_string("infotext", S("TA Protected Chest").." "..number.." "..S("connected with").." "..payload)
return true
end
else
return "unsupported"
end

View File

@ -83,10 +83,11 @@ end
local function not_protected(pos, placer_name, clicker_name)
local meta = minetest.get_meta(pos)
if meta then
local cached_name = meta:get_string("techage_cached_name")
if placer_name and (placer_name == cached_name or not minetest.is_protected(pos, placer_name)) then
meta:set_string("techage_cached_name", placer_name)
if clicker_name == nil or not minetest.is_protected(pos, clicker_name) then
if placer_name and not minetest.is_protected(pos, placer_name) then
if clicker_name == nil or placer_name == clicker_name then
return true
end
if not minetest.is_protected(pos, clicker_name) then
return true
end
end
@ -157,20 +158,6 @@ end
-- API helper functions
-------------------------------------------------------------------
-- Check the given list of numbers.
-- Returns true if number(s) is/are valid and point to real nodes.
function techage.check_numbers(numbers)
if numbers then
for _,num in ipairs(string_split(numbers, " ")) do
if Number2Pos[num] == nil then
return false
end
end
return true
end
return false
end
-- Function returns { pos, name } for the node on the given position number.
function techage.get_node_info(dest_num)
if Number2Pos[dest_num] then
@ -297,6 +284,21 @@ function techage.not_protected(number, placer_name, clicker_name)
return false
end
-- Check the given list of numbers.
-- Returns true if number(s) is/are valid, point to real nodes and
-- and the nodes are not protected for the given player_name.
function techage.check_numbers(numbers, placer_name)
if numbers then
for _,num in ipairs(string_split(numbers, " ")) do
if not techage.not_protected(num, placer_name, nil) then
return false
end
end
return true
end
return false
end
function techage.send_multi(numbers, topic, payload)
for _,num in ipairs(string_split(numbers, " ")) do
if Number2Pos[num] and Number2Pos[num].name then

View File

@ -109,5 +109,5 @@ techage.register_category_page("ta3l",
S("TA3: Logic"),
S("Collection of TA3 logic blocks to control your machines."),
"techage:terminal2",
{"terminal"}
{"terminal", "button", "detector", "repeater", "programmer"}
)

View File

@ -149,7 +149,12 @@ else
end
-- Logic
dofile(MP.."/logic/lib.lua")
dofile(MP.."/logic/terminal.lua")
dofile(MP.."/logic/button.lua")
dofile(MP.."/logic/detector.lua")
dofile(MP.."/logic/repeater.lua")
dofile(MP.."/logic/programmer.lua")
-- Test
dofile(MP.."/recipe_checker.lua")

201
logic/button.lua Normal file
View File

@ -0,0 +1,201 @@
--[[
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Logic button
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local logic = techage.logic
local function switch_on(pos)
local cycle_time = M(pos):get_int("cycle_time")
logic.swap_node(pos, "techage:button_on")
logic.send_on(pos, M(pos), cycle_time)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
end
local function switch_off(pos)
logic.swap_node(pos, "techage:button_off")
logic.send_off(pos, M(pos))
end
local function formspec(meta)
local numbers = meta:get_string("numbers") or ""
local idx = meta:get_int("cycle_idx") or 0
if idx == 0 then idx = 1 end
return "size[7.5,6]"..
"dropdown[0.2,0;3;type;switch,button 2s,button 4s,button 8s,button 16s,button 32s;"..idx.."]"..
"field[0.5,2;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"checkbox[1,3;public;public;false]"..
"button_exit[2,4;3,1;exit;"..S("Save").."]"
end
minetest.register_node("techage:button_off", {
description = S("TA3 Button/Switch"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_button.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_button.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_button_off.png",
},
after_place_node = function(pos, placer)
local meta = M(pos)
logic.after_place_node(pos, placer, "techage:button_off", S("TA3 Button/Switch"))
logic.infotext(meta, S("TA3 Button/Switch"))
meta:set_string("formspec", formspec(meta))
meta:set_string("public", "false")
meta:set_int("cycle_time", 0)
end,
on_receive_fields = function(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
print(dump(fields))
local meta = M(pos)
if not techage.check_numbers(fields.numbers, player:get_player_name()) then
return
end
meta:set_string("numbers", fields.numbers)
if fields.public then
meta:set_string("public", fields.public)
end
local cycle_time = nil
if fields.type == "switch" then
meta:set_int("cycle_idx", 1)
cycle_time = 0
elseif fields.type == "button 2s" then
meta:set_int("cycle_idx", 2)
cycle_time = 2
elseif fields.type == "button 4s" then
meta:set_int("cycle_idx", 3)
cycle_time = 4
elseif fields.type == "button 8s" then
meta:set_int("cycle_idx", 4)
cycle_time = 8
elseif fields.type == "button 16s" then
meta:set_int("cycle_idx", 5)
cycle_time = 16
elseif fields.type == "button 32s" then
meta:set_int("cycle_idx", 6)
cycle_time = 32
end
if cycle_time ~= nil then
meta:set_int("cycle_time", cycle_time)
end
logic.infotext(meta, S("TA3 Button/Switch"))
if fields.exit then
meta:set_string("formspec", nil)
else
meta:set_string("formspec", formspec(meta))
end
end,
on_rightclick = function(pos, node, clicker)
local meta = M(pos)
local numbers = meta:get_string("numbers")
if numbers ~= "" and numbers ~= nil then
if meta:get_string("public") == "true" or
clicker:get_player_name() == meta:get_string("owner") then
switch_on(pos)
end
end
end,
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Button/Switch"))
meta:set_string("formspec", formspec(meta))
return res
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
end,
on_rotate = screwdriver.disallow,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:button_on", {
description = ("TA3 Button/Switch"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_button.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_button.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_button_on.png",
},
on_rightclick = function(pos, node, clicker)
local meta = M(pos)
local numbers = meta:get_string("numbers")
if numbers ~= "" and numbers ~= nil then
if meta:get_string("public") == "true" or
clicker:get_player_name() == meta:get_string("owner") then
switch_off(pos)
end
end
end,
on_timer = switch_off,
on_rotate = screwdriver.disallow,
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Button/Switch"))
meta:set_string("formspec", formspec(meta))
return res
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
end,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
drop = "techage:button_off",
})
minetest.register_craft({
output = "techage:button_off",
recipe = {
{"", "group:wood", ""},
{"default:glass", "techage:vacuum_tube", ""},
{"", "group:wood", ""},
},
})
techage.register_entry_page("ta3l", "button",
S("TA3 Button/Switch"),
S("The Button/Switch is used to send on/off commands to machines/nodes.@n"..
"It can be configured as switch or as button with configurable cycle time from 2 to 32s)"),
"techage:button_on")

154
logic/detector.lua Normal file
View File

@ -0,0 +1,154 @@
--[[
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Item detector
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local logic = techage.logic
local BLOCKING_TIME = 8 -- seconds
local function switch_on(pos)
local mem = tubelib2.get_mem(pos)
local t = minetest.get_gametime()
if t > (mem.time or 0) then
logic.swap_node(pos, "techage:detector_on")
logic.send_on(pos, M(pos), 1)
mem.time = t + BLOCKING_TIME
end
end
local function switch_off(pos)
logic.swap_node(pos, "techage:detector_off")
logic.send_off(pos, M(pos))
end
local function formspec(meta)
local numbers = meta:get_string("numbers") or ""
return "size[7.5,3]"..
"field[0.5,1;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"button_exit[2,2;3,1;exit;"..S("Save").."]"
end
minetest.register_node("techage:detector_off", {
description = S("TA3 Detector"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png^techage_appl_arrow.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_detector.png^[transformFX",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_detector.png",
},
after_place_node = function(pos, placer)
local meta = M(pos)
logic.after_place_node(pos, placer, "techage:detector_off", S("TA3 Detector"))
logic.infotext(meta, S("TA3 Detector"))
meta:set_string("formspec", formspec(meta))
end,
on_receive_fields = function(pos, formname, fields, player)
local meta = minetest.get_meta(pos)
if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers)
logic.infotext(M(pos), S("TA3 Detector"))
meta:set_string("formspec", formspec(M(pos)))
end
end,
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Detector"))
meta:set_string("formspec", formspec(meta))
return res
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:detector_on", {
description = S("TA3 Detector"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png^techage_appl_arrow.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_detector_on.png^[transformFX",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_detector_on.png",
},
on_timer = switch_off,
on_rotate = screwdriver.disallow,
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Detector"))
meta:set_string("formspec", formspec(meta))
return res
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
end,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
drop = "techage:detector_off",
})
minetest.register_craft({
output = "techage:detector_off",
recipe = {
{"", "group:wood", ""},
{"techage:tubeS", "techage:vacuum_tube", "techage:tubeS"},
{"", "group:wood", ""},
},
})
techage.register_node({"techage:detector_off", "techage:detector_on"}, {
on_push_item = function(pos, in_dir, stack)
if techage.push_items(pos, in_dir, stack) then
switch_on(pos)
return true
end
return false
end,
is_pusher = true, -- is a pulling/pushing node
})
techage.register_entry_page("ta3l", "detector",
S("TA3 Detector"),
S("The Detector is a special kind of tube block that@n"..
"outputs an event when items pass through.@n"..
"It sends an 'on' when an item goes through,@n"..
"followed by an 'off' event one second later.@n"..
"After that it blocks further events for 8 seconds."),
"techage:detector_on")

73
logic/lib.lua Normal file
View File

@ -0,0 +1,73 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Logic library
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
techage.logic = {}
function techage.logic.swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
function techage.logic.after_place_node(pos, placer, name, descr)
local meta = M(pos)
local own_num = techage.add_node(pos, name)
meta:set_string("node_number", own_num)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", descr.." -")
end
function techage.logic.send_on(pos, meta, time)
local own_num = meta:get_string("node_number") or ""
local numbers = meta:get_string("numbers") or ""
if time and time > 0 then
minetest.get_node_timer(pos):start(time)
end
techage.send_multi(numbers, "on", own_num)
end
function techage.logic.send_off(pos, meta)
local own_num = meta:get_string("node_number") or ""
local numbers = meta:get_string("numbers") or ""
techage.send_multi(numbers, "off", own_num)
end
function techage.logic.infotext(meta, descr, text)
local own_num = meta:get_string("node_number") or ""
local numbers = meta:get_string("numbers") or ""
if numbers ~= "" then
meta:set_string("infotext", descr.." "..own_num..": "..S("connected with").." "..numbers)
elseif text then
meta:set_string("infotext", descr.." "..own_num..": "..text)
else
meta:set_string("infotext", descr.." "..own_num)
end
end
function techage.logic.set_numbers(pos, numbers, player_name, descr)
if techage.check_numbers(numbers, player_name) then
local meta = M(pos)
meta:set_string("numbers", numbers)
techage.logic.infotext(meta, descr)
return true
end
return false
end

108
logic/programmer.lua Normal file
View File

@ -0,0 +1,108 @@
--[[
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Number programmer
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local function join_to_string(tbl)
local t = {}
for key,_ in pairs(tbl) do
t[#t + 1] = key
end
return table.concat(t, " ")
end
local function reset_programmer(itemstack, user, pointed_thing)
user:set_attribute("techage_prog_numbers", nil)
minetest.chat_send_player(user:get_player_name(), S("[Techage Programmer] programmer reset"))
return itemstack
end
local function read_number(itemstack, user, pointed_thing)
local pos = pointed_thing.under
if pos then
local number = techage.get_node_number(pos)
if number then
local numbers = minetest.deserialize(user:get_attribute("techage_prog_numbers")) or {}
numbers[number] = true
user:set_attribute("techage_prog_numbers", minetest.serialize(numbers))
minetest.chat_send_player(user:get_player_name(), S("[Techage Programmer] number").." "..number.." read")
else
minetest.chat_send_player(user:get_player_name(), S("[Techage Programmer] Unknown node on").." "..minetest.pos_to_string(pos))
end
else
return reset_programmer(itemstack, user, pointed_thing)
end
return itemstack
end
local function program_numbers(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
if pos then
local meta = M(pos)
local numbers = minetest.deserialize(placer:get_attribute("techage_prog_numbers")) or {}
placer:set_attribute("techage_prog_numbers", nil)
local player_name = placer:get_player_name()
if meta and meta:get_string("owner") ~= player_name then
minetest.chat_send_player(player_name, S("[Techage Programmer] foreign or unknown node!"))
return itemstack
end
local text = join_to_string(numbers)
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
if ndef and ndef.techage_set_numbers then
local res = ndef.techage_set_numbers(pos, text, player_name)
if res == true then
minetest.chat_send_player(player_name, S("[Techage Programmer] node programmed!"))
else
minetest.chat_send_player(player_name, S("[Techage Programmer] Error: invalid numbers!"))
end
else
minetest.chat_send_player(player_name, S("[Techage Programmer] Error: programmer not supported!"))
end
return itemstack
else
return reset_programmer(itemstack, placer, pointed_thing)
end
end
minetest.register_craftitem("techage:programmer", {
description = S("Techage Programmer (right = read number, left = write numbers)"),
inventory_image = "techage_programmer.png",
stack_max = 1,
wield_image = "techage_programmer_wield.png",
groups = {cracky=1, book=1},
-- left mouse button = program
on_use = program_numbers,
on_secondary_use = reset_programmer,
-- right mouse button = read
on_place = read_number,
})
minetest.register_craft({
output = "techage:programmer",
recipe = {
{"", "default:steel_ingot", ""},
{"", "techage:wlanchip", ""},
{"", "dye:red", ""},
},
})
techage.register_entry_page("ta3l", "programmer",
S("Techage Programmer"),
S("The Programmer is a tool to collect block numbers (right mouse button)@n"..
"from machines/nodes to program (left mouse button) the Repeater@n"..
"or other nodes. This is especially useful if you want to switch on/off@n"..
"many block at the same time."),
"techage:programmer")

118
logic/repeater.lua Normal file
View File

@ -0,0 +1,118 @@
--[[
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Signal Repeater
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local logic = techage.logic
local OVER_LOAD_MAX = 10
local CYCLE_TIME = 2
local function formspec(meta)
local numbers = meta:get_string("numbers") or ""
return "size[7.5,3]"..
"field[0.5,1;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"button_exit[2,2;3,1;exit;"..S("Save").."]"
end
minetest.register_node("techage:repeater", {
description = S("TA3 Repeater"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_repeater.png",
},
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.get_mem(pos)
logic.after_place_node(pos, placer, "techage:repeater", S("TA3 Repeater"))
logic.infotext(meta, S("TA3 Repeater"))
meta:set_string("formspec", formspec(meta))
mem.overload_cnt = 0
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
on_receive_fields = function(pos, formname, fields, player)
local meta = M(pos)
if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers)
logic.infotext(M(pos), S("TA3 Repeater"))
meta:set_string("formspec", formspec(meta))
end
end,
on_timer = function(pos,elapsed)
local mem = tubelib2.get_mem(pos)
mem.overload_cnt = 0
return true
end,
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Repeater"))
meta:set_string("formspec", formspec(meta))
return res
end,
after_dig_node = function(pos)
techage.remove_node(pos)
end,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
})
minetest.register_craft({
output = "techage:repeater",
recipe = {
{"", "group:wood", ""},
{"techage:vacuum_tube", "", "techage:vacuum_tube"},
{"", "group:wood", ""},
},
})
techage.register_node({"techage:repeater"}, {
on_recv_message = function(pos, topic, payload)
local mem = tubelib2.get_mem(pos)
mem.overload_cnt = (mem.overload_cnt or 0) + 1
if mem.overload_cnt > OVER_LOAD_MAX then
logic.infotext(M(pos), S("TA3 Repeater"), "fault (overloaded)")
minetest.get_node_timer(pos):stop()
return false
else
local numbers = M(pos):get_string("numbers") or ""
techage.send_multi(numbers, topic, payload)
end
end,
on_node_load = function(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
})
techage.register_entry_page("ta3l", "repeater",
S("TA3 Repeater"),
S("The Repeater is a multiplier block, sending received commands@n"..
"to all connected blocks. The list of destination block numbers@n"..
"has to be configured, but can easily programmed@n"..
"by means of the Programmer."),
"techage:repeater")

View File

@ -12,6 +12,7 @@
]]--
local M = minetest.get_meta
local S = techage.S
local HELP_TA3 = S("#### TA3 Terminal ####@n"..
@ -40,14 +41,14 @@ local HELP_TA3 = S("#### TA3 Terminal ####@n"..
local CMNDS_TA3 = S("Syntax error, try help")
local function formspec1()
return "size[6,4]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"field[0.5,1;5,1;number;Techage Controller number:;]" ..
"button_exit[1.5,2.5;2,1;exit;Save]"
end
--local function formspec1()
-- return "size[6,4]"..
-- default.gui_bg..
-- default.gui_bg_img..
-- default.gui_slots..
-- "field[0.5,1;5,1;number;Techage Controller number:;]" ..
-- "button_exit[1.5,2.5;2,1;exit;Save]"
--end
local function get_string(meta, num, default)
local s = meta:get_string("bttn_text"..num)
@ -127,7 +128,6 @@ local function command(pos, command, player)
output(pos, "$ "..command)
local num, cmnd, payload = command:match('^cmd%s+([0-9]+)%s+(%w+)%s*(.*)$')
if num and cmnd then
local own_number = meta:get_string("own_number")
if techage.not_protected(num, owner, owner) then
local resp = techage.send_single(num, cmnd, payload)
if type(resp) == "string" then
@ -177,7 +177,7 @@ local function register_terminal(num, tiles, node_box, selection_box)
after_place_node = function(pos, placer)
local number = techage.add_node(pos, minetest.get_node(pos).name)
local meta = minetest.get_meta(pos)
meta:set_string("own_number", number)
meta:set_string("node_number", number)
meta:set_string("command", S("commands like: help"))
meta:set_string("formspec", formspec2(meta))
meta:set_string("owner", placer:get_player_name())
@ -284,12 +284,15 @@ minetest.register_craft({
techage.register_node({"techage:terminal1", "techage:terminal2"}, {
on_recv_message = function(pos, topic, payload)
if topic == "term" then
output(pos, payload)
return true
elseif topic == "msg" then
output(pos, payload.src..": "..payload.text)
return true
output(pos, "cmd="..dump(topic)..", data="..dump(payload))
return true
end,
on_node_load = function(pos)
local meta = M(pos)
local number = meta:get_string("number") or ""
if number ~= "" then
meta:set_string("node_number", number)
meta:set_string("number", nil)
end
end,
})

View File

@ -80,9 +80,9 @@ minetest.register_node("techage:powerswitch", {
},
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local meta = M(pos)
local number = techage.add_node(pos, "techage:powerswitch")
meta:set_string("number", number)
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA Power Switch").." "..number)
end,
@ -212,6 +212,14 @@ techage.register_node({"techage:powerswitch", "techage:powerswitch_on"}, {
return "unsupported"
end
end,
on_node_load = function(pos)
local meta = M(pos)
local number = meta:get_string("number") or ""
if number ~= "" then
meta:set_string("node_number", number)
meta:set_string("number", nil)
end
end,
})
minetest.register_craft({

View File

@ -83,7 +83,7 @@ minetest.register_node("techage:ta4_solar_minicell", {
after_place_node = function(pos)
local meta = minetest.get_meta(pos)
local number = techage.add_node(pos, "techage:ta4_solar_minicell")
meta:set_string("number", number)
meta:set_string("node_number", number)
meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number)
local mem = tubelib2.get_mem(pos)
mem.capa = 0
@ -121,6 +121,14 @@ techage.register_node({"techage:ta4_solar_minicell"}, {
return "unsupported"
end
end,
on_node_load = function(pos)
local meta = M(pos)
local number = meta:get_string("number") or ""
if number ~= "" then
meta:set_string("node_number", number)
meta:set_string("number", nil)
end
end,
})
minetest.register_craft({

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

View File

@ -1,7 +1,7 @@
--[[
TexchAge
========
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg