Make redstone block an alldirs block
[MineClone/MineClone2.git] / mods / ITEMS / REDSTONE / mesecons_torch / init.lua
blob865c8e485002dde8073d01138b21edb01bb4f94c
1 --MESECON TORCHES
3 local rotate_torch_rules = function (rules, param2)
4 if param2 == 5 then
5 return mesecon.rotate_rules_right(rules)
6 elseif param2 == 2 then
7 return mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) --180 degrees
8 elseif param2 == 4 then
9 return mesecon.rotate_rules_left(rules)
10 elseif param2 == 1 then
11 return mesecon.rotate_rules_down(rules)
12 elseif param2 == 0 then
13 return mesecon.rotate_rules_up(rules)
14 else
15 return rules
16 end
17 end
19 local torch_get_output_rules = function(node)
20 local rules = {
21 {x = 1, y = 0, z = 0},
22 {x = 0, y = 0, z = 1},
23 {x = 0, y = 0, z =-1},
24 {x = 0, y = 1, z = 0},
25 {x = 0, y =-1, z = 0}}
27 return rotate_torch_rules(rules, node.param2)
28 end
30 local torch_get_input_rules = function(node)
31 local rules = {{x = -2, y = 0, z = 0},
32 {x = -1, y = 1, z = 0}}
34 return rotate_torch_rules(rules, node.param2)
35 end
37 minetest.register_craft({
38 output = 'mesecons_torch:mesecon_torch_on',
39 recipe = {
40 {"mesecons:redstone"},
41 {"mcl_core:stick"},}
44 mcl_torches.register_torch("mesecon_torch_off", "Redstone Torch (off)",
45 nil,
46 nil,
47 "jeija_torches_off.png",
48 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
49 {"jeija_torches_off.png"},
51 {dig_immediate=3, dig_by_water=1, not_in_creative_inventory=1},
52 mcl_sounds.node_sound_wood_defaults(),
54 mesecons = {receptor = {
55 state = mesecon.state.off,
56 rules = torch_get_output_rules
57 }},
58 drop = "mesecons_torch:mesecon_torch_on",
59 _doc_items_create_entry = false,
63 mcl_torches.register_torch("mesecon_torch_on", "Redstone Torch",
64 "Redstone torches are redstone components which invert the signal of surrounding redstone components. An active component will become inactive, and an inactive component will become active. Redstone torches can be used as a quick and easy way to send a redstone to a redstone trail.",
65 [[Redstone torches can generally be placed at the side and on the top of full solid opaque blocks. The following exceptions apply:
66 • Glass, fence, wall, hopper: Can only be placed on top
67 • Upside-down slab/stair: Can only be placed on top
68 • Soul sand, mob spawner: Placement possible
69 • Glowstone and pistons: No placement possible]],
70 "jeija_torches_on.png",
71 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
72 {"jeija_torches_on.png"},
74 {dig_immediate=3, dig_by_water=1,},
75 mcl_sounds.node_sound_wood_defaults(),
77 mesecons = {receptor = {
78 state = mesecon.state.on,
79 rules = torch_get_output_rules
84 minetest.register_node("mesecons_torch:redstoneblock", {
85 description = "Block of Redstone",
86 _doc_items_longdesc = "A block of redstone permanently supplies redstone power to its surrounding blocks.",
87 tiles = {"redstone_redstone_block.png"},
88 stack_max = 64,
89 groups = {pickaxey=1},
90 sounds = mcl_sounds.node_sound_stone_defaults(),
91 is_ground_content = false,
92 mesecons = {receptor = {
93 state = mesecon.state.on,
94 rules = mesecon.rules.alldirs,
95 }},
96 _mcl_blast_resistance = 30,
97 _mcl_hardness = 5,
100 minetest.register_craft({
101 output = "mesecons_torch:redstoneblock",
102 recipe = {
103 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
104 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
105 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
109 minetest.register_craft({
110 output = 'mesecons:wire_00000000_off 9',
111 recipe = {
112 {'mesecons_torch:redstoneblock'},
116 minetest.register_abm({
117 label = "Redstone torch inversion",
118 nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_off_wall","mesecons_torch:mesecon_torch_on","mesecons_torch:mesecon_torch_on_wall"},
119 interval = 1,
120 chance = 1,
121 action = function(pos, node)
122 local is_powered = false
123 for _, rule in ipairs(torch_get_input_rules(node)) do
124 local src = vector.add(pos, rule)
125 if mesecon.is_power_on(src) then
126 is_powered = true
130 if is_powered then
131 if node.name == "mesecons_torch:mesecon_torch_on" then
132 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off", param2=node.param2})
133 mesecon.receptor_off(pos, torch_get_output_rules(node))
134 elseif node.name == "mesecons_torch:mesecon_torch_on_wall" then
135 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off_wall", param2=node.param2})
136 mesecon.receptor_off(pos, torch_get_output_rules(node))
138 elseif node.name == "mesecons_torch:mesecon_torch_off" then
139 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on", param2=node.param2})
140 mesecon.receptor_on(pos, torch_get_output_rules(node))
141 elseif node.name == "mesecons_torch:mesecon_torch_off_wall" then
142 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on_wall", param2=node.param2})
143 mesecon.receptor_on(pos, torch_get_output_rules(node))
148 if minetest.get_modpath("doc") then
149 doc.add_entry_alias("nodes", "mesecons_torch:mesecon_torch_on", "nodes", "mesecons_torch:mesecon_torch_off")
150 doc.add_entry_alias("nodes", "mesecons_torch:mesecon_torch_on", "nodes", "mesecons_torch:mesecon_torch_off_wall")