1
0
Fork 0

Fix incorrect power transmission of buttons

objects
Wuzzy 2018-01-13 04:08:40 +01:00
parent f612d1b584
commit 4f9be58871
5 changed files with 100 additions and 68 deletions

View File

@ -550,55 +550,4 @@ function mesecon.is_powered(pos, rule)
else return sourcepos end else return sourcepos end
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,
spread = rule.spread,})
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,
spread = rule.spread,})
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,
spread = rule.spread,})
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,
spread = rule.spread,})
end
return nr
end

View File

@ -42,12 +42,22 @@ mesecon.rules.buttonlike =
{x =-1, y = 0, z = 0}, {x =-1, y = 0, z = 0},
{x = 1, y = 0, z = 0, spread = true}} {x = 1, y = 0, z = 0, spread = true}}
mesecon.rules.floor =
{{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.flat = mesecon.rules.flat =
{{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 = 0, z =-1}} {x = 0, y = 0, z =-1}}
-- NOT IN ORIGNAL MESECONS -- NOT IN ORIGNAL MESECONS
mesecon.rules.mcl_alldirs_spread = mesecon.rules.mcl_alldirs_spread =
{{x= 1, y= 0, z= 0, spread = true}, {{x= 1, y= 0, z= 0, spread = true},
@ -59,23 +69,41 @@ mesecon.rules.mcl_alldirs_spread =
-- END OF UNOFFICIAL RULES -- END OF UNOFFICIAL RULES
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 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 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.buttonlike_get = function(node) mesecon.rules.buttonlike_get = function(node)
local rules = mesecon.rules.buttonlike
local dir = minetest.facedir_to_dir(node.param2) local dir = minetest.facedir_to_dir(node.param2)
if dir.x == 1 then return rules_from_dir(rules_buttonlike, dir)
-- No action needed end
elseif dir.z == -1 then
rules=mesecon.rotate_rules_left(rules) mesecon.rules.wallmounted_get = function(node)
elseif dir.x == -1 then local dir = minetest.wallmounted_to_dir(node.param2)
rules=mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) return rules_from_dir(rules_wallmounted, dir)
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
end end
mesecon.state.on = "on" mesecon.state.on = "on"

View File

@ -6,6 +6,59 @@ function mesecon.move_node(pos, newpos)
minetest.get_meta(pos):from_table(meta) minetest.get_meta(pos):from_table(meta)
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,
spread = rule.spread,})
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,
spread = rule.spread,})
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,
spread = rule.spread,})
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,
spread = rule.spread,})
end
return nr
end
function mesecon.flattenrules(allrules) function mesecon.flattenrules(allrules)
--[[ --[[
{ {

View File

@ -2,7 +2,7 @@
-- A button that when pressed emits power for 1 second -- A button that when pressed emits power for 1 second
-- and then turns off again -- and then turns off again
local button_get_output_rules = mesecon.rules.buttonlike_get local button_get_output_rules = mesecon.rules.wallmounted_get
local boxes_off = { local boxes_off = {
type = "wallmounted", type = "wallmounted",

View File

@ -16,7 +16,9 @@ local rotate_torch_rules = function (rules, param2)
end end
end end
local torch_get_output_rules = mesecon.rules.alldirs local torch_get_output_rules = function()
return mesecon.rules.mcl_alldirs_spread
end
local torch_get_input_rules = function(node) local torch_get_input_rules = function(node)
local rules = {{x = -2, y = 0, z = 0}, local rules = {{x = -2, y = 0, z = 0},