Maciej Kasatkin
2012-09-15 2bd039c0fe9d7efa71cd2b00e4439ad7b7f0c96c
commit | author | age
80b5f3 1 minetest.register_node("technic:nodebreaker_off", {
MK 2     description = "Node Breaker",
3     tile_images = {"technic_nodebreaker_top.png","technic_nodebreaker_bottom.png","technic_nodebreaker_side2.png","technic_nodebreaker_side1.png",
4             "technic_nodebreaker_back.png","technic_nodebreaker_front_off.png"},
5     is_ground_content = true,
6     paramtype2 = "facedir",
7     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_receptor_off = 1, mesecon_effector_off = 1, mesecon = 2},
8     sounds = default.node_sound_stone_defaults(),
9 })
10
11 minetest.register_node("technic:nodebreaker_on", {
12     description = "Node Breaker",
13     tile_images = {"technic_nodebreaker_top.png","technic_nodebreaker_bottom.png","technic_nodebreaker_side2.png","technic_nodebreaker_side1.png",
14             "technic_nodebreaker_back.png","technic_nodebreaker_front_on.png"},
15     is_ground_content = true,
16     paramtype2 = "facedir",
17     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_receptor_off = 1, mesecon_effector_off = 1, mesecon = 2},
18     sounds = default.node_sound_stone_defaults(),
19 })
20
21 mesecon:register_on_signal_on(function(pos, node)
22     if node.name == "technic:nodebreaker_off" then
23         minetest.env:add_node(pos, {name="technic:nodebreaker_on", param2 = node.param2})
24         break_node (pos,node.param2)
25         nodeupdate(pos)
26     end
27 end)
28
29 mesecon:register_on_signal_off(function(pos, node)
30     if node.name == "technic:nodebreaker_on" then
31         minetest.env:add_node(pos, {name="technic:nodebreaker_off", param2 = node.param2})
32         nodeupdate(pos)
33     end
34 end)
35
36 mesecon:register_effector("technic:nodebreaker_on", "technic:nodebreaker_off")
37
38 function break_node (pos,n_param)        
39     local pos1={}
40     local pos2={}
41     pos1.x=pos.x
42     pos1.y=pos.y
43     pos1.z=pos.z
44     pos2.x=pos.x
45     pos2.y=pos.y
46     pos2.z=pos.z
47
48     --param2 3=x+ 1=x- 2=z+ 0=z-
2bd039 49     if n_param==3 then pos2.x=pos2.x+1 pos1.x=pos1.x-1 end
80b5f3 50     if n_param==2 then pos2.z=pos2.z+1 pos1.z=pos1.z-1 end
MK 51     if n_param==1 then pos2.x=pos2.x-1 pos1.x=pos1.x+1 end
52     if n_param==0 then pos2.z=pos2.z-1 pos1.x=pos1.z+1 end
53
54     local node=minetest.env:get_node(pos2)
55     if node.name == "air" then return nil end
56     if node.name == "default:lava_source" then return nil end
57     if node.name == "default:lava_flowing" then return nil end
58     if node.name == "default:water_source" then minetest.env:remove_node(pos2) return nil end
59     if node.name == "default:water_flowing" then minetest.env:remove_node(pos2) return nil end
60     if node.name == "ignore" then minetest.env:remove_node(pos2) return nil end
61     local drops = minetest.get_node_drops(node.name, "default:pick_mese")
62         local _, dropped_item
63         for _, dropped_item in ipairs(drops) do
64             minetest.item_drop(dropped_item, "", pos1)
65         end
66     minetest.env:remove_node(pos2)
67
68 end
69