]> git.lizzy.rs Git - Crafter.git/blob - mods/torch/init.lua
More updates
[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 meta = minetest.get_meta(pos)
27       local dir = get_offset(minetest.get_node(pos).param2)
28       local ppos = vector.add(dir,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
79 --reload smoke and flame on load
80 minetest.register_abm({
81       label = "Torch Particle",
82       nodenames = {"group:torch"},
83       neighbors = {"air"},
84       interval = 0.1,
85       chance = 1,
86       action = function(pos, node, active_object_count, active_object_count_wider)
87             local found_player = false
88             for _,object in ipairs(minetest.get_objects_inside_radius(pos, 3)) do
89                   local pos2 = object:getpos()
90                   if object:is_player() then
91                         found_player = true
92                   end
93             end
94             if found_player == true then
95                   print("creating ps")
96                   create_ps(pos)
97             else
98                   print("deleting ps")
99                   delete_ps(pos)
100             end
101       end,
102 })
103
104 -- Item definitions
105 minetest.register_craftitem("torch:torch", {
106       description = "Torch",
107       inventory_image = "torches_torch.png",
108       wield_image = "torches_torch.png",
109       wield_scale = {x = 1, y = 1, z = 1 + 1/16},
110       liquids_pointable = false,
111       on_place = function(itemstack, placer, pointed_thing)
112             if pointed_thing.type ~= "node" then
113                   return itemstack
114             end
115
116             local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
117
118             local fakestack = itemstack
119             local retval = false
120             if wdir < 1 then
121                   return itemstack
122             elseif wdir == 1 then
123                   retval = fakestack:set_name("torch:floor")
124             else
125                   retval = fakestack:set_name("torch:wall")
126             end
127             if not retval then
128                   return itemstack
129             end
130             itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
131             itemstack:set_name("torch:torch")
132
133             if retval then
134                   minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
135             end
136
137             return itemstack
138       end
139 })
140
141 minetest.register_node("torch:floor", {
142       inventory_image = "default_torch.png",
143       wield_image = "torches_torch.png",
144       wield_scale = {x = 1, y = 1, z = 1 + 2/16},
145       drawtype = "mesh",
146       mesh = "torch_floor.obj",
147       tiles = {"torches_torch.png"},
148       paramtype = "light",
149       paramtype2 = "none",
150       sunlight_propagates = true,
151       drop = "torch:torch",
152       walkable = false,
153       light_source = 13,
154       groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
155       legacy_wallmounted = true,
156       selection_box = {
157             type = "fixed",
158             fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
159       },
160       on_construct = function(pos)
161             --create_ps(pos)
162       end,
163       on_destruct = function(pos)
164             --delete_ps(pos)
165       end,
166       sounds = main.woodSound(),
167 })
168
169 minetest.register_node("torch:wall", {
170       inventory_image = "default_torch.png",
171       wield_image = "torches_torch.png",
172       wield_scale = {x = 1, y = 1, z = 1 + 1/16},
173       drawtype = "mesh",
174       mesh = "torch_wall.obj",
175       tiles = {"torches_torch.png"},
176       paramtype = "light",
177       paramtype2 = "wallmounted",
178       sunlight_propagates = true,
179       walkable = false,
180       light_source = 13,
181       groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
182       drop = "torch:torch",
183       selection_box = {
184             type = "wallmounted",
185             wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
186             wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
187             wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
188       },
189       on_construct = function(pos)
190            -- create_ps(pos)
191       end,
192       on_destruct = function(pos)
193            -- delete_ps(pos)
194       end,
195       sounds = main.woodSound(),
196 })
197
198 minetest.register_craft({
199       output = "torch:torch 4",
200       recipe = {
201             {"main:coal"},
202             {"main:stick"}
203       }
204 })
205 minetest.register_craft({
206       output = "torch:torch 4",
207       recipe = {
208             {"main:charcoal"},
209             {"main:stick"}
210       }
211 })