commit 3a1bf374fe75fe2d200a95057e6c5f8b4881bc5d Author: Jeija Date: Sun Jan 20 00:03:51 2013 +0100 Initial Upload diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/digilines/depends.txt b/digilines/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/digilines/depends.txt @@ -0,0 +1 @@ +default diff --git a/digilines/init.lua b/digilines/init.lua new file mode 100644 index 0000000..b794b9e --- /dev/null +++ b/digilines/init.lua @@ -0,0 +1,16 @@ +digiline = {} +dofile(minetest.get_modpath("digilines").."/presetrules.lua") +dofile(minetest.get_modpath("digilines").."/util.lua") +dofile(minetest.get_modpath("digilines").."/internal.lua") +dofile(minetest.get_modpath("digilines").."/wires_common.lua") +dofile(minetest.get_modpath("digilines").."/wire_std.lua") + +function digiline:receptor_send(pos, rules, channel, msg) + local checked = {} + checked[tostring(pos.x).."_"..tostring(pos.y).."_"..tostring(pos.z)] = true -- exclude itself + for _,rule in ipairs(rules) do + if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then + digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked) + end + end +end diff --git a/digilines/internal.lua b/digilines/internal.lua new file mode 100644 index 0000000..ce4012c --- /dev/null +++ b/digilines/internal.lua @@ -0,0 +1,94 @@ +function digiline:getspec(node) + if not minetest.registered_nodes[node.name] then return false end + return minetest.registered_nodes[node.name].digiline +end + +function digiline:importrules(spec, node) + if type(spec) == 'function' then + return spec(node) + elseif spec then + return spec + else + return digiline.rules.default + end +end + +function digiline:getAnyInputRules(pos) + local node = minetest.env:get_node(pos) + spec = digiline:getspec(node) + if not spec then return end + + if spec.wire then + return digiline:importrules(spec.wire.rules, node) + end + if spec.effector then + return digiline:importrules(spec.effector.rules, node) + end + + return rules +end + +function digiline:getAnyOutputRules(pos) + local node = minetest.env:get_node(pos) + spec = digiline:getspec(node) + if not spec then return end + + if spec.wire then + return digiline:importrules(spec.wire.rules, node) + end + if spec.receptor then + return digiline:importrules(spec.receptor.rules, node) + end +end + +function digiline:rules_link(output, input) + local outputrules = digiline:getAnyOutputRules(output) + local inputrules = digiline:getAnyInputRules (input) + + if not outputrules or not inputrules then return false end + + + for _, orule in ipairs(outputrules) do + if digiline:cmpPos(digiline:addPosRule(output, orule), input) then + for _, irule in ipairs(inputrules) do + if digiline:cmpPos(digiline:addPosRule(input, irule), output) then + return true + end + end + end + end + return false +end + +function digiline:rules_link_anydir(output, input) + return digiline:rules_link(output, input) + or digiline:rules_link(input, output) +end + +function digiline:transmit(pos, channel, msg, checked) + checked = checked or {} + local checkedid = tostring(pos.x).."_"..tostring(pos.y).."_"..tostring(pos.z) + if checked[checkedid] then return checked end + checked[checkedid] = true + + local node = minetest.env:get_node(pos) + local spec = digiline:getspec(node) + if not spec then return end + + + -- Effector actions --> Receive + if spec.effector then + spec.effector.action(pos, node, channel, msg) + end + + -- Cable actions --> Transmit + if spec.wire then + local rules = digiline:importrules(spec.wire.rules, node) + for _,rule in ipairs(rules) do + if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then + checked = digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked) + end + end + end + return checked +end diff --git a/digilines/presetrules.lua b/digilines/presetrules.lua new file mode 100644 index 0000000..8d5e35b --- /dev/null +++ b/digilines/presetrules.lua @@ -0,0 +1,15 @@ +digiline.rules = {} + +digiline.rules.default = +{{x=0, y=0, z=-1}, +{x=1, y=0, z=0}, +{x=-1, y=0, z=0}, +{x=0, y=0, z=1}, +{x=1, y=1, z=0}, +{x=1, y=-1, z=0}, +{x=-1, y=1, z=0}, +{x=-1, y=-1, z=0}, +{x=0, y=1, z=1}, +{x=0, y=-1, z=1}, +{x=0, y=1, z=-1}, +{x=0, y=-1, z=-1}} diff --git a/digilines/textures/digiline_std.png b/digilines/textures/digiline_std.png new file mode 100644 index 0000000..721797c Binary files /dev/null and b/digilines/textures/digiline_std.png differ diff --git a/digilines/textures/digiline_std_bump.png b/digilines/textures/digiline_std_bump.png new file mode 100644 index 0000000..068a4a9 Binary files /dev/null and b/digilines/textures/digiline_std_bump.png differ diff --git a/digilines/textures/digiline_std_inv.png b/digilines/textures/digiline_std_inv.png new file mode 100644 index 0000000..f66f6c7 Binary files /dev/null and b/digilines/textures/digiline_std_inv.png differ diff --git a/digilines/textures/digiline_std_vertical.png b/digilines/textures/digiline_std_vertical.png new file mode 100644 index 0000000..1de0ead Binary files /dev/null and b/digilines/textures/digiline_std_vertical.png differ diff --git a/digilines/util.lua b/digilines/util.lua new file mode 100644 index 0000000..dad6579 --- /dev/null +++ b/digilines/util.lua @@ -0,0 +1,52 @@ +function digiline:addPosRule(p, r) + return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z} +end + +function digiline:cmpPos(p1, p2) + return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z) +end + +--Rules rotation Functions: +function digiline:rotate_rules_right(rules) + local nr={} + for i, rule in ipairs(rules) do + nr[i]={} + nr[i].z=rule.x + nr[i].x=-rule.z + nr[i].y=rule.y + end + return nr +end + +function digiline:rotate_rules_left(rules) + local nr={} + for i, rule in ipairs(rules) do + nr[i]={} + nr[i].z=-rules[i].x + nr[i].x=rules[i].z + nr[i].y=rules[i].y + end + return nr +end + +function digiline:rotate_rules_down(rules) + local nr={} + for i, rule in ipairs(rules) do + nr[i]={} + nr[i].y=rule.x + nr[i].x=-rule.y + nr[i].z=rule.z + end + return nr +end + +function digiline:rotate_rules_up(rules) + local nr={} + for i, rule in ipairs(rules) do + nr[i]={} + nr[i].y=-rule.x + nr[i].x=rule.y + nr[i].z=rule.z + end + return nr +end diff --git a/digilines/wire_std.lua b/digilines/wire_std.lua new file mode 100644 index 0000000..32645e9 --- /dev/null +++ b/digilines/wire_std.lua @@ -0,0 +1,117 @@ +-- naming scheme: wire:(xp)(zp)(xm)(zm)_on/off +-- The conditions in brackets define whether there is a digiline at that place or not +-- 1 = there is one; 0 = there is none +-- y always means y+ + +box_center = {-1/16, -.5, -1/16, 1/16, -.5+1/16, 1/16} +box_bump1 = { -2/16, -8/16, -2/16, 2/16, -13/32, 2/16 } +box_bump2 = { -3/32, -13/32, -3/32, 3/32, -12/32, 3/32 } + +box_xp = {1/16, -.5, -1/16, 8/16, -.5+1/16, 1/16} +box_zp = {-1/16, -.5, 1/16, 1/16, -.5+1/16, 8/16} +box_xm = {-8/16, -.5, -1/16, -1/16, -.5+1/16, 1/16} +box_zm = {-1/16, -.5, -8/16, 1/16, -.5+1/16, -1/16} + +box_xpy = {.5-1/16, -.5+1/16, -1/16, .5, .4999+1/16, 1/16} +box_zpy = {-1/16, -.5+1/16, .5-1/16, 1/16, .4999+1/16, .5} +box_xmy = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/16, 1/16} +box_zmy = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/16, -.5+1/16} + +for xp=0, 1 do +for zp=0, 1 do +for xm=0, 1 do +for zm=0, 1 do +for xpy=0, 1 do +for zpy=0, 1 do +for xmy=0, 1 do +for zmy=0, 1 do + if (xpy == 1 and xp == 0) or (zpy == 1 and zp == 0) + or (xmy == 1 and xm == 0) or (zmy == 1 and zm == 0) then break end + + local groups + local nodeid = tostring(xp )..tostring(zp )..tostring(xm )..tostring(zm ).. + tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy) + + if nodeid == "00000000" then + groups = {dig_immediate = 3} + wiredesc = "Digiline" + else + groups = {dig_immediate = 3, not_in_creative_inventory = 1} + end + + local nodebox = {} + local adjx = false + local adjz = false + if xp == 1 then table.insert(nodebox, box_xp) adjx = true end + if zp == 1 then table.insert(nodebox, box_zp) adjz = true end + if xm == 1 then table.insert(nodebox, box_xm) adjx = true end + if zm == 1 then table.insert(nodebox, box_zm) adjz = true end + if xpy == 1 then table.insert(nodebox, box_xpy) end + if zpy == 1 then table.insert(nodebox, box_zpy) end + if xmy == 1 then table.insert(nodebox, box_xmy) end + if zmy == 1 then table.insert(nodebox, box_zmy) end + + if adjx and adjz and (xp + zp + xm + zm > 2) then + table.insert(nodebox, box_bump1) + table.insert(nodebox, box_bump2) + tiles = { + "digiline_std_bump.png", + "digiline_std_bump.png", + "digiline_std_vertical.png", + "digiline_std_vertical.png", + "digiline_std_vertical.png", + "digiline_std_vertical.png" + } + else + table.insert(nodebox, box_center) + tiles = { + "digiline_std.png", + "digiline_std.png", + "digiline_std_vertical.png", + "digiline_std_vertical.png", + "digiline_std_vertical.png", + "digiline_std_vertical.png" + } + end + + if nodeid == "00000000" then + nodebox = {-8/16, -.5, -1/16, 8/16, -.5+1/16, 1/16} + end + + minetest.register_node("digilines:wire_std_"..nodeid, { + description = wiredesc, + drawtype = "nodebox", + tiles = tiles, + inventory_image = "digiline_std_inv.png", + wield_image = "digiline_std_inv.png", + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + digiline = + { + wire = + { + basename = "digilines:wire_std_" + } + }, + selection_box = { + type = "fixed", + fixed = {-.5, -.5, -.5, .5, -.5+1/16, .5} + }, + node_box = { + type = "fixed", + fixed = nodebox + }, + groups = groups, + walkable = false, + stack_max = 99, + drop = "digilines:wire_std_00000000" + }) +end +end +end +end +end +end +end +end diff --git a/digilines/wires_common.lua b/digilines/wires_common.lua new file mode 100644 index 0000000..4370241 --- /dev/null +++ b/digilines/wires_common.lua @@ -0,0 +1,84 @@ +minetest.register_on_placenode(function(pos, node) + if minetest.registered_nodes[node.name].digiline then + digiline:update_autoconnect(pos) + end +end) + +minetest.register_on_dignode(function(pos, node) + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].digiline then +-- need to make sure that node exists (unknown nodes!) + digiline:update_autoconnect(pos) + end +end) + +function digiline:update_autoconnect(pos, secondcall) + local xppos = {x=pos.x+1, y=pos.y, z=pos.z} + local zppos = {x=pos.x, y=pos.y, z=pos.z+1} + local xmpos = {x=pos.x-1, y=pos.y, z=pos.z} + local zmpos = {x=pos.x, y=pos.y, z=pos.z-1} + local xpympos = {x=pos.x+1, y=pos.y-1, z=pos.z} + local zpympos = {x=pos.x, y=pos.y-1, z=pos.z+1} + local xmympos = {x=pos.x-1, y=pos.y-1, z=pos.z} + local zmympos = {x=pos.x, y=pos.y-1, z=pos.z-1} + local xpypos = {x=pos.x+1, y=pos.y+1, z=pos.z} + local zpypos = {x=pos.x, y=pos.y+1, z=pos.z+1} + local xmypos = {x=pos.x-1, y=pos.y+1, z=pos.z} + local zmypos = {x=pos.x, y=pos.y+1, z=pos.z-1} + + if secondcall == nil then + digiline:update_autoconnect(xppos, true) + digiline:update_autoconnect(zppos, true) + digiline:update_autoconnect(xmpos, true) + digiline:update_autoconnect(zmpos, true) + + digiline:update_autoconnect(xpypos, true) + digiline:update_autoconnect(zpypos, true) + digiline:update_autoconnect(xmypos, true) + digiline:update_autoconnect(zmypos, true) + + digiline:update_autoconnect(xpympos, true) + digiline:update_autoconnect(zpympos, true) + digiline:update_autoconnect(xmympos, true) + digiline:update_autoconnect(zmympos, true) + end + + local digilinespec = minetest.registered_nodes[minetest.env:get_node(pos).name].digiline + if not digilinespec then return nil end + if not digilinespec.wire then return nil end + + local zmg = digiline:rules_link_anydir(pos, zmpos) + local zmymg = digiline:rules_link_anydir(pos, zmympos) + local xmg = digiline:rules_link_anydir(pos, xmpos) + local xmymg = digiline:rules_link_anydir(pos, xmympos) + local zpg = digiline:rules_link_anydir(pos, zppos) + local zpymg = digiline:rules_link_anydir(pos, zpympos) + local xpg = digiline:rules_link_anydir(pos, xppos) + local xpymg = digiline:rules_link_anydir(pos, xpympos) + + + local xpyg = digiline:rules_link_anydir(pos, xpypos) + local zpyg = digiline:rules_link_anydir(pos, zpypos) + local xmyg = digiline:rules_link_anydir(pos, xmypos) + local zmyg = digiline:rules_link_anydir(pos, zmypos) + + if zmg or zmymg then zm = 1 else zm = 0 end + if xmg or xmymg then xm = 1 else xm = 0 end + if zpg or zpymg then zp = 1 else zp = 0 end + if xpg or xpymg then xp = 1 else xp = 0 end + + if xpyg then xpy = 1 else xpy = 0 end + if zpyg then zpy = 1 else zpy = 0 end + if xmyg then xmy = 1 else xmy = 0 end + if zmyg then zmy = 1 else zmy = 0 end + + if xpy == 1 then xp = 1 end + if zpy == 1 then zp = 1 end + if xmy == 1 then xm = 1 end + if zmy == 1 then zm = 1 end + + local nodeid = tostring(xp )..tostring(zp )..tostring(xm )..tostring(zm ).. + tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy) + + + minetest.env:set_node(pos, {name = digilinespec.wire.basename..nodeid}) +end diff --git a/modpack.txt b/modpack.txt new file mode 100644 index 0000000..e69de29