mirror of
https://github.com/minetest-mods/digilines.git
synced 2024-12-23 17:20:20 +01:00
Initial Upload
This commit is contained in:
commit
3a1bf374fe
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*~
|
1
digilines/depends.txt
Normal file
1
digilines/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default
|
16
digilines/init.lua
Normal file
16
digilines/init.lua
Normal file
@ -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
|
94
digilines/internal.lua
Normal file
94
digilines/internal.lua
Normal file
@ -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
|
15
digilines/presetrules.lua
Normal file
15
digilines/presetrules.lua
Normal file
@ -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}}
|
BIN
digilines/textures/digiline_std.png
Normal file
BIN
digilines/textures/digiline_std.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 446 B |
BIN
digilines/textures/digiline_std_bump.png
Normal file
BIN
digilines/textures/digiline_std_bump.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 410 B |
BIN
digilines/textures/digiline_std_inv.png
Normal file
BIN
digilines/textures/digiline_std_inv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 196 B |
BIN
digilines/textures/digiline_std_vertical.png
Normal file
BIN
digilines/textures/digiline_std_vertical.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 378 B |
52
digilines/util.lua
Normal file
52
digilines/util.lua
Normal file
@ -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
|
117
digilines/wire_std.lua
Normal file
117
digilines/wire_std.lua
Normal file
@ -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
|
84
digilines/wires_common.lua
Normal file
84
digilines/wires_common.lua
Normal file
@ -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
|
0
modpack.txt
Normal file
0
modpack.txt
Normal file
Loading…
Reference in New Issue
Block a user