mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-23 00:19:32 +01:00
Support powering of opaque blocks (WIP)
This commit is contained in:
parent
c4ec520986
commit
f72717e8de
4 changed files with 83 additions and 39 deletions
|
@ -81,6 +81,13 @@ mesecon.queue:add_function("receptor_on", function (pos, rules)
|
|||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon.turnon(np, rulename)
|
||||
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
|
||||
|
||||
mesecon.vm_commit()
|
||||
|
@ -110,6 +117,19 @@ mesecon.queue:add_function("receptor_off", function (pos, rules)
|
|||
mesecon.vm_abort()
|
||||
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)
|
||||
|
||||
|
|
|
@ -398,6 +398,7 @@ function mesecon.turnon(pos, link)
|
|||
mesecon.activate(f.pos, node, f.link, depth)
|
||||
end
|
||||
end
|
||||
|
||||
depth = depth + 1
|
||||
end
|
||||
end
|
||||
|
@ -557,7 +558,8 @@ function mesecon.rotate_rules_right(rules)
|
|||
x = -rule.z,
|
||||
y = rule.y,
|
||||
z = rule.x,
|
||||
name = rule.name})
|
||||
name = rule.name,
|
||||
spread = rule.spread,})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
@ -569,7 +571,8 @@ function mesecon.rotate_rules_left(rules)
|
|||
x = rule.z,
|
||||
y = rule.y,
|
||||
z = -rule.x,
|
||||
name = rule.name})
|
||||
name = rule.name,
|
||||
spread = rule.spread,})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
@ -581,7 +584,8 @@ function mesecon.rotate_rules_down(rules)
|
|||
x = -rule.y,
|
||||
y = rule.x,
|
||||
z = rule.z,
|
||||
name = rule.name})
|
||||
name = rule.name,
|
||||
spread = rule.spread,})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
@ -593,7 +597,8 @@ function mesecon.rotate_rules_up(rules)
|
|||
x = rule.y,
|
||||
y = -rule.x,
|
||||
z = rule.z,
|
||||
name = rule.name})
|
||||
name = rule.name,
|
||||
spread = rule.spread,})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
|
|
@ -6,6 +6,9 @@ mesecon.rules.default =
|
|||
{x=1, y=0, z=0},
|
||||
{x=-1, y=0, z=0},
|
||||
{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},
|
||||
|
@ -16,6 +19,37 @@ mesecon.rules.default =
|
|||
{x=0, y=-1, z=-1}}
|
||||
|
||||
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= 0, y= 1, z= 0},
|
||||
|
@ -23,41 +57,7 @@ mesecon.rules.alldirs =
|
|||
{x= 0, y= 0, z= 1},
|
||||
{x= 0, y= 0, z=-1}}
|
||||
|
||||
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},
|
||||
{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}}
|
||||
-- END OF UNOFFICIAL RULES
|
||||
|
||||
mesecon.rules.buttonlike_get = function(node)
|
||||
local rules = mesecon.rules.buttonlike
|
||||
|
|
|
@ -90,6 +90,25 @@ function mesecon.rule2meta(findrule, allrules)
|
|||
return allrules[index]
|
||||
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)
|
||||
local x, y = math.floor(n / 2), n % 2
|
||||
if (n > 1) then
|
||||
|
|
Loading…
Reference in a new issue