diff options
Diffstat (limited to 'mesecons_microcontroller')
-rw-r--r-- | mesecons_microcontroller/init.lua | 61 | ||||
-rw-r--r-- | mesecons_microcontroller/textures/jeija_microcontroller_LED_A.png | bin | 0 -> 1240 bytes | |||
-rw-r--r-- | mesecons_microcontroller/textures/jeija_microcontroller_LED_B.png | bin | 0 -> 1239 bytes | |||
-rw-r--r-- | mesecons_microcontroller/textures/jeija_microcontroller_LED_C.png | bin | 0 -> 1240 bytes | |||
-rw-r--r-- | mesecons_microcontroller/textures/jeija_microcontroller_LED_D.png | bin | 0 -> 1239 bytes | |||
-rw-r--r-- | mesecons_microcontroller/textures/jeija_microcontroller_bottom.png | bin | 0 -> 550 bytes | |||
-rw-r--r-- | mesecons_microcontroller/textures/jeija_microcontroller_sides.png | bin | 0 -> 613 bytes | |||
-rw-r--r-- | mesecons_microcontroller/textures/jeija_microcontroller_top.png | bin | 0 -> 1151 bytes |
8 files changed, 41 insertions, 20 deletions
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 55faa5c..b6134da 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -39,7 +39,8 @@ mesecon:add_rules(nodename, rules) local mesecons = {effector = { rules = input_rules, - action_change = function (pos, node, rulename) + action_change = function (pos, node, rulename, newstate) + yc_update_real_portstates(pos, node, rulename, newstate) update_yc(pos) end }} @@ -633,25 +634,45 @@ function yc_set_portstate(port, state, L) return L end -function yc_get_real_portstates(pos) -- port powered or not (by itself or from outside)? - rulesA = mesecon:get_rules("mesecons_microcontroller:microcontroller0001") - rulesB = mesecon:get_rules("mesecons_microcontroller:microcontroller0010") - rulesC = mesecon:get_rules("mesecons_microcontroller:microcontroller0100") - rulesD = mesecon:get_rules("mesecons_microcontroller:microcontroller1000") - L = { - a = mesecon:is_power_on(mesecon:addPosRule(pos, rulesA[1]), - mesecon:invertRule(rulesA[1])) and - mesecon:rules_link(mesecon:addPosRule(pos, rulesA[1]), pos), - b = mesecon:is_power_on(mesecon:addPosRule(pos, rulesB[1]), - mesecon:invertRule(rulesB[1])) and - mesecon:rules_link(mesecon:addPosRule(pos, rulesB[1]), pos), - c = mesecon:is_power_on(mesecon:addPosRule(pos, rulesC[1]), - mesecon:invertRule(rulesC[1])) and - mesecon:rules_link(mesecon:addPosRule(pos, rulesC[1]), pos), - d = mesecon:is_power_on(mesecon:addPosRule(pos, rulesD[1]), - mesecon:invertRule(rulesD[1])) and - mesecon:rules_link(mesecon:addPosRule(pos, rulesD[1]), pos), - } +function yc_update_real_portstates(pos, node, rulename, newstate) + local meta = minetest.get_meta(pos) + if rulename == nil then + meta:set_int("real_portstates", 1) + return + end + local n = meta:get_int("real_portstates") - 1 + if n < 0 then + legacy_update_ports(pos) + n = meta:get_int("real_portstates") - 1 + end + local L = {} + for i = 1, 4 do + L[i] = n%2 + n = math.floor(n/2) + end + if rulename.x == nil then + for _, rname in ipairs(rulename) do + local port = ({4, 1, nil, 3, 2})[rname.x+2*rname.z+3] + L[port] = (newstate == "on") and 1 or 0 + end + else + local port = ({4, 1, nil, 3, 2})[rulename.x+2*rulename.z+3] + L[port] = (newstate == "on") and 1 or 0 + end + meta:set_int("real_portstates", 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4]) +end + +function yc_get_real_portstates(pos) -- determine if ports are powered (by itself or from outside) + local meta = minetest.get_meta(pos) + local L = {} + local n = meta:get_int("real_portstates") - 1 + if n < 0 then + return legacy_update_ports(pos) + end + for _, index in ipairs({"a", "b", "c", "d"}) do + L[index] = ((n%2) == 1) + n = math.floor(n/2) + end return L end diff --git a/mesecons_microcontroller/textures/jeija_microcontroller_LED_A.png b/mesecons_microcontroller/textures/jeija_microcontroller_LED_A.png Binary files differnew file mode 100644 index 0000000..64526cf --- /dev/null +++ b/mesecons_microcontroller/textures/jeija_microcontroller_LED_A.png diff --git a/mesecons_microcontroller/textures/jeija_microcontroller_LED_B.png b/mesecons_microcontroller/textures/jeija_microcontroller_LED_B.png Binary files differnew file mode 100644 index 0000000..1f7b451 --- /dev/null +++ b/mesecons_microcontroller/textures/jeija_microcontroller_LED_B.png diff --git a/mesecons_microcontroller/textures/jeija_microcontroller_LED_C.png b/mesecons_microcontroller/textures/jeija_microcontroller_LED_C.png Binary files differnew file mode 100644 index 0000000..399cc2c --- /dev/null +++ b/mesecons_microcontroller/textures/jeija_microcontroller_LED_C.png diff --git a/mesecons_microcontroller/textures/jeija_microcontroller_LED_D.png b/mesecons_microcontroller/textures/jeija_microcontroller_LED_D.png Binary files differnew file mode 100644 index 0000000..506389c --- /dev/null +++ b/mesecons_microcontroller/textures/jeija_microcontroller_LED_D.png diff --git a/mesecons_microcontroller/textures/jeija_microcontroller_bottom.png b/mesecons_microcontroller/textures/jeija_microcontroller_bottom.png Binary files differnew file mode 100644 index 0000000..3a9161e --- /dev/null +++ b/mesecons_microcontroller/textures/jeija_microcontroller_bottom.png diff --git a/mesecons_microcontroller/textures/jeija_microcontroller_sides.png b/mesecons_microcontroller/textures/jeija_microcontroller_sides.png Binary files differnew file mode 100644 index 0000000..b367644 --- /dev/null +++ b/mesecons_microcontroller/textures/jeija_microcontroller_sides.png diff --git a/mesecons_microcontroller/textures/jeija_microcontroller_top.png b/mesecons_microcontroller/textures/jeija_microcontroller_top.png Binary files differnew file mode 100644 index 0000000..438c934 --- /dev/null +++ b/mesecons_microcontroller/textures/jeija_microcontroller_top.png |