diff --git a/test3d_t416/depends.txt b/test3d_t416/depends.txt new file mode 100644 index 0000000..2cec86e --- /dev/null +++ b/test3d_t416/depends.txt @@ -0,0 +1,2 @@ +default +digilines diff --git a/test3d_t416/init.lua b/test3d_t416/init.lua new file mode 100644 index 0000000..a8a88b3 --- /dev/null +++ b/test3d_t416/init.lua @@ -0,0 +1,80 @@ +local MEMSIZE=16 +if not digiline then + print("Digilines not found.") + return +end +local oldprint=print +local function print(...) + for k,v in ipairs({...}) do + oldprint("[Test3D:T416] "..tostring(v)) + end +end +print("Loading.") + +local function t416_digiline_receive(pos, node, channel, msg) + print("Digiline: "..tostring(pos.x)..","..tostring(pos.y)..","..tostring(pos.z).."; Channel: "..tostring(channel).."; Message: "..tostring(msg)) + local meta = minetest.get_meta(pos) + local mem = string.split(meta:get_string("mem"),"\n") + local ms = "" + local chan = meta:get_string("channel") + local memoffset = meta:get_int("startaddr") + if channel:sub(1,#chan) == chan and tonumber(channel:sub(#chan+1),16)+1-memoffset <= MEMSIZE and tonumber(channel:sub(#chan+1),16)+1-memoffset > 0 then + local memaddr = tonumber(channel:sub(#chan+1),16)+1-memoffset + print(memaddr) + if tostring(msg):lower() == "get" then + digiline:receptor_send(pos, digiline.rules.default, channel, tonumber(mem[memaddr] or 0)) + print("Reading address "..tostring(memaddr)..": "..tostring(mem[memaddr])) + else + mem[memaddr] = tonumber(msg) or 0 + for k,v in ipairs(mem) do + ms = ms .. tostring(v) .. "\n" + end + meta:set_string("mem",ms) + print("Set address "..tostring(memaddr).." to "..tostring(tonumber(msg))) + end + end +end +print("Created T416 digiline function") + +local function t416_set_meta(pos) + local meta = minetest.get_meta(pos) + local ms = "" + for i = 1, 16 do + ms = ms .. "0\n" + end + meta:set_string("mem",ms) + meta:set_string("channel","Default") + meta:set_int("startaddr",0) + meta:set_string("formspec","size[5,12]\nlabel[0.4,0.5;T416 Memory Node (16 words)]\nfield[0.5,2;4,1;channel;Channel prefix;${channel}]\nfield[0.5,3;4,1;startaddr;Starting address;${startaddr}]\ntextarea[0.5,4;4,8;mem;Memory contents;${mem}]") +end +minetest.register_node("test3d_t416:t416", { + description = "T416 Memory Node", + tiles = { + { + image="t416.png", + animation={ + type = "vertical_frames", + aspect_w=16, + aspect_h=16, + length=18, + length=1.8, + }, + }, + }, + on_construct = t416_set_meta, + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, + digiline = { + receptor = {}, + effector = { + action = t416_digiline_receive + } + }, + on_receive_fields = function(pos,_,fields,sender) + if fields.channel == nil then return end + local meta = minetest.get_meta(pos) + fields.channel = fields.channel or "" + meta:set_string("channel",fields.channel) + meta:set_int("startaddr",tonumber(fields.startaddr)) + end +}) +print("T416 node registered") diff --git a/test3d_t416/textures/t416.png b/test3d_t416/textures/t416.png new file mode 100644 index 0000000..e5bfed3 Binary files /dev/null and b/test3d_t416/textures/t416.png differ