]> git.lizzy.rs Git - Crafter.git/blob - mods/torch/init.lua
Fix indentation of all files
[Crafter.git] / mods / torch / init.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 = "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 minetest.register_lbm({
80       name = "torch:torch",
81       nodenames = {"torch:floor","torch:wall"},
82       run_at_every_load = true,
83       action = function(pos, node)
84             create_ps(pos)
85       end,
86 })
87
88 -- Item definitions
89 minetest.register_craftitem("torch:torch", {
90       description = "Torch",
91       inventory_image = "torches_torch.png",
92       wield_image = "torches_torch.png",
93       wield_scale = {x = 1, y = 1, z = 1 + 1/16},
94       liquids_pointable = false,
95          on_place = function(itemstack, placer, pointed_thing)
96             if pointed_thing.type ~= "node" then
97                   return itemstack
98             end
99             
100             local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
101
102             local fakestack = itemstack
103             local retval = false
104             if wdir < 1 then
105                   return itemstack
106             elseif wdir == 1 then
107                   retval = fakestack:set_name("torch:floor")
108             else
109                   retval = fakestack:set_name("torch:wall")
110             end
111             if not retval then
112                   return itemstack
113             end
114             itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
115             itemstack:set_name("torch:torch")
116             
117             if retval then
118                   minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
119             end
120
121             return itemstack
122       end
123 })
124
125 minetest.register_node("torch:floor", {
126       inventory_image = "default_torch.png",
127       wield_image = "torches_torch.png",
128       wield_scale = {x = 1, y = 1, z = 1 + 2/16},
129       drawtype = "mesh",
130       mesh = "torch_floor.obj",
131       tiles = {"torches_torch.png"},
132       paramtype = "light",
133       paramtype2 = "none",
134       sunlight_propagates = true,
135       drop = "torch:torch",
136       walkable = false,
137       light_source = 13,
138       groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
139       legacy_wallmounted = true,
140       selection_box = {
141             type = "fixed",
142             fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
143       },
144       on_construct = function(pos)
145             create_ps(pos)
146       end,
147       on_destruct = function(pos)
148             delete_ps(pos)
149       end,
150       sounds = main.woodSound(),
151 })
152
153 minetest.register_node("torch:wall", {
154       inventory_image = "default_torch.png",
155       wield_image = "torches_torch.png",
156       wield_scale = {x = 1, y = 1, z = 1 + 1/16},
157       drawtype = "mesh",
158       mesh = "torch_wall.obj",
159       tiles = {"torches_torch.png"},
160       paramtype = "light",
161       paramtype2 = "wallmounted",
162       sunlight_propagates = true,
163       walkable = false,
164       light_source = 13,
165       groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
166       drop = "torch:torch",
167       selection_box = {
168             type = "wallmounted",
169             wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
170             wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
171             wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
172       },
173       on_construct = function(pos)
174             create_ps(pos)
175       end,
176       on_destruct = function(pos)
177             delete_ps(pos)
178       end,
179       sounds = main.woodSound(),
180 })
181
182 minetest.register_craft({
183       output = "torch:torch 4",
184       recipe = {
185             {"main:coal"},
186             {"main:stick"}
187       }
188 })
189 minetest.register_craft({
190       output = "torch:torch 4",
191       recipe = {
192             {"main:charcoal"},
193             {"main:stick"}
194       }
195 })