From f72717e8de0c9bf05c62717187dbeaad5a313690 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 13 Jan 2018 02:20:07 +0100 Subject: [PATCH] Support powering of opaque blocks (WIP) --- mods/ITEMS/REDSTONE/mesecons/init.lua | 20 +++++++ mods/ITEMS/REDSTONE/mesecons/internal.lua | 13 +++-- mods/ITEMS/REDSTONE/mesecons/presets.lua | 70 +++++++++++------------ mods/ITEMS/REDSTONE/mesecons/util.lua | 19 ++++++ 4 files changed, 83 insertions(+), 39 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons/init.lua b/mods/ITEMS/REDSTONE/mesecons/init.lua index 83e611b55..57b17b5b1 100644 --- a/mods/ITEMS/REDSTONE/mesecons/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons/init.lua @@ -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) diff --git a/mods/ITEMS/REDSTONE/mesecons/internal.lua b/mods/ITEMS/REDSTONE/mesecons/internal.lua index e5ba91eb9..3f1fb7373 100644 --- a/mods/ITEMS/REDSTONE/mesecons/internal.lua +++ b/mods/ITEMS/REDSTONE/mesecons/internal.lua @@ -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 diff --git a/mods/ITEMS/REDSTONE/mesecons/presets.lua b/mods/ITEMS/REDSTONE/mesecons/presets.lua index eca3d7354..1abaae9ba 100644 --- a/mods/ITEMS/REDSTONE/mesecons/presets.lua +++ b/mods/ITEMS/REDSTONE/mesecons/presets.lua @@ -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 diff --git a/mods/ITEMS/REDSTONE/mesecons/util.lua b/mods/ITEMS/REDSTONE/mesecons/util.lua index 39f56968d..fc7e1f2e5 100644 --- a/mods/ITEMS/REDSTONE/mesecons/util.lua +++ b/mods/ITEMS/REDSTONE/mesecons/util.lua @@ -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