Skip to content

Instantly share code, notes, and snippets.

@cheapie
Created July 26, 2023 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheapie/5b5f95b3336c33bc64aad2377d1777bb to your computer and use it in GitHub Desktop.
Save cheapie/5b5f95b3336c33bc64aad2377d1777bb to your computer and use it in GitHub Desktop.
local function get_init(pos)
return function()
local meta = minetest.get_meta(pos)
local is_init = meta:get_int("techage_assigned") == 1
local techage_id = meta:get_int("node_number")
if is_init then return techage_id end
techage_id = techage.add_node(pos)
meta:set_int("techage_assigned",1)
meta:set_string("infotext","Luacontroller "..techage_id)
end
end
local function send_relay(pos,src,dest,message,arg)
local ret = techage.send_single(src,dest,message,arg)
if ret then
local node = minetest.get_node(pos)
minetest.registered_nodes[node.name].digiline.effector.action(pos,node,string.format("techagereply_%d",dest),ret)
end
end
local function get_send(pos)
return function(dest,message,arg)
local meta = minetest.get_meta(pos)
if meta:get_int("techage_assigned") < 1 then
error("Techage not enabled for this controller")
end
local techage_id = meta:get_int("node_number")
assert(type(dest) == "number","Destination ID must be a number")
assert(type(message) == "string","Message must be a string")
assert(type(arg) == "string" or not arg,"Argument must be a string or nil")
dest = math.floor(dest)
minetest.after(0,send_relay,pos,techage_id,dest,message,arg)
end
end
function mesecon.luacontroller_libraries.techage(env,pos)
local lc_techage = {}
lc_techage.init = get_init(pos)
lc_techage.send = get_send(pos)
return lc_techage
end
for a=0,1,1 do
for b=0,1,1 do
for c=0,1,1 do
for d=0,1,1 do
local name = string.format("mesecons_luacontroller:luacontroller%d%d%d%d",a,b,c,d)
local olddig = minetest.registered_nodes[name].after_dig_node
minetest.registered_nodes[name].after_dig_node = function(pos,oldnode,oldmeta,digger)
if oldmeta.techage_assigned and tonumber(oldmeta.techage_assigned) > 0 then
techage.remove_node(pos,oldnode,oldmeta)
end
olddig(pos,oldnode,oldmeta,digger)
end
techage.NodeDef[name] = {on_recv_message = function(pos,src,message,arg)
minetest.registered_nodes[name].digiline.effector.action(pos,minetest.get_node(pos),string.format("techage_%d",src),{message=message,arg=arg})
end}
end
end
end
end
minetest.registered_nodes["mesecons_luacontroller:luacontroller_burnt"].after_dig_node = function(pos,oldnode,oldmeta)
if oldmeta:get_int("techage_assigned") > 0 then
techage.remove_node(pos,oldnode,oldmeta)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment