Faster updating of redstone torches
[MineClone/MineClone2.git] / mods / ITEMS / REDSTONE / mesecons_torch / init.lua
blob7b15a1d7a4a4328b2087292f3d15489eed7e99d9
1 --MESECON TORCHES
3 local rotate_torch_rules = function (rules, param2)
4 if param2 == 1 then
5 return rules
6 elseif param2 == 5 then
7 return mesecon.rotate_rules_right(rules)
8 elseif param2 == 2 then
9 return mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) --180 degrees
10 elseif param2 == 4 then
11 return mesecon.rotate_rules_left(rules)
12 elseif param2 == 0 then
13 return rules
14 else
15 return rules
16 end
17 end
19 local torch_get_output_rules = function(node)
20 if node.param2 == 1 then
21 return {
22 { x = -1, y = 0, z = 0 },
23 { x = 1, y = 0, z = 0 },
24 { x = 0, y = 1, z = 0, spread = true },
25 { x = 0, y = 0, z = -1 },
26 { x = 0, y = 0, z = 1 },
28 else
29 return rotate_torch_rules({
30 { x = 1, y = 0, z = 0 },
31 { x = 0, y = -1, z = 0 },
32 { x = 0, y = 1, z = 0, spread = true },
33 { x = 0, y = 1, z = 0 },
34 { x = 0, y = 0, z = -1 },
35 { x = 0, y = 0, z = 1 },
36 }, node.param2)
37 end
38 end
40 local torch_get_input_rules = function(node)
41 if node.param2 == 1 then
42 return {{x = 0, y = -1, z = 0 }}
43 else
44 return rotate_torch_rules({{ x = -1, y = 0, z = 0 }}, node.param2)
45 end
46 end
48 local torch_inversion = function(pos, node)
49 if node.name == "mesecons_torch:mesecon_torch_on" then
50 minetest.set_node(pos, {name="mesecons_torch:mesecon_torch_off", param2=node.param2})
51 mesecon.receptor_off(pos, torch_get_output_rules(node))
52 elseif node.name == "mesecons_torch:mesecon_torch_on_wall" then
53 minetest.set_node(pos, {name="mesecons_torch:mesecon_torch_off_wall", param2=node.param2})
54 mesecon.receptor_off(pos, torch_get_output_rules(node))
55 elseif node.name == "mesecons_torch:mesecon_torch_off" then
56 minetest.set_node(pos, {name="mesecons_torch:mesecon_torch_on", param2=node.param2})
57 mesecon.receptor_on(pos, torch_get_output_rules(node))
58 elseif node.name == "mesecons_torch:mesecon_torch_off_wall" then
59 minetest.set_node(pos, {name="mesecons_torch:mesecon_torch_on_wall", param2=node.param2})
60 mesecon.receptor_on(pos, torch_get_output_rules(node))
61 end
62 end
64 minetest.register_craft({
65 output = 'mesecons_torch:mesecon_torch_on',
66 recipe = {
67 {"mesecons:redstone"},
68 {"mcl_core:stick"},}
71 mcl_torches.register_torch("mesecon_torch_off", "Redstone Torch (off)",
72 nil,
73 nil,
74 "jeija_torches_off.png",
75 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
76 {"jeija_torches_off.png"},
78 {dig_immediate=3, dig_by_water=1, not_in_creative_inventory=1},
79 mcl_sounds.node_sound_wood_defaults(),
81 mesecons = {
82 receptor = {
83 state = mesecon.state.off,
84 rules = torch_get_output_rules,
86 effector = {
87 state = mesecon.state.on,
88 rules = torch_get_input_rules,
89 action_off = torch_inversion,
92 drop = "mesecons_torch:mesecon_torch_on",
93 _doc_items_create_entry = false,
97 mcl_torches.register_torch("mesecon_torch_on", "Redstone Torch",
98 "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.",
99 [[Redstone torches can generally be placed at the side and on the top of full solid opaque blocks. The following exceptions apply:
100 • Glass, fence, wall, hopper: Can only be placed on top
101 • Upside-down slab/stair: Can only be placed on top
102 • Soul sand, mob spawner: Placement possible
103 • Glowstone and pistons: No placement possible]],
104 "jeija_torches_on.png",
105 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
106 {"jeija_torches_on.png"},
108 {dig_immediate=3, dig_by_water=1,},
109 mcl_sounds.node_sound_wood_defaults(),
111 mesecons = {
112 receptor = {
113 state = mesecon.state.on,
114 rules = torch_get_output_rules
116 effector = {
117 state = mesecon.state.off,
118 rules = torch_get_input_rules,
119 action_on = torch_inversion,
125 minetest.register_node("mesecons_torch:redstoneblock", {
126 description = "Block of Redstone",
127 _doc_items_longdesc = "A block of redstone permanently supplies redstone power to its surrounding blocks.",
128 tiles = {"redstone_redstone_block.png"},
129 stack_max = 64,
130 groups = {pickaxey=1},
131 sounds = mcl_sounds.node_sound_stone_defaults(),
132 is_ground_content = false,
133 mesecons = {receptor = {
134 state = mesecon.state.on,
135 rules = mesecon.rules.alldirs,
137 _mcl_blast_resistance = 30,
138 _mcl_hardness = 5,
141 minetest.register_craft({
142 output = "mesecons_torch:redstoneblock",
143 recipe = {
144 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
145 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
146 {'mesecons:wire_00000000_off','mesecons:wire_00000000_off','mesecons:wire_00000000_off'},
150 minetest.register_craft({
151 output = 'mesecons:wire_00000000_off 9',
152 recipe = {
153 {'mesecons_torch:redstoneblock'},
157 if minetest.get_modpath("doc") then
158 doc.add_entry_alias("nodes", "mesecons_torch:mesecon_torch_on", "nodes", "mesecons_torch:mesecon_torch_off")
159 doc.add_entry_alias("nodes", "mesecons_torch:mesecon_torch_on", "nodes", "mesecons_torch:mesecon_torch_off_wall")