diff options
Diffstat (limited to 'mesecons')
-rw-r--r-- | mesecons/internal.lua | 49 | ||||
-rw-r--r-- | mesecons/presets.lua | 128 | ||||
-rw-r--r-- | mesecons/services.lua | 10 | ||||
-rw-r--r-- | mesecons/util.lua | 51 |
4 files changed, 136 insertions, 102 deletions
diff --git a/mesecons/internal.lua b/mesecons/internal.lua index e5ba91e..6fdc3f9 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -548,52 +548,3 @@ function mesecon.is_powered(pos, rule) if (#sourcepos == 0) then return false else return sourcepos end end - ---Rules rotation Functions: -function mesecon.rotate_rules_right(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = -rule.z, - y = rule.y, - z = rule.x, - name = rule.name}) - end - return nr -end - -function mesecon.rotate_rules_left(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = rule.z, - y = rule.y, - z = -rule.x, - name = rule.name}) - end - return nr -end - -function mesecon.rotate_rules_down(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = -rule.y, - y = rule.x, - z = rule.z, - name = rule.name}) - end - return nr -end - -function mesecon.rotate_rules_up(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = rule.y, - y = -rule.x, - z = rule.z, - name = rule.name}) - end - return nr -end diff --git a/mesecons/presets.lua b/mesecons/presets.lua index 8c3ed67..a2062d9 100644 --- a/mesecons/presets.lua +++ b/mesecons/presets.lua @@ -1,61 +1,85 @@ mesecon.rules = {} mesecon.state = {} -mesecon.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}} - -mesecon.rules.pplate = mesecon.mergetable(mesecon.rules.default, {{x=0, y=-2, z=0}}) - -mesecon.rules.buttonlike = -{{x = 1, y = 0, z = 0}, - {x = 1, y = 1, z = 0}, - {x = 1, y =-1, z = 0}, - {x = 1, y =-1, z = 1}, - {x = 1, y =-1, z =-1}, - {x = 2, y = 0, z = 0}} - -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}} - -mesecon.rules.alldirs = -{{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}} +mesecon.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}, +} + +mesecon.rules.floor = mesecon.mergetable(mesecon.rules.default, {{x = 0, y = -1, z = 0}}) + +mesecon.rules.pplate = mesecon.mergetable(mesecon.rules.floor, {{x = 0, y = -2, z = 0}}) + +mesecon.rules.buttonlike = { + {x = 1, y = 0, z = 0}, + {x = 1, y = 1, z = 0}, + {x = 1, y = -1, z = 0}, + {x = 1, y = -1, z = 1}, + {x = 1, y = -1, z = -1}, + {x = 2, y = 0, z = 0}, +} + +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}, +} + +mesecon.rules.alldirs = { + {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}, +} + +local rules_wallmounted = { + xp = mesecon.rotate_rules_down(mesecon.rules.floor), + xn = mesecon.rotate_rules_up(mesecon.rules.floor), + yp = mesecon.rotate_rules_up(mesecon.rotate_rules_up(mesecon.rules.floor)), + yn = mesecon.rules.floor, + zp = mesecon.rotate_rules_left(mesecon.rotate_rules_up(mesecon.rules.floor)), + zn = mesecon.rotate_rules_right(mesecon.rotate_rules_up(mesecon.rules.floor)), +} + +local rules_buttonlike = { + xp = mesecon.rules.buttonlike, + xn = mesecon.rotate_rules_right(mesecon.rotate_rules_right(mesecon.rules.buttonlike)), + yp = mesecon.rotate_rules_down(mesecon.rules.buttonlike), + yn = mesecon.rotate_rules_up(mesecon.rules.buttonlike), + zp = mesecon.rotate_rules_right(mesecon.rules.buttonlike), + zn = mesecon.rotate_rules_left(mesecon.rules.buttonlike), +} + +local function rules_from_dir(ruleset, dir) + if dir.x == 1 then return ruleset.xp end + if dir.y == 1 then return ruleset.yp end + if dir.z == 1 then return ruleset.zp end + if dir.x == -1 then return ruleset.xn end + if dir.y == -1 then return ruleset.yn end + if dir.z == -1 then return ruleset.zn end +end + +mesecon.rules.wallmounted_get = function(node) + local dir = minetest.wallmounted_to_dir(node.param2) + return rules_from_dir(rules_wallmounted, dir) +end mesecon.rules.buttonlike_get = function(node) - local rules = mesecon.rules.buttonlike local dir = minetest.facedir_to_dir(node.param2) - if dir.x == 1 then - -- No action needed - elseif dir.z == -1 then - rules=mesecon.rotate_rules_left(rules) - elseif dir.x == -1 then - rules=mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) - elseif dir.z == 1 then - rules=mesecon.rotate_rules_right(rules) - elseif dir.y == -1 then - rules=mesecon.rotate_rules_up(rules) - elseif dir.y == 1 then - rules=mesecon.rotate_rules_down(rules) - end - return rules + return rules_from_dir(rules_buttonlike, dir) end mesecon.state.on = "on" diff --git a/mesecons/services.lua b/mesecons/services.lua index 1e12de0..b1388ec 100644 --- a/mesecons/services.lua +++ b/mesecons/services.lua @@ -21,7 +21,8 @@ mesecon.on_placenode = function(pos, node) end --mesecon.receptor_on (pos, mesecon.conductor_get_rules(node)) elseif mesecon.is_conductor_on(node) then - minetest.swap_node(pos, {name = mesecon.get_conductor_off(node)}) + node.name = mesecon.get_conductor_off(node) + minetest.swap_node(pos, node) end end @@ -62,6 +63,13 @@ mesecon.on_dignode = function(pos, node) mesecon.execute_autoconnect_hooks_queue(pos, node) end +function mesecon.on_blastnode(pos, intensity) + local node = minetest.get_node(pos) + minetest.remove_node(pos) + mesecon.on_dignode(pos, node) + return minetest.get_node_drops(node.name, "") +end + minetest.register_on_placenode(mesecon.on_placenode) minetest.register_on_dignode(mesecon.on_dignode) diff --git a/mesecons/util.lua b/mesecons/util.lua index 39f5696..b15858d 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -6,6 +6,56 @@ function mesecon.move_node(pos, newpos) minetest.get_meta(pos):from_table(meta) end +-- Rules rotation Functions: +function mesecon.rotate_rules_right(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = -rule.z, + y = rule.y, + z = rule.x, + name = rule.name}) + end + return nr +end + +function mesecon.rotate_rules_left(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = rule.z, + y = rule.y, + z = -rule.x, + name = rule.name}) + end + return nr +end + +function mesecon.rotate_rules_down(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = -rule.y, + y = rule.x, + z = rule.z, + name = rule.name}) + end + return nr +end + +function mesecon.rotate_rules_up(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = rule.y, + y = -rule.x, + z = rule.z, + name = rule.name}) + end + return nr +end +-- + function mesecon.flattenrules(allrules) --[[ { @@ -178,6 +228,7 @@ end function mesecon.register_node(name, spec_common, spec_off, spec_on) spec_common.drop = spec_common.drop or name .. "_off" + spec_common.on_blast = spec_common.on_blast or mesecon.on_blastnode spec_common.__mesecon_basename = name spec_on.__mesecon_state = "on" spec_off.__mesecon_state = "off" |