Update helptext of obsidian
[MineClone/MineClone2.git] / mods / ITEMS / REDSTONE / mesecons_torch / init.lua
blobc7c4a4ca2a368169d3038db7cd58ddd4db55f6e4
1 -- REDSTONE TORCH AND BLOCK OF REDSTONE
3 local S = minetest.get_translator("mesecons_torch")
5 local TORCH_COOLOFF = 120 -- Number of seconds it takes for a burned-out torch to reactivate
7 local rotate_torch_rules = function (rules, param2)
8 if param2 == 1 then
9 return rules
10 elseif param2 == 5 then
11 return mesecon.rotate_rules_right(rules)
12 elseif param2 == 2 then
13 return mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) --180 degrees
14 elseif param2 == 4 then
15 return mesecon.rotate_rules_left(rules)
16 elseif param2 == 0 then
17 return rules
18 else
19 return rules
20 end
21 end
23 local torch_get_output_rules = function(node)
24 if node.param2 == 1 then
25 return {
26 { x = -1, y = 0, z = 0 },
27 { x = 1, y = 0, z = 0 },
28 { x = 0, y = 1, z = 0, spread = true },
29 { x = 0, y = 0, z = -1 },
30 { x = 0, y = 0, z = 1 },
32 else
33 return rotate_torch_rules({
34 { x = 1, y = 0, z = 0 },
35 { x = 0, y = -1, z = 0 },
36 { x = 0, y = 1, z = 0, spread = true },
37 { x = 0, y = 1, z = 0 },
38 { x = 0, y = 0, z = -1 },
39 { x = 0, y = 0, z = 1 },
40 }, node.param2)
41 end
42 end
44 local torch_get_input_rules = function(node)
45 if node.param2 == 1 then
46 return {{x = 0, y = -1, z = 0 }}
47 else
48 return rotate_torch_rules({{ x = -1, y = 0, z = 0 }}, node.param2)
49 end
50 end
52 local torch_overheated = function(pos)
53 minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.02, max_hear_distance = 6}, true)
54 minetest.add_particle({
55 pos = {x=pos.x, y=pos.y+0.2, z=pos.z},
56 velocity = {x = 0, y = 0.6, z = 0},
57 expirationtime = 1.2,
58 size = 1.5,
59 texture = "mcl_particles_smoke.png",
61 local timer = minetest.get_node_timer(pos)
62 timer:start(TORCH_COOLOFF)
63 end
65 local torch_action_on = function(pos, node)
66 local overheat
67 if node.name == "mesecons_torch:mesecon_torch_on" then
68 overheat = mesecon.do_overheat(pos)
69 if overheat then
70 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated", param2=node.param2})
71 else
72 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off", param2=node.param2})
73 end
74 mesecon.receptor_off(pos, torch_get_output_rules(node))
75 elseif node.name == "mesecons_torch:mesecon_torch_on_wall" then
76 overheat = mesecon.do_overheat(pos)
77 if overheat then
78 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated_wall", param2=node.param2})
79 else
80 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off_wall", param2=node.param2})
81 end
82 mesecon.receptor_off(pos, torch_get_output_rules(node))
83 end
84 if overheat then
85 torch_overheated(pos)
86 end
87 end
89 local torch_action_off = function(pos, node)
90 local overheat
91 if node.name == "mesecons_torch:mesecon_torch_off" or node.name == "mesecons_torch:mesecon_torch_overheated" then
92 overheat = mesecon.do_overheat(pos)
93 if overheat then
94 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated", param2=node.param2})
95 else
96 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on", param2=node.param2})
97 mesecon.receptor_on(pos, torch_get_output_rules(node))
98 end
99 elseif node.name == "mesecons_torch:mesecon_torch_off_wall" or node.name == "mesecons_torch:mesecon_torch_overheated_wall" then
100 overheat = mesecon.do_overheat(pos)
101 if overheat then
102 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated_wall", param2=node.param2})
103 else
104 minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on_wall", param2=node.param2})
105 mesecon.receptor_on(pos, torch_get_output_rules(node))
108 if overheat then
109 torch_overheated(pos)
113 minetest.register_craft({
114 output = 'mesecons_torch:mesecon_torch_on',
115 recipe = {
116 {"mesecons:redstone"},
117 {"mcl_core:stick"},}
120 mcl_torches.register_torch("mesecon_torch_off", S("Redstone Torch (off)"),
121 nil,
122 nil,
123 "jeija_torches_off.png",
124 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
125 {"jeija_torches_off.png"},
127 {dig_immediate=3, dig_by_water=1, redstone_torch=2, mesecon_ignore_opaque_dig=1, not_in_creative_inventory=1},
128 mcl_sounds.node_sound_wood_defaults(),
130 mesecons = {
131 receptor = {
132 state = mesecon.state.off,
133 rules = torch_get_output_rules,
135 effector = {
136 state = mesecon.state.on,
137 rules = torch_get_input_rules,
138 action_off = torch_action_off,
141 drop = "mesecons_torch:mesecon_torch_on",
142 _doc_items_create_entry = false,
146 mcl_torches.register_torch("mesecon_torch_overheated", S("Redstone Torch (overheated)"),
147 nil,
148 nil,
149 "jeija_torches_off.png",
150 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
151 {"jeija_torches_off.png"},
153 {dig_immediate=3, dig_by_water=1, redstone_torch=2, mesecon_ignore_opaque_dig=1, not_in_creative_inventory=1},
154 mcl_sounds.node_sound_wood_defaults(),
156 drop = "mesecons_torch:mesecon_torch_on",
157 _doc_items_create_entry = false,
158 on_timer = function(pos, elapsed)
159 if not mesecon.is_powered(pos) then
160 local node = minetest.get_node(pos)
161 torch_action_off(pos, node)
163 end,
169 mcl_torches.register_torch("mesecon_torch_on", S("Redstone Torch"),
170 S("A redstone torch is a redstone component which can be used to invert a redstone signal. It supplies its surrounding blocks with redstone power, except for the block it is attached to. A redstone torch is normally lit, but it can also be turned off by powering the block it is attached to. While unlit, a redstone torch does not power anything."),
171 S("Redstone torches can be placed at the side and on the top of full solid opaque blocks."),
172 "jeija_torches_on.png",
173 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
174 {"jeija_torches_on.png"},
176 {dig_immediate=3, dig_by_water=1, redstone_torch=1, mesecon_ignore_opaque_dig=1},
177 mcl_sounds.node_sound_wood_defaults(),
179 on_destruct = function(pos, oldnode)
180 local node = minetest.get_node(pos)
181 torch_action_on(pos, node)
182 end,
183 mesecons = {
184 receptor = {
185 state = mesecon.state.on,
186 rules = torch_get_output_rules
188 effector = {
189 state = mesecon.state.off,
190 rules = torch_get_input_rules,
191 action_on = torch_action_on,
194 _tt_help = S("Provides redstone power when it's not powered itself"),
198 minetest.register_node("mesecons_torch:redstoneblock", {
199 description = S("Block of Redstone"),
200 _tt_help = S("Provides redstone power"),
201 _doc_items_longdesc = S("A block of redstone permanently supplies redstone power to its surrounding blocks."),
202 tiles = {"redstone_redstone_block.png"},
203 stack_max = 64,
204 groups = {pickaxey=1},
205 sounds = mcl_sounds.node_sound_stone_defaults(),
206 is_ground_content = false,
207 mesecons = {receptor = {
208 state = mesecon.state.on,
209 rules = mesecon.rules.alldirs,
211 _mcl_blast_resistance = 6,
212 _mcl_hardness = 5,
215 minetest.register_craft({
216 output = "mesecons_torch:redstoneblock",
217 recipe = {
218 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
219 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
220 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
224 minetest.register_craft({
225 output = 'mesecons:wire_00000000_off 9',
226 recipe = {
227 {'mesecons_torch:redstoneblock'},
231 if minetest.get_modpath("doc") then
232 doc.add_entry_alias("nodes", "mesecons_torch:mesecon_torch_on", "nodes", "mesecons_torch:mesecon_torch_off")
233 doc.add_entry_alias("nodes", "mesecons_torch:mesecon_torch_on", "nodes", "mesecons_torch:mesecon_torch_off_wall")