summaryrefslogtreecommitdiff
path: root/digilines/digilines
diff options
context:
space:
mode:
Diffstat (limited to 'digilines/digilines')
-rw-r--r--digilines/digilines/depends.txt1
-rw-r--r--digilines/digilines/init.lua25
-rw-r--r--digilines/digilines/internal.lua92
-rw-r--r--digilines/digilines/presetrules.lua15
-rw-r--r--digilines/digilines/textures/digiline_std.pngbin0 -> 446 bytes
-rw-r--r--digilines/digilines/textures/digiline_std_bump.pngbin0 -> 410 bytes
-rw-r--r--digilines/digilines/textures/digiline_std_inv.pngbin0 -> 196 bytes
-rw-r--r--digilines/digilines/textures/digiline_std_vertical.pngbin0 -> 378 bytes
-rw-r--r--digilines/digilines/util.lua67
-rw-r--r--digilines/digilines/wire_std.lua118
-rw-r--r--digilines/digilines/wires_common.lua88
11 files changed, 406 insertions, 0 deletions
diff --git a/digilines/digilines/depends.txt b/digilines/digilines/depends.txt
new file mode 100644
index 0000000..4ad96d5
--- /dev/null
+++ b/digilines/digilines/depends.txt
@@ -0,0 +1 @@
+default
diff --git a/digilines/digilines/init.lua b/digilines/digilines/init.lua
new file mode 100644
index 0000000..92f916d
--- /dev/null
+++ b/digilines/digilines/init.lua
@@ -0,0 +1,25 @@
+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
+
+minetest.register_craft({
+ output = 'digilines:wire_std_00000000 2',
+ recipe = {
+ {'mesecons_materials:fiber', 'mesecons_materials:fiber', 'mesecons_materials:fiber'},
+ {'mesecons_insulated:insulated_off', 'mesecons_insulated:insulated_off', 'default:gold_ingot'},
+ {'mesecons_materials:fiber', 'mesecons_materials:fiber', 'mesecons_materials:fiber'},
+ }
+}) \ No newline at end of file
diff --git a/digilines/digilines/internal.lua b/digilines/digilines/internal.lua
new file mode 100644
index 0000000..f29cc8d
--- /dev/null
+++ b/digilines/digilines/internal.lua
@@ -0,0 +1,92 @@
+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.get_node(pos)
+ local 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.get_node(pos)
+ local 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)
+ local checkedid = tostring(pos.x).."_"..tostring(pos.y).."_"..tostring(pos.z)
+ if checked[checkedid] then return end
+ checked[checkedid] = true
+
+ local node = minetest.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
+ digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked)
+ end
+ end
+ end
+end
diff --git a/digilines/digilines/presetrules.lua b/digilines/digilines/presetrules.lua
new file mode 100644
index 0000000..8d5e35b
--- /dev/null
+++ b/digilines/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/digilines/textures/digiline_std.png b/digilines/digilines/textures/digiline_std.png
new file mode 100644
index 0000000..721797c
--- /dev/null
+++ b/digilines/digilines/textures/digiline_std.png
Binary files differ
diff --git a/digilines/digilines/textures/digiline_std_bump.png b/digilines/digilines/textures/digiline_std_bump.png
new file mode 100644
index 0000000..068a4a9
--- /dev/null
+++ b/digilines/digilines/textures/digiline_std_bump.png
Binary files differ
diff --git a/digilines/digilines/textures/digiline_std_inv.png b/digilines/digilines/textures/digiline_std_inv.png
new file mode 100644
index 0000000..f66f6c7
--- /dev/null
+++ b/digilines/digilines/textures/digiline_std_inv.png
Binary files differ
diff --git a/digilines/digilines/textures/digiline_std_vertical.png b/digilines/digilines/textures/digiline_std_vertical.png
new file mode 100644
index 0000000..1de0ead
--- /dev/null
+++ b/digilines/digilines/textures/digiline_std_vertical.png
Binary files differ
diff --git a/digilines/digilines/util.lua b/digilines/digilines/util.lua
new file mode 100644
index 0000000..d138d63
--- /dev/null
+++ b/digilines/digilines/util.lua
@@ -0,0 +1,67 @@
+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
+
+function digiline:tablecopy(table) -- deep table copy
+ if type(table) ~= "table" then return table end -- no need to copy
+ local newtable = {}
+
+ for idx, item in pairs(table) do
+ if type(item) == "table" then
+ newtable[idx] = digiline:tablecopy(item)
+ else
+ newtable[idx] = item
+ end
+ end
+
+ return newtable
+end
diff --git a/digilines/digilines/wire_std.lua b/digilines/digilines/wire_std.lua
new file mode 100644
index 0000000..71bbd0f
--- /dev/null
+++ b/digilines/digilines/wire_std.lua
@@ -0,0 +1,118 @@
+-- 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_",
+ use_autoconnect = true
+ }
+ },
+ 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/digilines/wires_common.lua b/digilines/digilines/wires_common.lua
new file mode 100644
index 0000000..c5f761b
--- /dev/null
+++ b/digilines/digilines/wires_common.lua
@@ -0,0 +1,88 @@
+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 def = minetest.registered_nodes[minetest.get_node(pos).name]
+ local digilinespec = def and def.digiline
+ if not (digilinespec and digilinespec.wire and
+ digilinespec.wire.use_autoconnect) 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)
+
+ local zm, xm, zp, xp, xpy, zpy, xmy, zmy
+ 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.set_node(pos, {name = digilinespec.wire.basename..nodeid})
+end