From 961b955f2d0872c4e84d9df63ea10a18643dfcbe Mon Sep 17 00:00:00 2001 From: Jeija Date: Sun, 9 Dec 2012 13:28:32 +0100 Subject: [PATCH] Port door, fix button/lever bug, new visual style for receiver --- mesecons/presets.lua | 14 +- mesecons_button/init.lua | 38 ++-- mesecons_compatibility/init.lua | 174 +++++++++++++++++- mesecons_receiver/init.lua | 10 +- .../textures/receiver_bottom_off.png | Bin 242 -> 494 bytes .../textures/receiver_bottom_on.png | Bin 247 -> 239 bytes .../textures/receiver_fb_off.png | Bin 374 -> 494 bytes mesecons_textures/textures/receiver_fb_on.png | Bin 517 -> 239 bytes .../textures/receiver_lr_off.png | Bin 317 -> 494 bytes mesecons_textures/textures/receiver_lr_on.png | Bin 321 -> 239 bytes .../textures/receiver_top_off.png | Bin 240 -> 494 bytes .../textures/receiver_top_on.png | Bin 245 -> 239 bytes mesecons_walllever/init.lua | 34 +--- 13 files changed, 205 insertions(+), 65 deletions(-) diff --git a/mesecons/presets.lua b/mesecons/presets.lua index 463a0f8..9988d22 100644 --- a/mesecons/presets.lua +++ b/mesecons/presets.lua @@ -1,4 +1,4 @@ -mesecon.rules={} +mesecon.rules = {} mesecon.state = {} mesecon.rules.default = @@ -23,5 +23,17 @@ mesecon.rules.buttonlike = {x = 1, y =-1, z =-1}, {x = 2, y = 0, z = 0}} +mesecon.rules.buttonlike_get = function(node) + local rules = mesecon.rules.buttonlike + if node.param2 == 2 then + rules=mesecon:rotate_rules_left(rules) + elseif node.param2 == 3 then + rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) + elseif node.param2 == 0 then + rules=mesecon:rotate_rules_right(rules) + end + return rules +end + mesecon.state.on = "on" mesecon.state.off = "off" diff --git a/mesecons_button/init.lua b/mesecons_button/init.lua index d4e6802..282e305 100644 --- a/mesecons_button/init.lua +++ b/mesecons_button/init.lua @@ -2,6 +2,15 @@ -- A button that when pressed emits power for 1 second -- and then turns off again +mesecon.button_turnoff = function (pos) + local node = minetest.env:get_node(pos) + if node.name=="mesecons_button:button_on" then --has not been dug + mesecon:swap_node(pos, "mesecons_button:button_off") + local rules = mesecon.rules.buttonlike_get(node) + mesecon:receptor_off(pos, rules) + end +end + minetest.register_node("mesecons_button:button_off", { drawtype = "nodebox", tiles = { @@ -32,13 +41,12 @@ minetest.register_node("mesecons_button:button_off", { description = "Button", on_punch = function (pos, node) mesecon:swap_node(pos, "mesecons_button:button_on") - local rules=mesecon.button_get_rules(node) - mesecon:receptor_on(pos, rules) - minetest.after(1, mesecon.button_turnoff, {pos=pos, param2=node.param2}) + mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node)) + minetest.after(1, mesecon.button_turnoff, pos) end, mesecons = {receptor = { state = mesecon.state.off, - rules = button_get_rules + rules = mesecon.rules.buttonlike_get }} }) @@ -74,30 +82,10 @@ minetest.register_node("mesecons_button:button_on", { description = "Button", mesecons = {receptor = { state = mesecon.state.on, - rules = button_get_rules + rules = mesecon.rules.buttonlike_get }} }) -mesecon.button_turnoff = function (params) - if minetest.env:get_node(params.pos).name=="mesecons_button:button_on" then - mesecon:swap_node(params.pos, "mesecons_button:button_off") - local rules=mesecon.button_get_rules(params) - mesecon:receptor_off(params.pos, rules) - end -end - -mesecon.button_get_rules = function(node) - local rules = mesecon.rules.buttonlike - if node.param2 == 2 then - rules=mesecon:rotate_rules_left(rules) - elseif node.param2 == 3 then - rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) - elseif node.param2 == 0 then - rules=mesecon:rotate_rules_right(rules) - end - return rules -end - minetest.register_craft({ output = '"mesecons_button:button_off" 2', recipe = { diff --git a/mesecons_compatibility/init.lua b/mesecons_compatibility/init.lua index dcf94de..b2f793c 100644 --- a/mesecons_compatibility/init.lua +++ b/mesecons_compatibility/init.lua @@ -1,11 +1,165 @@ -minetest.after(0, -function () - if minetest.registered_nodes["doors:door_wood_b_1"] then - mesecon:register_effector("doors:door_wood_b_1", "doors:door_wood_b_2") - mesecon:register_on_signal_change(function(pos, node) - if node.name == "doors:door_wood_b_2" or node.name == "doors:door_wood_b_1" then - minetest.registered_nodes[node.name].on_punch(pos, node) - end - end) +doors = {} + +-- Registers a door - REDEFINITION ONLY | DOORS MOD MUST HAVE BEEN LOADED BEFORE +-- name: The name of the door +-- def: a table with the folowing fields: +-- description +-- inventory_image +-- groups +-- tiles_bottom: the tiles of the bottom part of the door {front, side} +-- tiles_top: the tiles of the bottom part of the door {front, side} +-- If the following fields are not defined the default values are used +-- node_box_bottom +-- node_box_top +-- selection_box_bottom +-- selection_box_top +-- only_placer_can_open: if true only the player who placed the door can +-- open it + +function doors:register_door(name, def) + def.groups.not_in_creative_inventory = 1 + + local box = {{-0.5, -0.5, -0.5, 0.5, 0.5, -0.5+1.5/16}} + + if not def.node_box_bottom then + def.node_box_bottom = box end -end) + if not def.node_box_top then + def.node_box_top = box + end + if not def.selection_box_bottom then + def.selection_box_bottom= box + end + if not def.selection_box_top then + def.selection_box_top = box + end + + local tt = def.tiles_top + local tb = def.tiles_bottom + + local function after_dig_node(pos, name) + if minetest.env:get_node(pos).name == name then + minetest.env:remove_node(pos) + end + end + + local function on_punch(pos, dir, check_name, replace, replace_dir, params) + pos.y = pos.y+dir + if not minetest.env:get_node(pos).name == check_name then + return + end + local p2 = minetest.env:get_node(pos).param2 + p2 = params[p2+1] + + local meta = minetest.env:get_meta(pos):to_table() + minetest.env:set_node(pos, {name=replace_dir, param2=p2}) + minetest.env:get_meta(pos):from_table(meta) + + pos.y = pos.y-dir + meta = minetest.env:get_meta(pos):to_table() + minetest.env:set_node(pos, {name=replace, param2=p2}) + minetest.env:get_meta(pos):from_table(meta) + end + + local function on_mesecons_signal_open (pos, node) + on_punch(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) + end + + local function on_mesecons_signal_close (pos, node) + on_punch(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) + end + + local function check_player_priv(pos, player) + if not def.only_placer_can_open then + return true + end + local meta = minetest.env:get_meta(pos) + local pn = player:get_player_name() + return meta:get_string("doors_owner") == pn + end + + minetest.register_node(":"..name.."_b_1", { + tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"}, + paramtype = "light", + paramtype2 = "facedir", + drop = name, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_bottom + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_bottom + }, + groups = def.groups, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + pos.y = pos.y+1 + after_dig_node(pos, name.."_t_1") + end, + + on_punch = function(pos, node, puncher) + if check_player_priv(pos, puncher) then + on_punch(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) + end + end, + + mesecons = {effector = { + action_on = on_mesecons_signal_open + }}, + + can_dig = check_player_priv, + }) + + minetest.register_node(":"..name.."_b_2", { + tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]}, + paramtype = "light", + paramtype2 = "facedir", + drop = name, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_bottom + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_bottom + }, + groups = def.groups, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + pos.y = pos.y+1 + after_dig_node(pos, name.."_t_2") + end, + + on_punch = function(pos, node, puncher) + if check_player_priv(pos, puncher) then + on_punch(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) + end + end, + + mesecons = {effector = { + action_off = on_mesecons_signal_close + }}, + + can_dig = check_player_priv, + }) +end + +doors:register_door("doors:door_wood", { + description = "Wooden Door", + inventory_image = "door_wood.png", + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1}, + tiles_bottom = {"door_wood_b.png", "door_brown.png"}, + tiles_top = {"door_wood_a.png", "door_brown.png"}, +}) + +doors:register_door("doors:door_steel", { + description = "Steel Door", + inventory_image = "door_steel.png", + groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2,door=1}, + tiles_bottom = {"door_steel_b.png", "door_grey.png"}, + tiles_top = {"door_steel_a.png", "door_grey.png"}, + only_placer_can_open = true, +}) diff --git a/mesecons_receiver/init.lua b/mesecons_receiver/init.lua index d830d19..de2b535 100644 --- a/mesecons_receiver/init.lua +++ b/mesecons_receiver/init.lua @@ -1,8 +1,8 @@ rcvboxes = { { -3/16, -3/16 , -8/16 , 3/16, 3/16, -13/32 }, -- the smaller bump - { -5/32, -5/32 , -13/32 , 5/32, 5/32, -12/32 }, -- the receiver itself - { -3/32, -.5-1/32, -.5 , 3/32, 0 , -.5002+3/32 }, -- the vertical wire bit - { -3/32, -17/32 , -7/16+0.002 , 3/32, -13/32, 16/32+0.001 } -- the horizontal wire + { -1/32, -1/32 , -3/2 , 1/32, 1/32, -1/2 }, -- the wire through the block + { -2/32, -.5-1/32, -.5 , 2/32, 0 , -.5002+3/32 }, -- the vertical wire bit + { -2/32, -17/32 , -7/16+0.002 , 2/32, -14/32, 16/32+0.001 } -- the horizontal wire } local receiver_get_rules = function (node) @@ -31,6 +31,7 @@ minetest.register_node("mesecons_receiver:receiver_on", { paramtype = "light", paramtype2 = "facedir", sunlight_propagates = true, + walkable = false, selection_box = { type = "fixed", fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 } @@ -62,6 +63,7 @@ minetest.register_node("mesecons_receiver:receiver_off", { paramtype = "light", paramtype2 = "facedir", sunlight_propagates = true, + walkable = false, selection_box = { type = "fixed", fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 } @@ -113,7 +115,7 @@ function mesecon:receiver_place(rcpt_pos) minetest.env:dig_node(pos) if mesecon:is_power_on(rcpt_pos) then minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2}) - mesecon:receptor_on(pos, receiver_get_rules(node.param2)) + mesecon:receptor_on(pos, receiver_get_rules(node)) else minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2}) end diff --git a/mesecons_textures/textures/receiver_bottom_off.png b/mesecons_textures/textures/receiver_bottom_off.png index 8542e7d927e4bf04f7b62d115eb739bc0d166abc..b95903e82b18b78dce3b273e8b46cea4153bb520 100644 GIT binary patch delta 441 zcmV;q0Y?7v0qz5kBo78+OGiWi{{a60|De66laV1Ge+&r>4Iq{ZbDjVI0eeYAK~y-) zZIVHj+b|46KP1{tdV*fOz39A`#|%pqBW3USp^sg zgy_T60;P!7LBOzy)=UjiE0ij#O(}rkH~>I0wkex%J~6qdRd|>P5)5%3W?5lf0cG>i zVc*TRe+dtmT*}JbI{GlhuL>H59p0o4kj1rY`OM5gZj=y zEHlp8e7;XEwhhiRqdF(qZlAS725o+qU~*Awp*Mem{QoM+oQwfA#Ce*@6+1KiuVJ&; jAJ-j0Yng*_NuAtZSPU~c@Y|qh00000NkvXXu0mjf|5eZc delta 214 zcmV;{04e|O1M&foB!3BTNLh0L01FcU01FcV0GgZ_00007bV*G`2iyq(5*#~JTCj%z z005CmL_t(I%k9uH3WGotMbZ2IM1!OhA!)Jz!EI!PAsZ9if`!;=Gtv1evVt%vEg!to zTs>b`PsxeVDGRY}AVEcgz5X7y&?X+#NfM z?;EO01Ot`#hj-0PKh<1rE$cY&%eEZ6jsup1yJp66a6i>p4n7(j4gS{P10b$%C(~Ti QUjP6A07*qoM6N<$f{h3^bL?mZAUv0DMVAK~y-) z?ana{gD?~X(OL5y3vrm-|5Q{6EMsp9BBb;w*?LEMTGzMF(?o~}ah_(|Iw=VoY*?1W z7-kH}IdL3=Qm${TB2cIF##CJh;X4pi!5vb{h=2&> z?5I|VIPOl@Rn#@e<^J+qS_uFE diff --git a/mesecons_textures/textures/receiver_fb_off.png b/mesecons_textures/textures/receiver_fb_off.png index 3decca53e411b6c90bddeb6f0b3a47b16614db6f..aed3008e90eec9d014947cf75ec3a13de4d1118b 100644 GIT binary patch delta 441 zcmV;q0Y?7z0`3ElBo78+OGiWi{{a60|De66laV1Ge+&r>4Jvlunt%WR0eeYAK~y-) zZIVHj+b|46KP1{tdV*fOz39A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le1x diff --git a/mesecons_textures/textures/receiver_lr_off.png b/mesecons_textures/textures/receiver_lr_off.png index 50c602ca972537a5bb6d2ef0fa4a91690ef59531..1fb2b3a6e7f78aa91d886bcae2b8839784131d53 100644 GIT binary patch delta 441 zcmV;q0Y?740`3ElBo78+OGiWi{{a60|De66laV1Ge+&r>4Lclfx^e&j0eeYAK~y-) zZIVHj+b|46KP1{tdV*fOz39A`#|%pqBW3USp^sg zgy_T60;P!7LBOzy)=UjiE0ij#O(}rkH~>I0wkex%J~6qdRd|>P5)5%3W?5lf0cG>i zVc*TRe+dtmT*}JbI{GlhuL>H59p0o4kj1rY`OM5gZj=y zEHlp8e7;XEwhhiRqdF(qZlAS725o+qU~*Awp*Mem{QoM+oQwfA#Ce*@6+1KiuVJ&; jAJ-j0Yng*_NuAtZSPU~c@Y|qh00000NkvXXu0mjf+D6aq delta 290 zcmV+-0p0%Y1HA%}B!3BTNLh0L01FcU01FcV0GgZ_00007bV*G`2iyq(5*j*n2Pc;R z007)cL_t(I%casmN&`Ul)tx|q)dg1&F|NT#~T1%57u z_6?ZNM0Kf8A|?3#YQI7*P+b%o0XMhpBlJmB7ncE~t2Ut6{JGh~qpyA6|9wos=Z^z1 o1#ed;VhY|Lmm9EN3P7%B+)c^nh07*qoM6N<$g8Q_8nE(I) diff --git a/mesecons_textures/textures/receiver_lr_on.png b/mesecons_textures/textures/receiver_lr_on.png index 1eeda68773baeb4e45325be88d05d8a1b44b2856..087c0b41aa4e26a6abf3d7cece07c3dbabe5c773 100644 GIT binary patch delta 184 zcmV;p07w790`CEkBo78+OGiWi{{a60|De66laV1Ge+&r>4G5#Z+hhO$0DMVAK~y-) z?ana{gD?~X(OL5y3vrm-|5Q{6EMsp9BBb;w*?LEMTGzMF(?o~}ah_(|Iw=VoY*?1W z7-kH}IdL3=Qm${0onfV0l@;0B!3BTNLh0L01FcU01FcV0GgZ_00007bV*G`2iyq(5*j(|4t6a7 z007`gL_t(I%cau6Y63A3fZ=~;vn7&?A|A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