]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/torch.lua
Turn off nametags as they break the animation
[Crafter.git] / mods / redstone / torch.lua
1 --get point where particle spawner is added
2 local function get_offset(wdir)
3         local z = 0
4         local x = 0
5         if wdir == 4 then
6                 z = 0.25
7         elseif wdir == 2 then
8                 x = 0.25
9         elseif wdir == 5 then
10                 z = -0.25
11         elseif wdir == 3 then
12                 x = -0.25
13         end
14         return {x = x, y = 0.27, z = z} 
15 end
16
17 --remove smoke and fire
18 local function delete_ps(pos)
19         local meta = minetest.get_meta(pos)
20         minetest.delete_particlespawner(meta:get_int("psf"))
21         minetest.delete_particlespawner(meta:get_int("pss"))
22 end
23
24 --add in smoke and fire
25 local function create_ps(pos)
26         local dir = get_offset(minetest.get_node(pos).param2)
27         local ppos = vector.add(dir,pos)
28         local meta = minetest.get_meta(pos)
29         local psf = minetest.add_particlespawner({
30                 amount = 2,
31                 time = 0,
32                 minpos = ppos,
33                 maxpos = ppos,
34                 minvel = vector.new(0,0,0),
35                 maxvel = vector.new(0,0,0),
36                 minacc = {x=0, y=0, z=0},
37                 maxacc = {x=0, y=0, z=0},
38                 minexptime = 1,
39                 maxexptime = 1,
40                 minsize = 3,
41                 maxsize = 3,
42                 collisiondetection = false,
43                 vertical = true,
44                 texture = "redstone_torch_animated.png",
45                 animation = {type = "vertical_frames",
46
47                         aspect_w = 16,
48                         -- Width of a frame in pixels
49
50                         aspect_h = 16,
51                         -- Height of a frame in pixels
52
53                         length =  0.2,
54                         -- Full loop length
55                 },
56         })
57         local pss = minetest.add_particlespawner({
58                 amount = 2,
59                 time = 0,
60                 minpos = ppos,
61                 maxpos = ppos,
62                 minvel = vector.new(-0.1,0.1,-0.1),
63                 maxvel = vector.new(0.1,0.3,0.1),
64                 minacc = vector.new(0,0,0),
65                 maxacc = vector.new(0,0,0),
66                 minexptime = 1,
67                 maxexptime = 2,
68                 minsize = 1,
69                 maxsize = 2,
70                 collisiondetection = false,
71                 vertical = false,
72                 texture = "smoke.png",
73         })
74         meta:set_int("psf", psf)
75         meta:set_int("pss", pss)
76 end
77
78 --reload smoke and flame on load
79 --[[
80 minetest.register_lbm({
81         name = "redstone:torch",
82         nodenames = {"redstone:torch_floor","redstone:torch_wall"},
83         run_at_every_load = true,
84         action = function(pos, node)
85                 create_ps(pos)
86         end,
87 })
88 ]]--
89 -- Item definitions
90 minetest.register_craftitem("redstone:torch", {
91         description = "Redstone Torch",
92         inventory_image = "redstone_torch.png",
93         wield_image = "redstone_torch.png",
94         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
95         liquids_pointable = false,
96         power = 9,
97         on_place = function(itemstack, placer, pointed_thing)
98                 if pointed_thing.type ~= "node" then
99                         return itemstack
100                 end
101
102                 local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
103
104                 local fakestack = itemstack
105                 local retval = false
106                 if wdir < 1 then
107                         return itemstack
108                 elseif wdir == 1 then
109                         retval = fakestack:set_name("redstone:torch_floor")
110                 else
111                         retval = fakestack:set_name("redstone:torch_wall")
112                         --local name = minetest.get_node(pointed_thing.under).name
113                         --local def = minetest.registered_nodes[name]
114                         --if def.drawtype == "normal" and string.match(name, "main:") then
115                         --      minetest.set_node(pointed_thing.under,{name="redstone:"..string.gsub(name, "main:", "").."_deactivator"})
116                         --end
117                 end
118                 if not retval then
119                         return itemstack
120                 end
121                 itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
122                 itemstack:set_name("redstone:torch")
123
124                 if retval then
125                         minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
126                 end
127
128                 return itemstack
129         end
130 })
131
132 minetest.register_node("redstone:torch_floor", {
133         inventory_image = "redstone_torch.png",
134         wield_image = "redstone_torch.png",
135         wield_scale = {x = 1, y = 1, z = 1 + 2/16},
136         drawtype = "mesh",
137         mesh = "torch_floor.obj",
138         tiles = {"redstone_torch.png"},
139         paramtype = "light",
140         paramtype2 = "none",
141         power = 9,
142         sunlight_propagates = true,
143         drop = "redstone:torch",
144         walkable = false,
145         light_source = 13,
146         groups = {choppy=2, dig_immediate=3, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,redstone_torch=1,redstone_power=9},
147         legacy_wallmounted = true,
148         selection_box = {
149                 type = "fixed",
150                 fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
151         },
152         
153         on_construct = function(pos)
154                 --redstone.torch_activate(pos)
155                 redstone.collect_info(pos)
156         end,
157         after_destruct = function(pos, oldnode)
158                 redstone.collect_info(pos)
159         end,
160         sounds = main.woodSound(),
161 })
162
163 minetest.register_node("redstone:torch_wall", {
164         inventory_image = "redstone_torch.png",
165         wield_image = "redstone_torch.png",
166         wield_scale = {x = 1, y = 1, z = 1 + 1/16},
167         drawtype = "mesh",
168         mesh = "torch_wall.obj",
169         tiles = {"redstone_torch.png"},
170         paramtype = "light",
171         paramtype2 = "wallmounted",
172         sunlight_propagates = true,
173         walkable = false,
174         light_source = 13,
175         power = 9,
176         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,redstone_torch=1,redstone_power=9},
177         drop = "redstone:torch",
178         selection_box = {
179                 type = "wallmounted",
180                 wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
181                 wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
182                 wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
183         },
184         on_construct = function(pos)
185                 --redstone.torch_activate(pos)
186                 redstone.collect_info(pos)
187         end,
188         after_destruct = function(pos, oldnode)
189                 redstone.collect_info(pos)
190         end,
191         sounds = main.woodSound(),
192 })
193