1
0
Fork 0

Support powering of opaque blocks (WIP)

This commit is contained in:
Wuzzy 2018-01-13 02:20:07 +01:00
parent c4ec520986
commit f72717e8de
4 changed files with 83 additions and 39 deletions

View File

@ -81,6 +81,13 @@ mesecon.queue:add_function("receptor_on", function (pos, rules)
for _, rulename in ipairs(rulenames) do for _, rulename in ipairs(rulenames) do
mesecon.turnon(np, rulename) mesecon.turnon(np, rulename)
end end
if rule.spread then
if minetest.get_item_group(minetest.get_node(np).name, "opaque") == 1 then
for _, neighbor in ipairs(mesecon.mcl_get_neighbors(np)) do
mesecon.turnon(neighbor.pos, vector.add(rule, neighbor.link))
end
end
end
end end
mesecon.vm_commit() mesecon.vm_commit()
@ -110,6 +117,19 @@ mesecon.queue:add_function("receptor_off", function (pos, rules)
mesecon.vm_abort() mesecon.vm_abort()
end end
end end
if rule.spread then
if minetest.get_item_group(minetest.get_node(np).name, "opaque") == 1 then
for _, neighbor in ipairs(mesecon.mcl_get_neighbors(np)) do
mesecon.vm_begin()
mesecon.changesignal(neighbor.pos, minetest.get_node(neighbor.pos), vector.add(rule, neighbor.link), mesecon.state.off, 2)
if (mesecon.turnoff(neighbor.pos, vector.add(rule, neighbor.link))) then
mesecon.vm_commit()
else
mesecon.vm_abort()
end
end
end
end
end end
end) end)

View File

@ -398,6 +398,7 @@ function mesecon.turnon(pos, link)
mesecon.activate(f.pos, node, f.link, depth) mesecon.activate(f.pos, node, f.link, depth)
end end
end end
depth = depth + 1 depth = depth + 1
end end
end end
@ -557,7 +558,8 @@ function mesecon.rotate_rules_right(rules)
x = -rule.z, x = -rule.z,
y = rule.y, y = rule.y,
z = rule.x, z = rule.x,
name = rule.name}) name = rule.name,
spread = rule.spread,})
end end
return nr return nr
end end
@ -569,7 +571,8 @@ function mesecon.rotate_rules_left(rules)
x = rule.z, x = rule.z,
y = rule.y, y = rule.y,
z = -rule.x, z = -rule.x,
name = rule.name}) name = rule.name,
spread = rule.spread,})
end end
return nr return nr
end end
@ -581,7 +584,8 @@ function mesecon.rotate_rules_down(rules)
x = -rule.y, x = -rule.y,
y = rule.x, y = rule.x,
z = rule.z, z = rule.z,
name = rule.name}) name = rule.name,
spread = rule.spread,})
end end
return nr return nr
end end
@ -593,7 +597,8 @@ function mesecon.rotate_rules_up(rules)
x = rule.y, x = rule.y,
y = -rule.x, y = -rule.x,
z = rule.z, z = rule.z,
name = rule.name}) name = rule.name,
spread = rule.spread,})
end end
return nr return nr
end end

View File

@ -6,6 +6,9 @@ mesecon.rules.default =
{x=1, y=0, z=0}, {x=1, y=0, z=0},
{x=-1, y=0, z=0}, {x=-1, y=0, z=0},
{x=0, y=0, z=1}, {x=0, y=0, z=1},
{x=0, y=1, z=0},
{x=0, y=-1, z=0},
{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=-1, y=1, z=0}, {x=-1, y=1, z=0},
@ -16,6 +19,37 @@ mesecon.rules.default =
{x=0, y=-1, z=-1}} {x=0, y=-1, z=-1}}
mesecon.rules.alldirs = mesecon.rules.alldirs =
{{x= 1, y= 0, z= 0, spread = true},
{x=-1, y= 0, z= 0, spread = true},
{x= 0, y= 1, z= 0, spread = true},
{x= 0, y=-1, z= 0, spread = true},
{x= 0, y= 0, z= 1, spread = true},
{x= 0, y= 0, z=-1, spread = true}}
mesecon.rules.pplate =
{{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y =-1, z = 0, spread = true},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1}}
mesecon.rules.buttonlike =
{{x = 0, y = 0, z =-1},
{x = 0, y = 0, z = 1},
{x = 0, y =-1, z = 0},
{x = 0, y = 1, z = 0},
{x =-1, y = 0, z = 0},
{x = 1, y = 0, z = 0, spread = true}}
mesecon.rules.flat =
{{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1}}
-- NOT IN ORIGNAL MESECONS
mesecon.rules.mcl_alldirs_short =
{{x= 1, y= 0, z= 0}, {{x= 1, y= 0, z= 0},
{x=-1, y= 0, z= 0}, {x=-1, y= 0, z= 0},
{x= 0, y= 1, z= 0}, {x= 0, y= 1, z= 0},
@ -23,41 +57,7 @@ mesecon.rules.alldirs =
{x= 0, y= 0, z= 1}, {x= 0, y= 0, z= 1},
{x= 0, y= 0, z=-1}} {x= 0, y= 0, z=-1}}
mesecon.rules.pplate = -- END OF UNOFFICIAL RULES
{{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y =-1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1},
{x = 0, y = -2, 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}}
mesecon.rules.buttonlike =
{{x = 1, y = 0, z = 0},
{x = 1, y = 1, z = 0},
{x = 1, y =-1, z = 0},
{x = 1, y = 0, z =-1},
{x = 1, y = 0, z = 1},
{x = 2, y = 0, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y = -1, z = 0},
{x =-1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1}}
mesecon.rules.flat =
{{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1},
{x = 2, y = 0, z = 0},
{x =-2, y = 0, z = 0},
{x = 0, y = 0, z = 2},
{x = 0, y = 0, z =-2}}
mesecon.rules.buttonlike_get = function(node) mesecon.rules.buttonlike_get = function(node)
local rules = mesecon.rules.buttonlike local rules = mesecon.rules.buttonlike

View File

@ -90,6 +90,25 @@ function mesecon.rule2meta(findrule, allrules)
return allrules[index] return allrules[index]
end end
-- Returns the 6 immediate neighbors of pos
-- (nodes which touch the sides of pos).
-- NOT PART OF ORIGINAL MESECONS!
function mesecon.mcl_get_neighbors(pos)
local r = {
{ x= 0, y= 0, z=-1 },
{ x= 0, y= 0, z= 1 },
{ x= 0, y=-1, z= 0 },
{ x= 0, y= 1, z= 0 },
{ x=-1, y= 0, z= 0 },
{ x= 1, y= 0, z= 0 },
}
local e = {}
for i=1, #r do
table.insert(e, { pos = vector.add(pos, r[i]), link = r[i] })
end
return e
end
function mesecon.dec2bin(n) function mesecon.dec2bin(n)
local x, y = math.floor(n / 2), n % 2 local x, y = math.floor(n / 2), n % 2
if (n > 1) then if (n > 1) then